Skip to content

Commit

Permalink
clang: update to clang v4
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <[email protected]>
  • Loading branch information
zchee committed Nov 10, 2021
1 parent b06cefa commit 5a44304
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 95 deletions.
3 changes: 3 additions & 0 deletions clang/callingconv_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
CallingConv_X86Pascal = C.CXCallingConv_X86Pascal
CallingConv_AAPCS = C.CXCallingConv_AAPCS
CallingConv_AAPCS_VFP = C.CXCallingConv_AAPCS_VFP
CallingConv_X86RegCall = C.CXCallingConv_X86RegCall
CallingConv_IntelOclBicc = C.CXCallingConv_IntelOclBicc
CallingConv_X86_64Win64 = C.CXCallingConv_X86_64Win64
CallingConv_X86_64SysV = C.CXCallingConv_X86_64SysV
Expand Down Expand Up @@ -46,6 +47,8 @@ func (cc CallingConv) Spelling() string {
return "CallingConv=AAPCS"
case CallingConv_AAPCS_VFP:
return "CallingConv=AAPCS_VFP"
case CallingConv_X86RegCall:
return "CallingConv=X86RegCall"
case CallingConv_IntelOclBicc:
return "CallingConv=IntelOclBicc"
case CallingConv_X86_64Win64:
Expand Down
1 change: 1 addition & 0 deletions clang/cgoflags_dynamic.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !static
// +build !static

package clang
Expand Down
3 changes: 1 addition & 2 deletions clang/cgoflags_static.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build static
// +build static

package clang

import "C"
89 changes: 79 additions & 10 deletions clang/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
*/
#define CINDEX_VERSION_MAJOR 0
#define CINDEX_VERSION_MINOR 35
#define CINDEX_VERSION_MINOR 37

#define CINDEX_VERSION_ENCODE(major, minor) ( \
((major) * 10000) \
Expand Down Expand Up @@ -328,7 +328,7 @@ clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
*
* \param tu the translation unit
*
* \param file_name the name of the file.
* \param file_name the name of the file.
*
* \returns the file handle for the named file in the translation unit \p tu,
* or a NULL file handle if the file was not a part of this translation unit.
Expand Down Expand Up @@ -628,6 +628,15 @@ typedef struct {
CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu,
CXFile file);

/**
* \brief Retrieve all ranges from all files that were skipped by the
* preprocessor.
*
* The preprocessor will skip lines when they are surrounded by an
* if/ifdef/ifndef directive whose condition does not evaluate to true.
*/
CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit tu);

/**
* \brief Destroy the given \c CXSourceRangeList.
*/
Expand Down Expand Up @@ -2327,7 +2336,47 @@ enum CXCursorKind {
*/
CXCursor_OMPTargetParallelForSimdDirective = 269,

CXCursor_LastStmt = CXCursor_OMPTargetParallelForSimdDirective,
/** \brief OpenMP target simd directive.
*/
CXCursor_OMPTargetSimdDirective = 270,

/** \brief OpenMP teams distribute directive.
*/
CXCursor_OMPTeamsDistributeDirective = 271,

/** \brief OpenMP teams distribute simd directive.
*/
CXCursor_OMPTeamsDistributeSimdDirective = 272,

/** \brief OpenMP teams distribute parallel for simd directive.
*/
CXCursor_OMPTeamsDistributeParallelForSimdDirective = 273,

/** \brief OpenMP teams distribute parallel for directive.
*/
CXCursor_OMPTeamsDistributeParallelForDirective = 274,

/** \brief OpenMP target teams directive.
*/
CXCursor_OMPTargetTeamsDirective = 275,

/** \brief OpenMP target teams distribute directive.
*/
CXCursor_OMPTargetTeamsDistributeDirective = 276,

/** \brief OpenMP target teams distribute parallel for directive.
*/
CXCursor_OMPTargetTeamsDistributeParallelForDirective = 277,

/** \brief OpenMP target teams distribute parallel for simd directive.
*/
CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective = 278,

/** \brief OpenMP target teams distribute simd directive.
*/
CXCursor_OMPTargetTeamsDistributeSimdDirective = 279,

CXCursor_LastStmt = CXCursor_OMPTargetTeamsDistributeSimdDirective,

/**
* \brief Cursor that represents the translation unit itself.
Expand Down Expand Up @@ -2385,8 +2434,12 @@ enum CXCursorKind {
* \brief A static_assert or _Static_assert node
*/
CXCursor_StaticAssert = 602,
/**
* \brief a friend declaration.
*/
CXCursor_FriendDecl = 603,
CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
CXCursor_LastExtraDecl = CXCursor_StaticAssert,
CXCursor_LastExtraDecl = CXCursor_FriendDecl,

/**
* \brief A code completion overload candidate.
Expand Down Expand Up @@ -3003,7 +3056,7 @@ enum CXCallingConv {
CXCallingConv_X86Pascal = 5,
CXCallingConv_AAPCS = 6,
CXCallingConv_AAPCS_VFP = 7,
/* Value 8 was PnaclCall, but it was never used, so it could safely be re-used. */
CXCallingConv_X86RegCall = 8,
CXCallingConv_IntelOclBicc = 9,
CXCallingConv_X86_64Win64 = 10,
CXCallingConv_X86_64SysV = 11,
Expand Down Expand Up @@ -3493,11 +3546,8 @@ enum CXRefQualifierKind {
};

/**
* \brief Returns the number of template arguments for given class template
* specialization, or -1 if type \c T is not a class template specialization.
*
* Variadic argument packs count as only one argument, and can not be inspected
* further.
* \brief Returns the number of template arguments for given template
* specialization, or -1 if type \c T is not a template specialization.
*/
CINDEX_LINKAGE int clang_Type_getNumTemplateArguments(CXType T);

Expand Down Expand Up @@ -5241,6 +5291,25 @@ CINDEX_LINKAGE CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E);
*/
CINDEX_LINKAGE int clang_EvalResult_getAsInt(CXEvalResult E);

