From 459e906ae1ca8103caa23d1cffaeee41782cf7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 21 Jan 2020 07:00:03 +0100 Subject: [PATCH] Clang import; ConditionalExpr --- lib/clangimport.cpp | 13 +++++++++++++ test/testclangimport.cpp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 7fa37083f..606b71b4c 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -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()); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 5491b5f79..cf621f05d 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -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 col:5 x 'int' cinit\n" + " `-ConditionalOperator 0x257cda8 'int'\n" + " |-ImplicitCastExpr 0x257cd60 'int' \n" + " | `-DeclRefExpr 0x257cce8 'int' lvalue Var 0x257cae0 'a' 'int'\n" + " |-ImplicitCastExpr 0x257cd78 'int' \n" + " | `-DeclRefExpr 0x257cd10 'int' lvalue Var 0x257cb98 'b' 'int'\n" + " `-ImplicitCastExpr 0x257cd90 'int' \n" + " `-DeclRefExpr 0x257cd38 '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 \n"