Skip to content

Commit 580092c

Browse files
committed
clang: update to clang v12
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
1 parent e1e0f98 commit 580092c

File tree

8 files changed

+203
-35
lines changed

8 files changed

+203
-35
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- "main"
1010

1111
env:
12-
LLVM_VERSION: 11
12+
LLVM_VERSION: 12
1313

1414
jobs:
1515
test:

clang/clang-c/Index.h

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
3636
*/
3737
#define CINDEX_VERSION_MAJOR 0
38-
#define CINDEX_VERSION_MINOR 60
38+
#define CINDEX_VERSION_MINOR 61
3939

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

@@ -2054,62 +2054,58 @@ enum CXCursorKind {
20542054
*/
20552055
CXCursor_CXXFunctionalCastExpr = 128,
20562056

2057-
/** OpenCL's addrspace_cast<> expression.
2058-
*/
2059-
CXCursor_CXXAddrspaceCastExpr = 129,
2060-
20612057
/** A C++ typeid expression (C++ [expr.typeid]).
20622058
*/
2063-
CXCursor_CXXTypeidExpr = 130,
2059+
CXCursor_CXXTypeidExpr = 129,
20642060

20652061
/** [C++ 2.13.5] C++ Boolean Literal.
20662062
*/
2067-
CXCursor_CXXBoolLiteralExpr = 131,
2063+
CXCursor_CXXBoolLiteralExpr = 130,
20682064

20692065
/** [C++0x 2.14.7] C++ Pointer Literal.
20702066
*/
2071-
CXCursor_CXXNullPtrLiteralExpr = 132,
2067+
CXCursor_CXXNullPtrLiteralExpr = 131,
20722068

20732069
/** Represents the "this" expression in C++
20742070
*/
2075-
CXCursor_CXXThisExpr = 133,
2071+
CXCursor_CXXThisExpr = 132,
20762072

20772073
/** [C++ 15] C++ Throw Expression.
20782074
*
20792075
* This handles 'throw' and 'throw' assignment-expression. When
20802076
* assignment-expression isn't present, Op will be null.
20812077
*/
2082-
CXCursor_CXXThrowExpr = 134,
2078+
CXCursor_CXXThrowExpr = 133,
20832079

20842080
/** A new expression for memory allocation and constructor calls, e.g:
20852081
* "new CXXNewExpr(foo)".
20862082
*/
2087-
CXCursor_CXXNewExpr = 135,
2083+
CXCursor_CXXNewExpr = 134,
20882084

20892085
/** A delete expression for memory deallocation and destructor calls,
20902086
* e.g. "delete[] pArray".
20912087
*/
2092-
CXCursor_CXXDeleteExpr = 136,
2088+
CXCursor_CXXDeleteExpr = 135,
20932089

20942090
/** A unary expression. (noexcept, sizeof, or other traits)
20952091
*/
2096-
CXCursor_UnaryExpr = 137,
2092+
CXCursor_UnaryExpr = 136,
20972093

20982094
/** An Objective-C string literal i.e. @"foo".
20992095
*/
2100-
CXCursor_ObjCStringLiteral = 138,
2096+
CXCursor_ObjCStringLiteral = 137,
21012097

21022098
/** An Objective-C \@encode expression.
21032099
*/
2104-
CXCursor_ObjCEncodeExpr = 139,
2100+
CXCursor_ObjCEncodeExpr = 138,
21052101

21062102
/** An Objective-C \@selector expression.
21072103
*/
2108-
CXCursor_ObjCSelectorExpr = 140,
2104+
CXCursor_ObjCSelectorExpr = 139,
21092105

21102106
/** An Objective-C \@protocol expression.
21112107
*/
2112-
CXCursor_ObjCProtocolExpr = 141,
2108+
CXCursor_ObjCProtocolExpr = 140,
21132109

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

21232119
/** Represents a C++0x pack expansion that produces a sequence of
21242120
* expressions.
@@ -2133,7 +2129,7 @@ enum CXCursorKind {
21332129
* }
21342130
* \endcode
21352131
*/
2136-
CXCursor_PackExpansionExpr = 143,
2132+
CXCursor_PackExpansionExpr = 142,
21372133

21382134
/** Represents an expression that computes the length of a parameter
21392135
* pack.
@@ -2145,7 +2141,7 @@ enum CXCursorKind {
21452141
* };
21462142
* \endcode
21472143
*/
2148-
CXCursor_SizeOfPackExpr = 144,
2144+
CXCursor_SizeOfPackExpr = 143,
21492145

21502146
/* Represents a C++ lambda expression that produces a local function
21512147
* object.
@@ -2159,39 +2155,43 @@ enum CXCursorKind {
21592155
* }
21602156
* \endcode
21612157
*/
2162-
CXCursor_LambdaExpr = 145,
2158+
CXCursor_LambdaExpr = 144,
21632159

21642160
/** Objective-c Boolean Literal.
21652161
*/
2166-
CXCursor_ObjCBoolLiteralExpr = 146,
2162+
CXCursor_ObjCBoolLiteralExpr = 145,
21672163

21682164
/** Represents the "self" expression in an Objective-C method.
21692165
*/
2170-
CXCursor_ObjCSelfExpr = 147,
2166+
CXCursor_ObjCSelfExpr = 146,
21712167

21722168
/** OpenMP 5.0 [2.1.5, Array Section].
21732169
*/
2174-
CXCursor_OMPArraySectionExpr = 148,
2170+
CXCursor_OMPArraySectionExpr = 147,
21752171

21762172
/** Represents an @available(...) check.
21772173
*/
2178-
CXCursor_ObjCAvailabilityCheckExpr = 149,
2174+
CXCursor_ObjCAvailabilityCheckExpr = 148,
21792175

21802176
/**
21812177
* Fixed point literal
21822178
*/
2183-
CXCursor_FixedPointLiteral = 150,
2179+
CXCursor_FixedPointLiteral = 149,
21842180

21852181
/** OpenMP 5.0 [2.1.4, Array Shaping].
21862182
*/
2187-
CXCursor_OMPArrayShapingExpr = 151,
2183+
CXCursor_OMPArrayShapingExpr = 150,
21882184

21892185
/**
21902186
* OpenMP 5.0 [2.1.6 Iterators]
21912187
*/
2192-
CXCursor_OMPIteratorExpr = 152,
2188+
CXCursor_OMPIteratorExpr = 151,
21932189

2194-
CXCursor_LastExpr = CXCursor_OMPIteratorExpr,
2190+
/** OpenCL's addrspace_cast<> expression.
2191+
*/
2192+
CXCursor_CXXAddrspaceCastExpr = 152,
2193+
2194+
CXCursor_LastExpr = CXCursor_CXXAddrspaceCastExpr,
21952195

21962196
/* Statements */
21972197
CXCursor_FirstStmt = 200,
@@ -2942,6 +2942,26 @@ CINDEX_LINKAGE int clang_getCursorPlatformAvailability(
29422942
CINDEX_LINKAGE void
29432943
clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
29442944

2945+
/**
2946+
* If cursor refers to a variable declaration and it has initializer returns
2947+
* cursor referring to the initializer otherwise return null cursor.
2948+
*/
2949+
CINDEX_LINKAGE CXCursor clang_Cursor_getVarDeclInitializer(CXCursor cursor);
2950+
2951+
/**
2952+
* If cursor refers to a variable declaration that has global storage returns 1.
2953+
* If cursor refers to a variable declaration that doesn't have global storage
2954+
* returns 0. Otherwise returns -1.
2955+
*/
2956+
CINDEX_LINKAGE int clang_Cursor_hasVarDeclGlobalStorage(CXCursor cursor);
2957+
2958+
/**
2959+
* If cursor refers to a variable declaration that has external storage
2960+
* returns 1. If cursor refers to a variable declaration that doesn't have
2961+
* external storage returns 0. Otherwise returns -1.
2962+
*/
2963+
CINDEX_LINKAGE int clang_Cursor_hasVarDeclExternalStorage(CXCursor cursor);
2964+
29452965
/**
29462966
* Describe the "language" of the entity referred to by a cursor.
29472967
*/
@@ -3843,7 +3863,15 @@ enum CXTypeNullabilityKind {
38433863
/**
38443864
* Nullability is not applicable to this type.
38453865
*/
3846-
CXTypeNullability_Invalid = 3
3866+
CXTypeNullability_Invalid = 3,
3867+
3868+
/**
3869+
* Generally behaves like Nullable, except when used in a block parameter that
3870+
* was imported into a swift async method. There, swift will assume that the
3871+
* parameter can get null even if no error occured. _Nullable parameters are
3872+
* assumed to only get null on error.
3873+
*/
3874+
CXTypeNullability_NullableResult = 4
38473875
};
38483876

38493877
/**

clang/clang-c/Rewrite.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <stdint.h>
2+
3+
/*===-- clang-c/Rewrite.h - C CXRewriter --------------------------*- C -*-===*\
4+
|* *|
5+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
6+
|* Exceptions. *|
7+
|* See https://llvm.org/LICENSE.txt for license information. *|
8+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
9+
|* *|
10+
|*===----------------------------------------------------------------------===*/
11+
12+
#ifndef LLVM_CLANG_C_REWRITE_H
13+
#define LLVM_CLANG_C_REWRITE_H
14+
15+
#include "clang-c/CXString.h"
16+
#include "clang-c/ExternC.h"
17+
#include "clang-c/Index.h"
18+
#include "clang-c/Platform.h"
19+
20+
LLVM_CLANG_C_EXTERN_C_BEGIN
21+
22+
typedef void *CXRewriter;
23+
24+
/**
25+
* Create CXRewriter.
26+
*/
27+
CINDEX_LINKAGE CXRewriter clang_CXRewriter_create(CXTranslationUnit TU);
28+
29+
/**
30+
* Insert the specified string at the specified location in the original buffer.
31+
*/
32+
CINDEX_LINKAGE void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
33+
const char *Insert);
34+
35+
/**
36+
* Replace the specified range of characters in the input with the specified
37+
* replacement.
38+
*/
39+
CINDEX_LINKAGE void clang_CXRewriter_replaceText(CXRewriter Rew, CXSourceRange ToBeReplaced,
40+
const char *Replacement);
41+
42+
/**
43+
* Remove the specified range.
44+
*/
45+
CINDEX_LINKAGE void clang_CXRewriter_removeText(CXRewriter Rew, CXSourceRange ToBeRemoved);
46+
47+
/**
48+
* Save all changed files to disk.
49+
* Returns 1 if any files were not saved successfully, returns 0 otherwise.
50+
*/
51+
CINDEX_LINKAGE int clang_CXRewriter_overwriteChangedFiles(CXRewriter Rew);
52+
53+
/**
54+
* Write out rewritten version of the main file to stdout.
55+
*/
56+
CINDEX_LINKAGE void clang_CXRewriter_writeMainFileToStdOut(CXRewriter Rew);
57+
58+
/**
59+
* Free the given CXRewriter.
60+
*/
61+
CINDEX_LINKAGE void clang_CXRewriter_dispose(CXRewriter Rew);
62+
63+
LLVM_CLANG_C_EXTERN_C_END
64+
65+
#endif

clang/cursor_gen.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ func (c Cursor) Availability() AvailabilityKind {
118118
return AvailabilityKind(C.clang_getCursorAvailability(c.c))
119119
}
120120

121+
// If cursor refers to a variable declaration and it has initializer returns cursor referring to the initializer otherwise return null cursor.
122+
func (c Cursor) VarDeclInitializer() Cursor {
123+
return Cursor{C.clang_Cursor_getVarDeclInitializer(c.c)}
124+
}
125+
126+
// 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.
127+
func (c Cursor) HasVarDeclGlobalStorage() bool {
128+
o := C.clang_Cursor_hasVarDeclGlobalStorage(c.c)
129+
130+
return o != C.int(0)
131+
}
132+
133+
// 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.
134+
func (c Cursor) HasVarDeclExternalStorage() bool {
135+
o := C.clang_Cursor_hasVarDeclExternalStorage(c.c)
136+
137+
return o != C.int(0)
138+
}
139+
121140
// Determine the "language" of the entity referred to by a given cursor.
122141
func (c Cursor) Language() LanguageKind {
123142
return LanguageKind(C.clang_getCursorLanguage(c.c))

clang/cursorkind_gen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,6 @@ const (
306306
\endcode
307307
*/
308308
Cursor_CXXFunctionalCastExpr = C.CXCursor_CXXFunctionalCastExpr
309-
// OpenCL's addrspace_cast<> expression.
310-
Cursor_CXXAddrspaceCastExpr = C.CXCursor_CXXAddrspaceCastExpr
311309
// A C++ typeid expression (C++ [expr.typeid]).
312310
Cursor_CXXTypeidExpr = C.CXCursor_CXXTypeidExpr
313311
// [C++ 2.13.5] C++ Boolean Literal.
@@ -388,9 +386,11 @@ const (
388386
Cursor_OMPArrayShapingExpr = C.CXCursor_OMPArrayShapingExpr
389387
// OpenMP 5.0 [2.1.6 Iterators]
390388
Cursor_OMPIteratorExpr = C.CXCursor_OMPIteratorExpr
391-
// OpenMP 5.0 [2.1.6 Iterators]
389+
// OpenCL's addrspace_cast<> expression.
390+
Cursor_CXXAddrspaceCastExpr = C.CXCursor_CXXAddrspaceCastExpr
391+
// OpenCL's addrspace_cast<> expression.
392392
Cursor_LastExpr = C.CXCursor_LastExpr
393-
// OpenMP 5.0 [2.1.6 Iterators]
393+
// OpenCL's addrspace_cast<> expression.
394394
Cursor_FirstStmt = C.CXCursor_FirstStmt
395395
/*
396396
A statement whose specific kind is not exposed via this

clang/rewriter_gen.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package clang
2+
3+
// #include "./clang-c/Rewrite.h"
4+
// #include "go-clang.h"
5+
import "C"
6+
import "unsafe"
7+
8+
type Rewriter struct {
9+
c C.CXRewriter
10+
}
11+
12+
// Insert the specified string at the specified location in the original buffer.
13+
func (r Rewriter) InsertTextBefore(loc SourceLocation, insert string) {
14+
c_insert := C.CString(insert)
15+
defer C.free(unsafe.Pointer(c_insert))
16+
17+
C.clang_CXRewriter_insertTextBefore(r.c, loc.c, c_insert)
18+
}
19+
20+
// Replace the specified range of characters in the input with the specified replacement.
21+
func (r Rewriter) ReplaceText(toBeReplaced SourceRange, replacement string) {
22+
c_replacement := C.CString(replacement)
23+
defer C.free(unsafe.Pointer(c_replacement))
24+
25+
C.clang_CXRewriter_replaceText(r.c, toBeReplaced.c, c_replacement)
26+
}
27+
28+
// Remove the specified range.
29+
func (r Rewriter) RemoveText(toBeRemoved SourceRange) {
30+
C.clang_CXRewriter_removeText(r.c, toBeRemoved.c)
31+
}
32+
33+
// Save all changed files to disk. Returns 1 if any files were not saved successfully, returns 0 otherwise.
34+
func (r Rewriter) OverwriteChangedFiles() int32 {
35+
return int32(C.clang_CXRewriter_overwriteChangedFiles(r.c))
36+
}
37+
38+
// Write out rewritten version of the main file to stdout.
39+
func (r Rewriter) WriteMainFileToStdOut() {
40+
C.clang_CXRewriter_writeMainFileToStdOut(r.c)
41+
}
42+
43+
// Free the given CXRewriter.
44+
func (r Rewriter) CXRewriter_Dispose() {
45+
C.clang_CXRewriter_dispose(r.c)
46+
}

clang/translationunit_gen.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package clang
22

33
// #include "./clang-c/Index.h"
4+
// #include "./clang-c/Rewrite.h"
45
// #include "go-clang.h"
56
import "C"
67
import (
@@ -489,3 +490,8 @@ func (tu TranslationUnit) CodeCompleteAt(completeFilename string, completeLine u
489490
func (tu TranslationUnit) FindIncludesInFile(file File, visitor CursorAndRangeVisitor) Result {
490491
return Result(C.clang_findIncludesInFile(tu.c, file.c, visitor.c))
491492
}
493+
494+
// Create CXRewriter.
495+
func (tu TranslationUnit) Create() Rewriter {
496+
return Rewriter{C.clang_CXRewriter_create(tu.c)}
497+
}

0 commit comments

Comments
 (0)