Clang import; ConditionalExpr

This commit is contained in:
Daniel Marjamäki 2020-01-21 07:00:03 +01:00
parent e5662ceef2
commit 459e906ae1
2 changed files with 26 additions and 0 deletions

View File

@ -34,6 +34,7 @@ static const std::string CaseStmt = "CaseStmt";
static const std::string CharacterLiteral = "CharacterLiteral";
static const std::string ClassTemplateDecl = "ClassTemplateDecl";
static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl";
static const std::string ConditionalOperator = "ConditionalOperator";
static const std::string CompoundAssignOperator = "CompoundAssignOperator";
static const std::string CompoundStmt = "CompoundStmt";
static const std::string ContinueStmt = "ContinueStmt";
@ -537,6 +538,18 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
createTokensForCXXRecord(tokenList);
return nullptr;
}
if (nodeType == ConditionalOperator) {
Token *expr1 = children[0]->createTokens(tokenList);
Token *tok1 = addtoken(tokenList, "?");
Token *expr2 = children[1]->createTokens(tokenList);
Token *tok2 = addtoken(tokenList, ":");
Token *expr3 = children[2]->createTokens(tokenList);
tok2->astOperand1(expr2);
tok2->astOperand1(expr3);
tok1->astOperand1(expr1);
tok1->astOperand2(tok2);
return tok1;
}
if (nodeType == CompoundAssignOperator) {
Token *lhs = children[0]->createTokens(tokenList);
Token *assign = addtoken(tokenList, getSpelling());

View File

@ -36,6 +36,7 @@ private:
TEST_CASE(class1);
TEST_CASE(classTemplateDecl1);
TEST_CASE(classTemplateDecl2);
TEST_CASE(conditionalExpr);
TEST_CASE(compoundAssignOperator);
TEST_CASE(continueStmt);
TEST_CASE(cstyleCastExpr);
@ -218,6 +219,18 @@ private:
ASSERT_EQUALS("class C { int foo ( ) { return 0 ; } }", parse(clang));
}
void conditionalExpr() {
const char clang[] = "`-VarDecl 0x257cc88 <line:4:1, col:13> col:5 x 'int' cinit\n"
" `-ConditionalOperator 0x257cda8 <col:9, col:13> 'int'\n"
" |-ImplicitCastExpr 0x257cd60 <col:9> 'int' <LValueToRValue>\n"
" | `-DeclRefExpr 0x257cce8 <col:9> 'int' lvalue Var 0x257cae0 'a' 'int'\n"
" |-ImplicitCastExpr 0x257cd78 <col:11> 'int' <LValueToRValue>\n"
" | `-DeclRefExpr 0x257cd10 <col:11> 'int' lvalue Var 0x257cb98 'b' 'int'\n"
" `-ImplicitCastExpr 0x257cd90 <col:13> 'int' <LValueToRValue>\n"
" `-DeclRefExpr 0x257cd38 <col:13> 'int' lvalue Var 0x257cc10 'c' 'int'";
ASSERT_EQUALS("int x@1 = a ? b : c ;", parse(clang));
}
void compoundAssignOperator() {
const char clang[] = "`-FunctionDecl 0x3570690 <1.cpp:2:1, col:25> col:6 f 'void ()'\n"
" `-CompoundStmt 0x3570880 <col:10, col:25>\n"