<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000">
I am trying to use the module functionalities from libclang. Here is
the context:<br>
<br>
I have a clang module defined and a source file that call it:<br>
<br>
module.modulemap<br>
<br>
<blockquote>module test {<br>
requires cplusplus<br>
header "test.h"<br>
}<br>
</blockquote>
test.h :<br>
<br>
<blockquote>#pragma once<br>
<br>
static inline int foo() { return 1; }<br>
</blockquote>
test.cpp :<br>
<br>
<blockquote>// Try the following command:<br>
// clang++ -fmodules -fcxx-modules
-fmodules-cache-path=./cache_path -c test.cpp<br>
// If you see stuff in the ./cache_path directory, then it works!<br>
#include "test.h"<br>
<br>
int main(int, char **) {<br>
return foo();<br>
}<br>
</blockquote>
cache_path is at first empty then after the command in the comments
I can see stuff in it so this is working.<br>
<br>
My problem is when I try to use libclang to parse the test.cpp file
in order to get informations about module:<br>
<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<blockquote>#include <stdio.h><br>
#include "clang-c/Index.h"<br>
/*<br>
compile with:<br>
clang -lclang -o module_parser module_parser.c<br>
*/<br>
static enum CXChildVisitResult <br>
visitor(CXCursor cursor, CXCursor parent, CXClientData data)<br>
{<br>
CXSourceLocation loc;<br>
CXFile file;<br>
CXString module_import;<br>
CXModule module;<br>
CXString module_name;<br>
CXString module_full_name;<br>
unsigned line;<br>
unsigned column;<br>
unsigned offset;<br>
if (clang_getCursorKind(cursor) == CXCursor_ModuleImportDecl)<br>
{<br>
loc = clang_getCursorLocation(cursor);<br>
clang_getSpellingLocation(loc,<br>
&file,<br>
&line,<br>
&column,<br>
&offset);<br>
<br>
module_import = clang_getCursorSpelling(cursor);<br>
printf("Module import dec at line: %d \"%s\"\n", line,
clang_getCString(module_import));<br>
clang_disposeString(module_import);<br>
}<br>
module = clang_Cursor_getModule(cursor);<br>
module_name = clang_Module_getName(module);<br>
module_full_name = clang_Module_getFullName(module);<br>
printf("Module name %s , full name %s\n",
clang_getCString(module_name),<br>
clang_getCString(module_full_name));<br>
clang_disposeString(module_name);<br>
clang_disposeString(module_full_name);<br>
<br>
return CXChildVisit_Recurse; // visit complete AST recursivly<br>
}<br>
<br>
int main(int argc, char *argv[]) {<br>
CXIndex Index = clang_createIndex(0, 1);<br>
const char *args[] = { "-x",<br>
"c++",<br>
"-fmodules",<br>
"-fcxxmodules"//,<br>
"-fmodules-cache-path",<br>
"cache_path"<br>
};<br>
CXTranslationUnit TU =
clang_createTranslationUnitFromSourceFile(Index,<br>
"test.cpp",<br>
6,<br>
args,<br>
0,<br>
0);<br>
<br>
clang_visitChildren(clang_getTranslationUnitCursor(TU), visitor,
0);<br>
<br>
clang_disposeTranslationUnit(TU);<br>
clang_disposeIndex(Index);<br>
return 0;<br>
}<br>
</blockquote>
<br>
The output of this code is :<br>
<br>
<blockquote>...<br>
Module name , full name <br>
Module name , full name <br>
Module name , full name <br>
Module name , full name <br>
Module name , full name <br>
...<br>
</blockquote>
First it seems that clang doesn't detect any cursor of the kind
CXCursor_ModuleImportDecl and then at any momment it find a valid
module.<br>
<br>
What am I doing wrong?<br>
<br>
<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</body>
</html>