Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions _xtool/llcppsymg/_cmptest/clangutils_test/clangutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

func main() {
TestClangUtil()
TestPreProcess()
}

func TestClangUtil() {
Expand Down Expand Up @@ -117,3 +118,32 @@ func TestClangUtil() {
fmt.Println()
}
}

func TestPreProcess() {
config := &clangutils.Config{
File: `
#include <inter.h>
#include <compat.h>
`,
Temp: true,
IsCpp: false,
Args: []string{"-I./hfile", "-E"},
}
index, unit, err := clangutils.CreateTranslationUnit(config)
if err != nil {
fmt.Printf("CreateTranslationUnit failed: %v\n", err)
}

fmt.Println("CreateTranslationUnit succeeded")

cursor := unit.Cursor()

clangutils.VisitChildren(cursor, func(cursor, parent clang.Cursor) clang.ChildVisitResult {
if cursor.Kind != clang.CursorMacroDefinition {
fmt.Println(clang.GoString(cursor.Location().File().FileName()), clang.GoString(cursor.String()))
}
return clang.ChildVisit_Recurse
})
index.Dispose()
unit.Dispose()
}
4 changes: 4 additions & 0 deletions _xtool/llcppsymg/_cmptest/clangutils_test/hfile/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef COMPAT_H
#define COMPAT_H
typedef foo foo2;
#endif
6 changes: 6 additions & 0 deletions _xtool/llcppsymg/_cmptest/clangutils_test/hfile/inter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef INTER_H
#define INTER_H
typedef long foo;
#include "compat.h"
typedef foo2 foo3;
#endif
9 changes: 9 additions & 0 deletions _xtool/llcppsymg/_cmptest/clangutils_test/llgo.expect
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ Namespace: TestNamespace
Function/Method: namespaced_function
Scoping parts: [TestNamespace namespaced_function]

CreateTranslationUnit succeeded
temp.h inter.h
./hfile/inter.h compat.h
temp.h compat.h
./hfile/inter.h foo
./hfile/compat.h foo2
./hfile/compat.h foo
./hfile/inter.h foo3
./hfile/inter.h foo2

#stderr

Expand Down
Loading