ASTContext is a class in the Clang C++ library that provides access to various information and utilities related to the syntax tree of a C++ program. One of its methods is getSourceManager, which returns the SourceManager object responsible for tracking source file locations and their contents.
Example code:
```c++
#include "clang/AST/ASTContext.h"
#include "clang/Basic/SourceManager.h"
// ...
void myFunction(ASTContext& context)
{
SourceManager& sm = context.getSourceManager();
// Get the filename and line number of the current position in the code
const auto& currLoc = sm.getExpansionLoc(context.getFullLoc(context.getCurrentDecl()->getBeginLoc()));
const std::string currFile = sm.getFilename(currLoc);
const int currLine = sm.getLineNumber(currLoc);
// ...
}
```
This example uses getSourceManager to obtain the current location in the code (i.e., the file name and line number), as well as to get other information about the Code. This example is part of Clang's AST library, which is included in the Clang package for C++ developers.
C++ (Cpp) ASTContext::getSourceManager - 30 examples found. These are the top rated real world C++ (Cpp) examples of ASTContext::getSourceManager extracted from open source projects. You can rate examples to help us improve the quality of examples.