Clang import; Arrays
This commit is contained in:
parent
7024d29a9d
commit
b829c4cebb
|
@ -24,6 +24,7 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
static const std::string ArraySubscriptExpr = "ArraySubscriptExpr";
|
||||
static const std::string BinaryOperator = "BinaryOperator";
|
||||
static const std::string CallExpr = "CallExpr";
|
||||
static const std::string CompoundStmt = "CompoundStmt";
|
||||
|
@ -246,6 +247,16 @@ Scope *clangastdump::AstNode::createScope(TokenList *tokenList, Scope::ScopeType
|
|||
|
||||
Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
||||
{
|
||||
if (nodeType == ArraySubscriptExpr) {
|
||||
Token *array = children[0]->createTokens(tokenList);
|
||||
Token *bracket1 = addtoken(tokenList, "[");
|
||||
Token *index = children[1]->createTokens(tokenList);
|
||||
Token *bracket2 = addtoken(tokenList, "]");
|
||||
bracket1->astOperand1(array);
|
||||
bracket1->astOperand2(index);
|
||||
bracket1->link(bracket2);
|
||||
return bracket1;
|
||||
}
|
||||
if (nodeType == BinaryOperator) {
|
||||
Token *tok1 = children[0]->createTokens(tokenList);
|
||||
Token *binop = addtoken(tokenList, unquote(mExtTokens.back()));
|
||||
|
@ -367,7 +378,7 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
|||
Token *vartok1 = addtoken(tokenList, name);
|
||||
Scope *scope = const_cast<Scope *>(tokenList->back()->scope());
|
||||
const AccessControl accessControl = (scope->type == Scope::ScopeType::eGlobal) ? (AccessControl::Global) : (AccessControl::Local);
|
||||
scope->varlist.push_back(Variable(vartok1, nullptr, nullptr, 0, accessControl, nullptr, scope, nullptr));
|
||||
scope->varlist.push_back(Variable(vartok1, type, 0, accessControl, nullptr, scope));
|
||||
mData->varDecl(addr, vartok1, &scope->varlist.back());
|
||||
addtoken(tokenList, ";");
|
||||
if (isInit) {
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class SymbolDatabase;
|
||||
class Tokenizer;
|
||||
|
||||
namespace clangastdump {
|
||||
|
|
|
@ -1723,6 +1723,36 @@ void SymbolDatabase::clangSetVariables(const std::vector<const Variable *> &vari
|
|||
mVariableList = variableList;
|
||||
}
|
||||
|
||||
Variable::Variable(const Token *name_, const std::string &clangType,
|
||||
nonneg int index_, AccessControl access_, const Type *type_,
|
||||
const Scope *scope_)
|
||||
: mNameToken(name_),
|
||||
mTypeStartToken(nullptr),
|
||||
mTypeEndToken(nullptr),
|
||||
mIndex(index_),
|
||||
mAccess(access_),
|
||||
mFlags(0),
|
||||
mType(type_),
|
||||
mScope(scope_),
|
||||
mValueType(nullptr)
|
||||
{
|
||||
|
||||
std::string::size_type pos = clangType.find("[");
|
||||
if (pos != std::string::npos) {
|
||||
setFlag(fIsArray, true);
|
||||
do {
|
||||
const std::string::size_type pos1 = pos+1;
|
||||
pos = clangType.find("]", pos1);
|
||||
Dimension dim;
|
||||
dim.tok = nullptr;
|
||||
dim.known = true;
|
||||
dim.num = MathLib::toLongNumber(clangType.substr(pos1, pos-pos1));
|
||||
mDimensions.push_back(dim);
|
||||
++pos;
|
||||
} while (pos < clangType.size() && clangType[pos] == '[');
|
||||
}
|
||||
}
|
||||
|
||||
Variable::~Variable()
|
||||
{
|
||||
delete mValueType;
|
||||
|
|
|
@ -235,6 +235,10 @@ public:
|
|||
evaluate(settings);
|
||||
}
|
||||
|
||||
Variable(const Token *name_, const std::string &clangType,
|
||||
nonneg int index_, AccessControl access_, const Type *type_,
|
||||
const Scope *scope_);
|
||||
|
||||
~Variable();
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,7 @@ private:
|
|||
TEST_CASE(funcdecl1);
|
||||
TEST_CASE(funcdecl2);
|
||||
TEST_CASE(vardecl1);
|
||||
TEST_CASE(vardecl2);
|
||||
}
|
||||
|
||||
std::string parse(const char clang[]) {
|
||||
|
@ -76,6 +77,25 @@ private:
|
|||
"int b@2 ; b@2 = a@1 ;",
|
||||
parse(clang));
|
||||
}
|
||||
|
||||
void vardecl2() {
|
||||
const char clang[] = "|-VarDecl 0x3873b50 <1.c:1:1, col:9> col:5 used a 'int [10]'\n"
|
||||
"`-FunctionDecl 0x3873c38 <line:3:1, line:6:1> line:3:6 foo 'void ()'\n"
|
||||
" `-CompoundStmt 0x3873dd0 <line:4:1, line:6:1>\n"
|
||||
" `-BinaryOperator 0x3873da8 <line:5:3, col:10> 'int' '='\n"
|
||||
" |-ArraySubscriptExpr 0x3873d60 <col:3, col:6> 'int' lvalue\n"
|
||||
" | |-ImplicitCastExpr 0x3873d48 <col:3> 'int *' <ArrayToPointerDecay>\n"
|
||||
" | | `-DeclRefExpr 0x3873cd8 <col:3> 'int [10]' lvalue Var 0x3873b50 'a' 'int [10]'\n"
|
||||
" | `-IntegerLiteral 0x3873d00 <col:5> 'int' 0\n"
|
||||
" `-IntegerLiteral 0x3873d88 <col:10> 'int' 0\n";
|
||||
|
||||
ASSERT_EQUALS("int[10] a@1 ;\n"
|
||||
"\n"
|
||||
"void foo ( ) {\n"
|
||||
"\n"
|
||||
"a@1 [ 0 ] = 0 ; }",
|
||||
parse(clang));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestClangAstDump)
|
||||
|
|
Loading…
Reference in New Issue