Skip to content

Commit

Permalink
clang: update to clang v12
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee committed Nov 20, 2021
1 parent e1e0f98 commit 580092c
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- "main"

env:
LLVM_VERSION: 11
LLVM_VERSION: 12

jobs:
test:
Expand Down
88 changes: 58 additions & 30 deletions clang/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
*/
#define CINDEX_VERSION_MAJOR 0
#define CINDEX_VERSION_MINOR 60
#define CINDEX_VERSION_MINOR 61

#define CINDEX_VERSION_ENCODE(major, minor) (((major)*10000) + ((minor)*1))

Expand Down Expand Up @@ -2054,62 +2054,58 @@ enum CXCursorKind {
*/
CXCursor_CXXFunctionalCastExpr = 128,

/** OpenCL's addrspace_cast<> expression.
*/
CXCursor_CXXAddrspaceCastExpr = 129,

/** A C++ typeid expression (C++ [expr.typeid]).
*/
CXCursor_CXXTypeidExpr = 130,
CXCursor_CXXTypeidExpr = 129,

/** [C++ 2.13.5] C++ Boolean Literal.
*/
CXCursor_CXXBoolLiteralExpr = 131,
CXCursor_CXXBoolLiteralExpr = 130,

/** [C++0x 2.14.7] C++ Pointer Literal.
*/
CXCursor_CXXNullPtrLiteralExpr = 132,
CXCursor_CXXNullPtrLiteralExpr = 131,

/** Represents the "this" expression in C++
*/
CXCursor_CXXThisExpr = 133,
CXCursor_CXXThisExpr = 132,

/** [C++ 15] C++ Throw Expression.
*
* This handles 'throw' and 'throw' assignment-expression. When
* assignment-expression isn't present, Op will be null.
*/
CXCursor_CXXThrowExpr = 134,
CXCursor_CXXThrowExpr = 133,

/** A new expression for memory allocation and constructor calls, e.g:
* "new CXXNewExpr(foo)".
*/
CXCursor_CXXNewExpr = 135,
CXCursor_CXXNewExpr = 134,

/** A delete expression for memory deallocation and destructor calls,
* e.g. "delete[] pArray".
*/
CXCursor_CXXDeleteExpr = 136,
CXCursor_CXXDeleteExpr = 135,

/** A unary expression. (noexcept, sizeof, or other traits)
*/
CXCursor_UnaryExpr = 137,
CXCursor_UnaryExpr = 136,

/** An Objective-C string literal i.e. @"foo".
*/
CXCursor_ObjCStringLiteral = 138,
CXCursor_ObjCStringLiteral = 137,

/** An Objective-C \@encode expression.
*/
CXCursor_ObjCEncodeExpr = 139,
CXCursor_ObjCEncodeExpr = 138,

/** An Objective-C \@selector expression.
*/
CXCursor_ObjCSelectorExpr = 140,
CXCursor_ObjCSelectorExpr = 139,

/** An Objective-C \@protocol expression.
*/
CXCursor_ObjCProtocolExpr = 141,
CXCursor_ObjCProtocolExpr = 140,

/** An Objective-C "bridged" cast expression, which casts between
* Objective-C pointers and C pointers, transferring ownership in the process.
Expand All @@ -2118,7 +2114,7 @@ enum CXCursorKind {
* NSString *str = (__bridge_transfer NSString *)CFCreateString();
* \endcode
*/
CXCursor_ObjCBridgedCastExpr = 142,
CXCursor_ObjCBridgedCastExpr = 141,

/** Represents a C++0x pack expansion that produces a sequence of
* expressions.
Expand All @@ -2133,7 +2129,7 @@ enum CXCursorKind {
* }
* \endcode
*/
CXCursor_PackExpansionExpr = 143,
CXCursor_PackExpansionExpr = 142,

/** Represents an expression that computes the length of a parameter
* pack.
Expand All @@ -2145,7 +2141,7 @@ enum CXCursorKind {
* };
* \endcode
*/
CXCursor_SizeOfPackExpr = 144,
CXCursor_SizeOfPackExpr = 143,

/* Represents a C++ lambda expression that produces a local function
* object.
Expand All @@ -2159,39 +2155,43 @@ enum CXCursorKind {
* }
* \endcode
*/
CXCursor_LambdaExpr = 145,
CXCursor_LambdaExpr = 144,

/** Objective-c Boolean Literal.
*/
CXCursor_ObjCBoolLiteralExpr = 146,
CXCursor_ObjCBoolLiteralExpr = 145,

/** Represents the "self" expression in an Objective-C method.
*/
CXCursor_ObjCSelfExpr = 147,
CXCursor_ObjCSelfExpr = 146,

/** OpenMP 5.0 [2.1.5, Array Section].
*/
CXCursor_OMPArraySectionExpr = 148,
CXCursor_OMPArraySectionExpr = 147,

/** Represents an @available(...) check.
*/
CXCursor_ObjCAvailabilityCheckExpr = 149,
CXCursor_ObjCAvailabilityCheckExpr = 148,

/**
* Fixed point literal
*/
CXCursor_FixedPointLiteral = 150,
CXCursor_FixedPointLiteral = 149,

/** OpenMP 5.0 [2.1.4, Array Shaping].
*/
CXCursor_OMPArrayShapingExpr = 151,
CXCursor_OMPArrayShapingExpr = 150,

/**
* OpenMP 5.0 [2.1.6 Iterators]
*/
CXCursor_OMPIteratorExpr = 152,
CXCursor_OMPIteratorExpr = 151,

CXCursor_LastExpr = CXCursor_OMPIteratorExpr,
/** OpenCL's addrspace_cast<> expression.
*/
CXCursor_CXXAddrspaceCastExpr = 152,

CXCursor_LastExpr = CXCursor_CXXAddrspaceCastExpr,

/* Statements */
CXCursor_FirstStmt = 200,
Expand Down Expand Up @@ -2942,6 +2942,26 @@ CINDEX_LINKAGE int clang_getCursorPlatformAvailability(
CINDEX_LINKAGE void
clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);

/**
* If cursor refers to a variable declaration and it has initializer returns
* cursor referring to the initializer otherwise return null cursor.
*/
CINDEX_LINKAGE CXCursor clang_Cursor_getVarDeclInitializer(CXCursor cursor);

/**
* If cursor refers to a variable declaration that has global storage returns 1.
* If cursor refers to a variable declaration that doesn't have global storage
* returns 0. Otherwise returns -1.
*/
CINDEX_LINKAGE int clang_Cursor_hasVarDeclGlobalStorage(CXCursor cursor);

/**
* If cursor refers to a variable declaration that has external storage
* returns 1. If cursor refers to a variable declaration that doesn't have
* external storage returns 0. Otherwise returns -1.
*/
CINDEX_LINKAGE int clang_Cursor_hasVarDeclExternalStorage(CXCursor cursor);

/**
* Describe the "language" of the entity referred to by a cursor.
*/
Expand Down Expand Up @@ -3843,7 +3863,15 @@ enum CXTypeNullabilityKind {
/**
* Nullability is not applicable to this type.
*/
CXTypeNullability_Invalid = 3
CXTypeNullability_Invalid = 3,

/**
* Generally behaves like Nullable, except when used in a block parameter that
* was imported into a swift async method. There, swift will assume that the
* parameter can get null even if no error occured. _Nullable parameters are
* assumed to only get null on error.
*/
CXTypeNullability_NullableResult = 4
};

/**
Expand Down
65 changes: 65 additions & 0 deletions clang/clang-c/Rewrite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdint.h>

/*===-- clang-c/Rewrite.h - C CXRewriter --------------------------*- C -*-===*\
|* *|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*/

#ifndef LLVM_CLANG_C_REWRITE_H
#define LLVM_CLANG_C_REWRITE_H

#include "clang-c/CXString.h"
#include "clang-c/ExternC.h"
#include "clang-c/Index.h"
#include "clang-c/Platform.h"

LLVM_CLANG_C_EXTERN_C_BEGIN

typedef void *CXRewriter;

/**
* Create CXRewriter.
*/
CINDEX_LINKAGE CXRewriter clang_CXRewriter_create(CXTranslationUnit TU);

/**
* Insert the specified string at the specified location in the original buffer.
*/
CINDEX_LINKAGE void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
const char *Insert);

/**
* Replace the specified range of characters in the input with the specified
* replacement.
*/
CINDEX_LINKAGE void clang_CXRewriter_replaceText(CXRewriter Rew, CXSourceRange ToBeReplaced,
const char *Replacement);

/**
* Remove the specified range.
*/
CINDEX_LINKAGE void clang_CXRewriter_removeText(CXRewriter Rew, CXSourceRange ToBeRemoved);

/**
* Save all changed files to disk.
* Returns 1 if any files were not saved successfully, returns 0 otherwise.
*/
CINDEX_LINKAGE int clang_CXRewriter_overwriteChangedFiles(CXRewriter Rew);

/**
* Write out rewritten version of the main file to stdout.
*/
CINDEX_LINKAGE void clang_CXRewriter_writeMainFileToStdOut(CXRewriter Rew);

/**
* Free the given CXRewriter.
*/
CINDEX_LINKAGE void clang_CXRewriter_dispose(CXRewriter Rew);

LLVM_CLANG_C_EXTERN_C_END

#endif
19 changes: 19 additions & 0 deletions clang/cursor_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ func (c Cursor) Availability() AvailabilityKind {
return AvailabilityKind(C.clang_getCursorAvailability(c.c))
}

// If cursor refers to a variable declaration and it has initializer returns cursor referring to the initializer otherwise return null cursor.
func (c Cursor) VarDeclInitializer() Cursor {
return Cursor{C.clang_Cursor_getVarDeclInitializer(c.c)}
}

