AST in JSONFormat

2019-06-08 Thread Monalisa Rout via cfe-commits
Hello,

I am using LibTooling to dump the clangAST in JSON format which is
available in clang 9.
I need the JSON Schema for that. Is it available ??

If not wil you be interested in one ??

Regards,
Mona
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


LLVM Types

2019-08-06 Thread Monalisa Rout via cfe-commits
Hello,
Can I dump LLVM Type hierarchies somehow ??

Types which are declared in this file ("clang/AST/Type.h
"  )

Regards,
Mona
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


AST for For loop

2019-08-06 Thread Monalisa Rout via cfe-commits
Hello,
While dumping the AST for For loop, Why do I get  <<>> ??

Source code:
void func()
{
for (int i = 0; i < 5; i++)
break;
}

AST

FunctionDecl 0x4a4ac10

line:2:6 func 'void ()'
`-CompoundStmt 0x4a4ae1c 
  `-ForStmt 0x4a4adf8 
|-DeclStmt 0x4a4ad38 
| `-VarDecl 0x4a4acd0  col:11 used i 'int' cinit
|   `-IntegerLiteral 0x4a4ad10  'int' 0
|-<<>>
|-BinaryOperator 0x4a4ada8  'int' '<'
| |-ImplicitCastExpr 0x4a4ad98  'int' 
| | `-DeclRefExpr 0x4a4ad50  'int' lvalue Var 0x4a4acd0 'i'
'int'
| `-IntegerLiteral 0x4a4ad70  'int' 5
|-UnaryOperator 0x4a4ade0  'int' postfix '++'
| `-DeclRefExpr 0x4a4adc0  'int' lvalue Var 0x4a4acd0 'i' 'int'
`-BreakStmt 0x4a4adf0 

Regards,
Mona
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: AST for For loop

2019-08-06 Thread Monalisa Rout via cfe-commits
Awesome, thanks!

On Tue, Aug 6, 2019 at 5:18 PM Aaron Ballman  wrote:

> On Tue, Aug 6, 2019 at 11:15 AM Monalisa Rout via cfe-commits
>  wrote:
> >
> > Hello,
> > While dumping the AST for For loop, Why do I get  <<>> ??
> >
> > Source code:
> > void func()
> > {
> > for (int i = 0; i < 5; i++)
> > break;
> > }
> >
> > AST
> >
> > FunctionDecl 0x4a4ac10
> 
> line:2:6 func 'void ()'
> > `-CompoundStmt 0x4a4ae1c 
> >   `-ForStmt 0x4a4adf8 
> > |-DeclStmt 0x4a4ad38 
> > | `-VarDecl 0x4a4acd0  col:11 used i 'int' cinit
> > |   `-IntegerLiteral 0x4a4ad10  'int' 0
> > |-<<>>
> > |-BinaryOperator 0x4a4ada8  'int' '<'
> > | |-ImplicitCastExpr 0x4a4ad98  'int' 
> > | | `-DeclRefExpr 0x4a4ad50  'int' lvalue Var 0x4a4acd0 'i'
> 'int'
> > | `-IntegerLiteral 0x4a4ad70  'int' 5
> > |-UnaryOperator 0x4a4ade0  'int' postfix '++'
> > | `-DeclRefExpr 0x4a4adc0  'int' lvalue Var 0x4a4acd0 'i'
> 'int'
> > `-BreakStmt 0x4a4adf0 
>
> The AST dumps child nodes by calling children() on a given AST node.
> The ForStmt node always has five child nodes, which are (in order):
> init statement, condition variable, condition, increment, and body.
> Some of those may be NULL depending on the format of the for loop
> (your for loop example has no condition variable, for instance).
>
> HTH!
>
> ~Aaron
>
> >
> > Regards,
> > Mona
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


QualType

2019-08-15 Thread Monalisa Rout via cfe-commits
Hello,
I want to create QualType instances for *const int*, *int* const*,  and *const
int* const.*
How can I do that??

Regards,
Mona
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Dumping Clang AST to a file

2019-07-09 Thread Monalisa Rout via cfe-commits
Hello, Currently I am dumping the Clang AST to the console but I want to
write it to a file.

I have pasted the code snippet.

bool HandleTopLevelDecl(DeclGroupRef DR) override {
for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
(*b)->dump(llvm::errs(), false,clang::ADOF_JSON);
}
return true;
}

