本文整理汇总了C++中AST类的典型用法代码示例。如果您正苦于以下问题:C++ AST类的具体用法?C++ AST怎么用?C++ AST使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AST类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getAllPKBValues
bool QueryEvaluator::evaluatePTClause(TNode * PT_node,
vector<int> row,
vector<vector<int>> * new_rows,
ResultTable * temp_result) {
TNode * stmt_node = PT_node->getChildAtIndex(0);
string stmt_name = stmt_node->getValue();
Symbol stmt_type = SyntaxHelper::getSymbolType(table.getType(stmt_name));
int stmt_index=row[0]; // get stmt_index from row
if (stmt_index==-1) {
// retrieve a list of values of stmt_type from PKB
vector<int> stmt_indexes = getAllPKBValues(stmt_name);
for (size_t i=0; i<stmt_indexes.size(); i++) {
//save back stmt_indexes[i] to row
row[0] = stmt_indexes[i];
//recursive call to update new_rows
vector<vector<int>> rows;
bool isSatisfied = evaluatePTClause(PT_node, row, &rows, temp_result);
if (isSatisfied) {
for (size_t j=0; j<rows.size(); j++) {
new_rows->push_back(rows[j]);
}
}
}
} else {
// from here is hell of logic
// get ASTNode of this Stmt
TNode * root = PKB::getASTRoot();
AST tree; tree.setRoot(root);
TNode * ast_node = tree.findNodeOfStmt(stmt_index);
// handle first argument node
TNode * arg1_node = stmt_node->getChildAtIndex(0);
if (!evaluatePTArgNode(arg1_node, ast_node, ARG1, row, new_rows))
return false;
switch(stmt_type) {
case Assign:
{
TNode * expr_node = stmt_node->getChildAtIndex(1);
if (!evaluateExprNode(expr_node, ast_node)) return false;
return true;
}
case While:
{
break;
}
case If:
{
break;
}
default:
break;
}
}
if (!new_rows->empty()) return true;
return false;
}
示例2: repl
/// Read-Eval-Print-Loop
static void repl(CEnv& cenv, ExecutionEngine* engine)
{
while (1) {
std::cout << "> ";
std::cout.flush();
SExp exp = readExpression(std::cin);
try {
AST* ast = parseExpression(exp);
if (ast->evaluatable()) {
ASTPrototype* proto = new ASTPrototype(false, "", vector<string>());
ASTFunction* func = new ASTFunction(proto, ast);
Function* code = func->Funcgen(cenv);
void* fp = engine->getPointerToFunction(code);
double (*f)() = (double (*)())fp;
std::cout << f() << endl;
} else {
Value* code = ast->Codegen(cenv);
std::cout << "Generated code:" << endl;
code->dump();
}
} catch (SyntaxError e) {
std::cerr << "Syntax error: " << e.what() << endl;
}
}
}
示例3: __etest
int __etest(const char *program)
{
FILE *f = fopen("/tmp/tmp", "w");
if (f == NULL) {
//fprintf(stderr, "open fail %s (%s)\n", strerror(errno), argv[1]);
exit(-1);
}
fwrite(program, 1, strlen(program), f);
fclose(f);
SCParser parser;
AST *ast = parser.parse("/tmp/tmp");
assert(ast);
DBG("%s", ast->toString().c_str());
DBG("\n");
DBG("%s", ast->toSource().c_str());
TypeCheck typeCheck;
ast->accept(&typeCheck);
DBG("%s\n", SymbolTable.toString().c_str());
int err = typeCheck.getLastError();
return err;
}
示例4: main
int main() {
AST *ast = new ASTree();
ast->ShowTree();
//ast.GetCurrentElement()
}
示例5: analyse
void DepGenerator::analyse(const AST& ast) {
const string& modName = ast.getModuleName();
const string& fileName = ast.getFileName();
ModInfo* info = getInfo(modName);
info->addFile(fileName, ast);
}
示例6:
AST*
ASTHelper::retrieveMethodAST( IPosition<SourceToken>& p )
{
AST* ast = this->ast.copySubtree( p );
ast->storeIndent();
return ast;
}
示例7: testFile
void testFile(const char *file)
{
SCParser parser;
AST *ast = parser.parse(file);
if (ast) {
DBG("%s", ast->toString().c_str());
DBG("\n");
DBG("%s", ast->toSource().c_str());
}
}
示例8: main
int main ()
{
AST* id = new ID_NODE("may_var");
AST* val = new VAL_NODE(5.5);
AST* opr = new OPR_NODE('+', id, val);
opr->process();
return 0;
}
示例9: onNode
void MittenSource::onNode(AST &a, ASTBuilder &b, ErrorHandler &e, StructureParser &p)
{
MittenErrorHandler &meh = dynamic_cast<MittenErrorHandler &>(e);
if (a.isBranch() && a.name().compare("line") == 0)
{
cout << "LINE: " << a.display() << "\n";
if (a.size() == 2)
{
if (a[0].isLeaf() && a[0].leaf().value().compare("include") == 0)
{
if (a[1].isBranch())
{
if (a[1].size() == 1)
{
if (a[1][0].size() == 1)
{
if (a[1][0][0].isLeaf())
{
Token inc = a[1][0][0].leaf();
if (inc.tag() == SymbolTag)
cout << "INCLUDE MODULE '" << inc.value() << "'\n";
else if (inc.tag() == StringLiteralTag)
cout << "INCLUDE FILE '" << inc.value() << "'\n";
else
meh.includeRequiresModuleOrFileName(a[0].leaf());
}
else
{
meh.includeRequiresModuleOrFileName(a[0].leaf());
}
}
else
{
meh.includeRequiresOneArgument(a[0].leaf());
}
}
else
{
meh.includeRequiresOneArgument(a[0].leaf());
}
}
else
{
meh.includeRequiresArgumentList(a[0].leaf());
}
}
}
}
}
示例10: Parser
int Calculator::eval(string expr, bool flag) {
Parser* parser = new Parser(new istringstream(expr), flag);
AST* tree = parser->parse();
int result = tree->evaluate();
delete tree;
delete parser;
return result;
}
示例11: testFile
void testFile(const char *file)
{
SCParser parser;
AST *ast = parser.parse(file);
if (ast) {
DBG("%s", ast->toString().c_str());
DBG("\n");
DBG("%s", ast->toSource().c_str());
}
TypeCheck typeCheck;
ast->accept(&typeCheck);
//int err = typeCheck.getLastError();
}
示例12: switch
size_t CFG::_varcnt_(void) {
size_t cnt = 0;
for (ssize_t i = 0; i < this->length(); ++i) {
AST *child = (AST *)this->child(i);
switch(child->type()) {
case AST_ASSIGN:
if (0 != child->length() && 0 == child->child(0)->length()) {
cnt ++;
}
break;
case AST_FUNC:
if (0 != child->length() && 0 != child->child(0)->length()) {
cnt += child->child(0)->child(0)->length();
}
break;
default:
_D(LOG_DEBUG, "Need NOT count on %s", child->data().c_str());
break;
}
}
cnt += (NULL == this->nextCFG(true) ? 0 : this->nextCFG(true)->_varcnt_());
cnt += (NULL == this->nextCFG(false) ? 0 : this->nextCFG(false)->_varcnt_());
return cnt;
}
示例13: scopeOfNode
void scopeOfNode( AST* ast, QStringList& scope )
{
if( !ast )
return;
if( ast->parent() )
scopeOfNode( ast->parent(), scope );
QString s;
switch( ast->nodeType() )
{
case NodeType_ClassSpecifier:
if( ((ClassSpecifierAST*)ast)->name() ){
s = ((ClassSpecifierAST*)ast)->name()->text();
s = s.isEmpty() ? QString::fromLatin1("<unnamed>") : s;
scope.push_back( s );
}
break;
case NodeType_Namespace:
{
AST* namespaceName = ((NamespaceAST*)ast)->namespaceName();
s = namespaceName ? namespaceName->text() : QString::fromLatin1("<unnamed>");
scope.push_back( s );
}
break;
case NodeType_FunctionDefinition:
{
FunctionDefinitionAST* funDef = static_cast<FunctionDefinitionAST*>( ast );
DeclaratorAST* d = funDef->initDeclarator()->declarator();
// hotfix for bug #68726
if ( !d->declaratorId() )
break;
QList<ClassOrNamespaceNameAST*> l = d->declaratorId()->classOrNamespaceNameList();
for( int i = 0; i < l.size(); ++i ) {
AST* name = l.at(i)->name();
scope.push_back( name->text() );
}
}
break;
default:
break;
}
}
示例14: main
int main()
{
Parser parser;
parser.parse();
AST ast = parser.ast();
if (ast.printErrors(std::cerr))
return -1;
int code = SymbolResolver::resolve(ast, std::cerr);
if (code)
return code;
PrintVisitor::print(std::cerr, ast);
PrintCode::print(std::cout, ast, true);
}
示例15: SourceMgr
C2Sema::C2Sema(SourceManager& sm_, DiagnosticsEngine& Diags_, AST& ast_, clang::Preprocessor& PP_)
: SourceMgr(sm_)
, Diags(Diags_)
, typeContext(ast_.getTypeContext())
, ast(ast_)
, PP(PP_)
{}