Clang import; UnaryExprOrTypeTraitExpr

This commit is contained in:
Daniel Marjamäki 2020-01-09 17:31:46 +01:00
parent 7daa1bc11d
commit d842f00aef
2 changed files with 37 additions and 0 deletions

View File

@ -62,6 +62,7 @@ static const std::string StringLiteral = "StringLiteral";
static const std::string TemplateArgument = "TemplateArgument";
static const std::string TypedefDecl = "TypedefDecl";
static const std::string UnaryOperator = "UnaryOperator";
static const std::string UnaryExprOrTypeTraitExpr = "UnaryExprOrTypeTraitExpr";
static const std::string VarDecl = "VarDecl";
static const std::string WhileStmt = "WhileStmt";
@ -179,6 +180,7 @@ namespace clangastdump {
std::string getType() const;
std::string getTemplateParameters() const;
const Scope *getNestedInScope(TokenList *tokenList);
void setValueType(Token *tok);
int mFile = 0;
int mLine = 1;
@ -303,6 +305,21 @@ const Scope *clangastdump::AstNode::getNestedInScope(TokenList *tokenList)
return tokenList->back()->scope();
}
void clangastdump::AstNode::setValueType(Token *tok)
{
int typeIndex = -1;
if (nodeType == UnaryExprOrTypeTraitExpr)
typeIndex = mExtTokens.size() - 3;
else
return;
TokenList decl(nullptr);
addTypeTokens(&decl, mExtTokens[typeIndex]);
if (Token::simpleMatch(decl.front(), "unsigned long"))
tok->setValueType(new ValueType(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0));
}
Scope *clangastdump::AstNode::createScope(TokenList *tokenList, Scope::ScopeType scopeType, AstNodePtr astNode)
{
std::vector<AstNodePtr> children{astNode};
@ -567,6 +584,18 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
unop->astOperand1(children[0]->createTokens(tokenList));
return unop;
}
if (nodeType == UnaryExprOrTypeTraitExpr) {
Token *tok1 = addtoken(tokenList, getSpelling());
Token *par1 = addtoken(tokenList, "(");
addTypeTokens(tokenList, mExtTokens.back());
Token *par2 = addtoken(tokenList, ")");
par1->link(par2);
par2->link(par1);
par1->astOperand1(tok1);
par1->astOperand2(par1->next());
setValueType(par1);
return par1;
}
if (nodeType == VarDecl)
return createTokensVarDecl(tokenList);
if (nodeType == WhileStmt) {

View File

@ -53,6 +53,7 @@ private:
TEST_CASE(typedefDecl1);
TEST_CASE(typedefDecl2);
TEST_CASE(typedefDecl3);
TEST_CASE(unaryExprOrTypeTraitExpr);
TEST_CASE(vardecl1);
TEST_CASE(vardecl2);
TEST_CASE(vardecl3);
@ -379,6 +380,13 @@ private:
ASSERT_EQUALS("typedef char * __builtin_ms_va_list ;", parse(clang));
}
void unaryExprOrTypeTraitExpr() {
const char clang[] = "`-VarDecl 0x24cc610 <a.cpp:1:1, col:19> col:5 x 'int' cinit\n"
" `-ImplicitCastExpr 0x24cc6e8 <col:9, col:19> 'int' <IntegralCast>\n"
" `-UnaryExprOrTypeTraitExpr 0x24cc6c8 <col:9, col:19> 'unsigned long' sizeof 'int'\n";
ASSERT_EQUALS("int x@1 = sizeof ( int ) ;", parse(clang));
}
void vardecl1() {
const char clang[] = "|-VarDecl 0x32b8aa0 <1.c:1:1, col:9> col:5 used a 'int' cinit\n"
"| `-IntegerLiteral 0x32b8b40 <col:9> 'int' 1\n"