clang++ - Evaluating constant expressions in clang tools -


i'm writing clang tool , i'm trying figure out how evaluate string literal given access program's ast. given following program:

class dholder {  public:   dholder(std::string s) {} };  dholder x("foo");     

i have following code in clang tool:

const cxxconstructexpr *ctor = ... // constructs `x` above const expr *expr = ctor->getarg(0); // "foo" expression ??? 

how can expr representing "foo" string literal actual c++ string in tool? i've tried like:

// exprconstant.cpp evaluate(result, info, expr); 

but don't know how initialize result , info parameters.

any clues?

the proper way use ast matchers match string literal , bind name can later referenced, this:

statementmatcher m =      constructexpr(hasargument(0, stringliteral().bind("myliteral"))).bind("myctor"); 

and in match callback this:

const cxxconstructexpr *ctor =      result.nodes.getnodeas<cxxconstructexpr("optionmatcher");  const stringliteral *optnameliteral =      result.nodes.getnodeas<stringliteral>("optname"); 

the literal can accessed through

optnameliteral->getstring().str(); 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -