Clang import; CXXConstructExpr
This commit is contained in:
parent
c23d33fc0a
commit
7a3bedb583
|
@ -38,6 +38,7 @@ static const std::string ContinueStmt = "ContinueStmt";
|
|||
static const std::string CStyleCastExpr = "CStyleCastExpr";
|
||||
static const std::string CXXBoolLiteralExpr = "CXXBoolLiteralExpr";
|
||||
static const std::string CXXConstructorDecl = "CXXConstructorDecl";
|
||||
static const std::string CXXConstructExpr = "CXXConstructExpr";
|
||||
static const std::string CXXMemberCallExpr = "CXXMemberCallExpr";
|
||||
static const std::string CXXMethodDecl = "CXXMethodDecl";
|
||||
static const std::string CXXOperatorCallExpr = "CXXOperatorCallExpr";
|
||||
|
@ -251,29 +252,10 @@ std::string clangimport::AstNode::getSpelling() const
|
|||
|
||||
std::string clangimport::AstNode::getType() const
|
||||
{
|
||||
if (nodeType == BinaryOperator)
|
||||
return unquote(mExtTokens[mExtTokens.size() - 2]);
|
||||
if (nodeType == CStyleCastExpr)
|
||||
return unquote((mExtTokens.back() == "<NoOp>") ?
|
||||
mExtTokens[mExtTokens.size() - 2] :
|
||||
mExtTokens.back());
|
||||
if (nodeType == CXXStaticCastExpr)
|
||||
return unquote(mExtTokens[mExtTokens.size() - 3]);
|
||||
if (nodeType == DeclRefExpr)
|
||||
return unquote(mExtTokens.back());
|
||||
if (nodeType == FunctionDecl) {
|
||||
int retTypeIndex = mExtTokens.size() - 1;
|
||||
while (mExtTokens[retTypeIndex][0] != '\'')
|
||||
retTypeIndex--;
|
||||
return unquote(mExtTokens[retTypeIndex]);
|
||||
}
|
||||
if (nodeType == IntegerLiteral)
|
||||
return unquote(mExtTokens[mExtTokens.size() - 2]);
|
||||
if (nodeType == TypedefDecl)
|
||||
return unquote(mExtTokens.back());
|
||||
if (nodeType == UnaryExprOrTypeTraitExpr)
|
||||
return unquote(mExtTokens[mExtTokens.size() - 3]);
|
||||
return "";
|
||||
int typeIndex = mExtTokens.size() - 1;
|
||||
while (typeIndex >= 0 && mExtTokens[typeIndex][0] != '\'')
|
||||
typeIndex--;
|
||||
return typeIndex == -1 ? "" : unquote(mExtTokens[typeIndex]);
|
||||
}
|
||||
|
||||
std::string clangimport::AstNode::getTemplateParameters() const
|
||||
|
@ -524,6 +506,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
|
|||
tokenList->back()->setValueType(new ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0));
|
||||
return tokenList->back();
|
||||
}
|
||||
if (nodeType == CXXConstructExpr)
|
||||
return children[0]->createTokens(tokenList);
|
||||
if (nodeType == CXXMethodDecl) {
|
||||
createTokensFunctionDecl(tokenList);
|
||||
return nullptr;
|
||||
|
|
|
@ -38,6 +38,7 @@ private:
|
|||
TEST_CASE(cstyleCastExpr);
|
||||
TEST_CASE(cxxBoolLiteralExpr);
|
||||
TEST_CASE(cxxConstructorDecl);
|
||||
TEST_CASE(cxxConstructExpr);
|
||||
TEST_CASE(cxxMemberCall);
|
||||
TEST_CASE(cxxOperatorCallExpr);
|
||||
TEST_CASE(cxxStaticCastExpr1);
|
||||
|
@ -200,6 +201,17 @@ private:
|
|||
ASSERT_EQUALS("void C ( ) { this . x@1 = 0 ; } int x@1", parse(clang));
|
||||
}
|
||||
|
||||
void cxxConstructExpr() {
|
||||
const char clang[] = "`-FunctionDecl 0x2dd7940 <line:2:1, col:30> col:5 f 'Foo (Foo)'\n"
|
||||
" |-ParmVarDecl 0x2dd7880 <col:7, col:11> col:11 used foo 'Foo'\n"
|
||||
" `-CompoundStmt 0x2dd80c0 <col:16, col:30>\n"
|
||||
" `-ReturnStmt 0x2dd80a8 <col:18, col:25>\n"
|
||||
" `-CXXConstructExpr 0x2dd8070 <col:25> 'Foo' 'void (Foo &&) noexcept'\n"
|
||||
" `-ImplicitCastExpr 0x2dd7f28 <col:25> 'Foo' xvalue <NoOp>\n"
|
||||
" `-DeclRefExpr 0x2dd7a28 <col:25> 'Foo' lvalue ParmVar 0x2dd7880 'foo' 'Foo'";
|
||||
ASSERT_EQUALS("Foo f ( Foo foo@1 ) { return foo@1 ; }", parse(clang));
|
||||
}
|
||||
|
||||
void cxxMemberCall() {
|
||||
const char clang[] = "`-FunctionDecl 0x320dc80 <line:2:1, col:33> col:6 bar 'void ()'\n"
|
||||
" `-CompoundStmt 0x323bb08 <col:12, col:33>\n"
|
||||
|
|
Loading…
Reference in New Issue