Skip to content

Commit

Permalink
Overhaul treatment of source locations
Browse files Browse the repository at this point in the history
We are now much more precise; see discussion of `MultiLoc` in
`src/HsBindgen/Clang/Util/SourceLoc/Type.hs` for details.
  • Loading branch information
edsko committed Oct 5, 2024
1 parent 63a9b28 commit 1bcdb83
Show file tree
Hide file tree
Showing 22 changed files with 921 additions and 372 deletions.
10 changes: 10 additions & 0 deletions hs-bindgen-libclang/cbits/clang_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ enum CXChildVisitResult wrap_visitor(CXCursor cursor, CXCursor parent, CXClientD
WrapCXCursorVisitor visitor = client_data;
return visitor(&cursor, &parent);
}

/**
* Debugging
*/

void clang_breakpoint(void) {
static int i = 0;
fprintf(stderr, "clang_breakpoint: %d\n", ++i);
}

28 changes: 27 additions & 1 deletion hs-bindgen-libclang/cbits/clang_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ static inline void wrap_getCursorKindSpelling(enum CXCursorKind Kind, CXString*
*result = clang_getCursorKindSpelling(Kind);
}

static inline CXTranslationUnit wrap_Cursor_getTranslationUnit(const CXCursor* cursor) {
return clang_Cursor_getTranslationUnit(*cursor);
}

/**
* Traversing the AST with cursors
*
Expand Down Expand Up @@ -419,10 +423,26 @@ static inline void wrap_getExpansionLocation(const CXSourceLocation* location, C
clang_getExpansionLocation(*location, file, line, column, offset);
}

static inline void wrap_getPresumedLocation(const CXSourceLocation* location, CXString* filename, unsigned* line, unsigned* column) {
clang_getPresumedLocation(*location, filename, line, column);
}

static inline void wrap_getSpellingLocation(const CXSourceLocation* location, CXFile* file, unsigned* line, unsigned* column, unsigned* offset) {
clang_getSpellingLocation(*location, file, line, column, offset);
}

static inline void wrap_getFileLocation(const CXSourceLocation* location, CXFile* file, unsigned* line, unsigned* column, unsigned* offset) {
clang_getFileLocation(*location, file, line, column, offset);
}

static inline void wrap_getLocation(CXTranslationUnit tu, CXFile file, unsigned line, unsigned column, CXSourceLocation* result) {
*result = clang_getLocation(tu, file, line, column);
}

static inline void wrap_getRange(const CXSourceLocation* begin, const CXSourceLocation* end, CXSourceRange* result) {
*result = clang_getRange(*begin, *end);
}

static inline int wrap_Location_isFromMainFile(const CXSourceLocation* location) {
return clang_Location_isFromMainFile(*location);
}
Expand All @@ -448,4 +468,10 @@ static inline void wrap_disposeString(const CXString* string) {
clang_disposeString(*string);
}

#endif
/**
* Debugging
*/

void clang_breakpoint(void);

#endif
1 change: 1 addition & 0 deletions hs-bindgen-libclang/hs-bindgen-libclang.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ library
HsBindgen.Clang.Util.Diagnostics
HsBindgen.Clang.Util.Fold
HsBindgen.Clang.Util.SourceLoc
HsBindgen.Clang.Util.SourceLoc.Type
HsBindgen.Clang.Util.Tokens
other-modules:
HsBindgen.Clang.Core.Enums
Expand Down
Loading

0 comments on commit 1bcdb83

Please sign in to comment.