/**
* \brief Returns the evaluation result as a long long integer if the
* kind is Int. This prevents overflows that may happen if the result is
* returned with clang_EvalResult_getAsInt.
*/
CINDEX_LINKAGE long long clang_EvalResult_getAsLongLong(CXEvalResult E);

/**
* \brief Returns a non-zero value if the kind is Int and the evaluation
* result resulted in an unsigned integer.
*/
CINDEX_LINKAGE unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E);

/**
* \brief Returns the evaluation result as an unsigned integer if
* the kind is Int and clang_EvalResult_isUnsignedInt is non-zero.
*/
CINDEX_LINKAGE unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E);

/**
* \brief Returns the evaluation result as double if the
* kind is double.
Expand Down
23 changes: 16 additions & 7 deletions clang/clang_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package clang

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestBasicParsing(t *testing.T) {
idx := NewIndex(0, 1)
defer idx.Dispose()

tu := idx.ParseTranslationUnit("../testdata/basicparsing.c", nil, nil, 0)
assert.True(t, tu.IsValid())
if !tu.IsValid() {
t.Fatal("tu is invalid")
}
defer tu.Dispose()

found := 0
Expand All @@ -23,19 +24,25 @@ func TestBasicParsing(t *testing.T) {

switch cursor.Kind() {
case Cursor_FunctionDecl:
assert.Equal(t, "foo", cursor.Spelling())
if "foo" != cursor.Spelling() {
t.Fatalf("want foo but got %s", cursor.Spelling())
}

found++
case Cursor_ParmDecl:
assert.Equal(t, "bar", cursor.Spelling())
if "bar" != cursor.Spelling() {
t.Fatalf("want bar but got %s", cursor.Spelling())
}

found++
}

return ChildVisit_Recurse
})

assert.Equal(t, 2, found, "Did not find all nodes")
if !reflect.DeepEqual(2, found) {
t.Fatal("Did not find all nodes")
}
}

func TestReparse(t *testing.T) {
Expand All @@ -47,7 +54,9 @@ func TestReparse(t *testing.T) {
defer idx.Dispose()

tu := idx.ParseTranslationUnit("hello.cpp", nil, us, 0)
assert.True(t, tu.IsValid())
if !tu.IsValid() {
t.Fatal("tu is invalid")
}
defer tu.Dispose()

ok := false
Expand Down
6 changes: 5 additions & 1 deletion clang/codecompleteresults.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package clang

func (ccr *CodeCompleteResults) Diagnostics() []Diagnostic { // TODO this can be generated https://github.com/go-clang/gen/issues/47
// TODO this can be generated https://github.com/go-clang/gen/issues/47

// Diagnostics determine the number of diagnostics produced prior to the
// location where code completion was performed.
func (ccr *CodeCompleteResults) Diagnostics() []Diagnostic {
s := make([]Diagnostic, ccr.NumDiagnostics())

for i := range s {
Expand Down
14 changes: 9 additions & 5 deletions clang/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ package clang
import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCompletion(t *testing.T) {
idx := NewIndex(0, 0)
defer idx.Dispose()

tu := idx.ParseTranslationUnit("cursor.c", nil, nil, 0)
assert.True(t, tu.IsValid())
if !tu.IsValid() {
t.Fatal("tu is invalid")
}
defer tu.Dispose()

res := tu.CodeCompleteAt("cursor.c", 5, 18, nil, 0)
assert.NotNil(t, res)
if res == nil {
t.Fatal("expected res is non-nil")
}
defer res.Dispose()

if n := len(res.Results()); n < 10 {
Expand Down Expand Up @@ -48,5 +50,7 @@ func TestCompletion(t *testing.T) {
}
t.Log(d.Severity(), d.Spelling())
}
assert.True(t, ok)
if !ok {
t.Fatal("not found diagnostics")
}
}
Loading

0 comments on commit 5a44304

Please sign in to comment.