// If cursor refers to a variable declaration that has global storage returns 1. If cursor refers to a variable declaration that doesn't have global storage returns 0. Otherwise returns -1.
func (c Cursor) HasVarDeclGlobalStorage() bool {
o := C.clang_Cursor_hasVarDeclGlobalStorage(c.c)

return o != C.int(0)
}

// If cursor refers to a variable declaration that has external storage returns 1. If cursor refers to a variable declaration that doesn't have external storage returns 0. Otherwise returns -1.
func (c Cursor) HasVarDeclExternalStorage() bool {
o := C.clang_Cursor_hasVarDeclExternalStorage(c.c)

return o != C.int(0)
}

// Determine the "language" of the entity referred to by a given cursor.
func (c Cursor) Language() LanguageKind {
return LanguageKind(C.clang_getCursorLanguage(c.c))
Expand Down
8 changes: 4 additions & 4 deletions clang/cursorkind_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ const (
\endcode
*/
Cursor_CXXFunctionalCastExpr = C.CXCursor_CXXFunctionalCastExpr
// OpenCL's addrspace_cast<> expression.
Cursor_CXXAddrspaceCastExpr = C.CXCursor_CXXAddrspaceCastExpr
// A C++ typeid expression (C++ [expr.typeid]).
Cursor_CXXTypeidExpr = C.CXCursor_CXXTypeidExpr
// [C++ 2.13.5] C++ Boolean Literal.
Expand Down Expand Up @@ -388,9 +386,11 @@ const (
Cursor_OMPArrayShapingExpr = C.CXCursor_OMPArrayShapingExpr
// OpenMP 5.0 [2.1.6 Iterators]
Cursor_OMPIteratorExpr = C.CXCursor_OMPIteratorExpr
// OpenMP 5.0 [2.1.6 Iterators]
// OpenCL's addrspace_cast<> expression.
Cursor_CXXAddrspaceCastExpr = C.CXCursor_CXXAddrspaceCastExpr
// OpenCL's addrspace_cast<> expression.
Cursor_LastExpr = C.CXCursor_LastExpr
// OpenMP 5.0 [2.1.6 Iterators]
// OpenCL's addrspace_cast<> expression.
Cursor_FirstStmt = C.CXCursor_FirstStmt
/*
A statement whose specific kind is not exposed via this
Expand Down
46 changes: 46 additions & 0 deletions clang/rewriter_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package clang

// #include "./clang-c/Rewrite.h"
// #include "go-clang.h"
import "C"
import "unsafe"

type Rewriter struct {
c C.CXRewriter
}

// Insert the specified string at the specified location in the original buffer.
func (r Rewriter) InsertTextBefore(loc SourceLocation, insert string) {
c_insert := C.CString(insert)
defer C.free(unsafe.Pointer(c_insert))

C.clang_CXRewriter_insertTextBefore(r.c, loc.c, c_insert)
}

// Replace the specified range of characters in the input with the specified replacement.
func (r Rewriter) ReplaceText(toBeReplaced SourceRange, replacement string) {
c_replacement := C.CString(replacement)
defer C.free(unsafe.Pointer(c_replacement))

C.clang_CXRewriter_replaceText(r.c, toBeReplaced.c, c_replacement)
}

// Remove the specified range.
func (r Rewriter) RemoveText(toBeRemoved SourceRange) {
C.clang_CXRewriter_removeText(r.c, toBeRemoved.c)
}

// Save all changed files to disk. Returns 1 if any files were not saved successfully, returns 0 otherwise.
func (r Rewriter) OverwriteChangedFiles() int32 {
return int32(C.clang_CXRewriter_overwriteChangedFiles(r.c))
}

// Write out rewritten version of the main file to stdout.
func (r Rewriter) WriteMainFileToStdOut() {
C.clang_CXRewriter_writeMainFileToStdOut(r.c)
}

// Free the given CXRewriter.
func (r Rewriter) CXRewriter_Dispose() {
C.clang_CXRewriter_dispose(r.c)
}
6 changes: 6 additions & 0 deletions clang/translationunit_gen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clang

// #include "./clang-c/Index.h"
// #include "./clang-c/Rewrite.h"
// #include "go-clang.h"
import "C"
import (
Expand Down Expand Up @@ -489,3 +490,8 @@ func (tu TranslationUnit) CodeCompleteAt(completeFilename string, completeLine u
func (tu TranslationUnit) FindIncludesInFile(file File, visitor CursorAndRangeVisitor) Result {
return Result(C.clang_findIncludesInFile(tu.c, file.c, visitor.c))
}

// Create CXRewriter.
func (tu TranslationUnit) Create() Rewriter {
return Rewriter{C.clang_CXRewriter_create(tu.c)}
}
Loading

0 comments on commit 580092c

Please sign in to comment.