How this can be done ?? Any help is appreciated.

Regards,
Mona
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


-isysem path

2019-10-09 Thread Monalisa Rout via cfe-commits
Hello,

I have created one visual studio application by using LibTooling library.
I am dumping the AST and all LLVM Types. I want to pass the isystem path to
the
clangTool object.

I have declared the isystem path in the Command Arguments
(Project->Properties->Debugging->Command Arguments)
input.c Output.json -isystem xxx

static llvm::cl::list ISystemPaths(
"isystem", llvm::cl::ZeroOrMore, llvm::cl::value_desc("filename"),
llvm::cl::desc("This is isystem"));

I have read that command argument as well, but I have no idea how to use it
further.

Have a look at my source code if that would help you to understand the
problem clearly.

[ clang -Xclang -ast-dump input.c -isystem xxx ] - I dont want to use like
this.

Regards,
Mona

#include
using namespace std;
#include 
#include 

#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/raw_ostream.h"
#include 
#include "llvm/Support/JSON.h"
#include "clang/AST/JSONNodeDumper.h"
#include "clang/Basic/DiagnosticIDs.h"
using namespace clang;
using namespace clang::driver;
using namespace clang::tooling;

static llvm::cl::OptionCategory ToolingSampleCategory("Tooling Sample");

static llvm::cl::list ISystemPaths(
"isystem", llvm::cl::ZeroOrMore, llvm::cl::value_desc("filename"),
llvm::cl::desc("This is isystem"));


StringRef 
stringref1("D:\\Data\\Rout\\svn\\ASTJSONProject\\ASTJSONProject\\defaultOutput.json");
llvm::raw_fd_ostream Sdefault(stringref1, std::error_code());
std::string outputPath;
// By implementing RecursiveASTVisitor, we can specify which AST nodes
// we're interested in by overriding relevant methods.
class MyASTVisitor : public RecursiveASTVisitor {
public:
MyASTVisitor(Rewriter &R) : TheRewriter(R) {}

bool VisitStmt(Stmt *s) {

return true;
}

// how to make out function def, fuction call and function declaration.
bool VisitFunctionDecl(FunctionDecl *f) {
// Only function definitions (with bodies), not declarations.
if (f->hasBody()) {
Stmt *FuncBody = f->getBody();
// Type name as string
QualType QT = f->getReturnType();
std::string TypeStr = QT.getAsString();

// Function name
DeclarationName DeclName = f->getNameInfo().getName();
std::string FuncName = DeclName.getAsString();
}

return true;
}
bool VisitDecl(Decl *D) 
{ 
if (isa(D))
return true;
}

bool VisitExpr(const Expr *E)
{


return true;
}
bool VisitRecordDecl(RecordDecl *Declaration) {
// For debugging, dumping the AST nodes will show which nodes 
are already
// being visited.
//Declaration->dump(llvm::errs(), false, clang::ADOF_JSON);

// The return value indicates whether we want the visitation to 
proceed.
// Return false to stop the traversal of the AST.
return true;
}

private:
Rewriter & TheRewriter;
//private Block block; // available in Gecos library
};


// Implementation of the ASTConsumer interface for reading an AST produced
// by the Clang parser.


class MyASTConsumer : public ASTConsumer {
public:
llvm::raw_fd_ostream S = { StringRef(outputPath) , std::error_code() };
MyASTConsumer(Rewriter &R) : Visitor(R) {
/*StringRef stringref(outputPath);
llvm::raw_fd_ostream S(stringref, std::error_code());*/
S << "{";
S<< "\n";
std::string str("\"root\"");
S << str;
S << ":";
S<< "\n";
S << "[";
S<< "\n";
}

// Override the method that gets called for each parsed top-level
// declaration.
bool HandleTopLevelDecl(DeclGroupRef DR) override { 

for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != 
e; ++b) {
// Traverse the declaration using our AST visitor.
RecordDecl *recordDecl = dyn_cast(*b);
TypedefDecl* typedefdecl = dyn_cast(*b);
if (recordDecl)
{
std::vector recordVec;
//const struct
QualType reco