diff --git a/_xtool/llcppsymg/_cmptest/clangutils_test/clangutils.go b/_xtool/llcppsymg/_cmptest/clangutils_test/clangutils.go index 80816b50..9d178b20 100644 --- a/_xtool/llcppsymg/_cmptest/clangutils_test/clangutils.go +++ b/_xtool/llcppsymg/_cmptest/clangutils_test/clangutils.go @@ -11,6 +11,7 @@ import ( func main() { TestClangUtil() + TestPreProcess() } func TestClangUtil() { @@ -117,3 +118,32 @@ func TestClangUtil() { fmt.Println() } } + +func TestPreProcess() { + config := &clangutils.Config{ + File: ` + #include + #include + `, + 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() +} diff --git a/_xtool/llcppsymg/_cmptest/clangutils_test/hfile/compat.h b/_xtool/llcppsymg/_cmptest/clangutils_test/hfile/compat.h new file mode 100644 index 00000000..9547760c --- /dev/null +++ b/_xtool/llcppsymg/_cmptest/clangutils_test/hfile/compat.h @@ -0,0 +1,4 @@ +#ifndef COMPAT_H +#define COMPAT_H +typedef foo foo2; +#endif diff --git a/_xtool/llcppsymg/_cmptest/clangutils_test/hfile/inter.h b/_xtool/llcppsymg/_cmptest/clangutils_test/hfile/inter.h new file mode 100644 index 00000000..061cc0f3 --- /dev/null +++ b/_xtool/llcppsymg/_cmptest/clangutils_test/hfile/inter.h @@ -0,0 +1,6 @@ +#ifndef INTER_H +#define INTER_H +typedef long foo; +#include "compat.h" +typedef foo2 foo3; +#endif \ No newline at end of file diff --git a/_xtool/llcppsymg/_cmptest/clangutils_test/llgo.expect b/_xtool/llcppsymg/_cmptest/clangutils_test/llgo.expect index de8589e7..22a4f083 100644 --- a/_xtool/llcppsymg/_cmptest/clangutils_test/llgo.expect +++ b/_xtool/llcppsymg/_cmptest/clangutils_test/llgo.expect @@ -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