当前位置: 首页>>代码示例>>C++>>正文


C++ AST类代码示例

本文整理汇总了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;
}
开发者ID:SeanNguyen,项目名称:cs3202-team-4-repo,代码行数:60,代码来源:QueryEvaluator.cpp

示例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;
		}
	}
}
开发者ID:Dieken,项目名称:jff,代码行数:27,代码来源:toy-llvm-lisp.cpp

示例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;
}
开发者ID:ktok07b6,项目名称:scc,代码行数:27,代码来源:typecheck_main.cpp

示例4: main

int main() {

	

	AST *ast = new ASTree();
	ast->ShowTree();

	//ast.GetCurrentElement()
}
开发者ID:lovingmage,项目名称:SPA-Platform,代码行数:9,代码来源:ASTree.cpp

示例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);
}
开发者ID:hbarve1,项目名称:c2compiler,代码行数:7,代码来源:DepGenerator.cpp

示例6:

AST*
ASTHelper::retrieveMethodAST( IPosition<SourceToken>& p )
{
	AST* ast = this->ast.copySubtree( p );

	ast->storeIndent();
	
	return ast;
}
开发者ID:danielbradley,项目名称:Astral,代码行数:9,代码来源:ASTHelper.cpp

示例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());
	}
}
开发者ID:ktok07b6,项目名称:scc,代码行数:10,代码来源:scparser_test.cpp

示例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;



}
开发者ID:gtatyous93,项目名称:my-first-compiler,代码行数:12,代码来源:main.cpp

示例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());
					}
				}
			}
		}
	}
开发者ID:oliverkatz,项目名称:mitten,代码行数:51,代码来源:MittenSource.cpp

示例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;
}
开发者ID:maestro252,项目名称:Semilleros,代码行数:14,代码来源:calculator.C

示例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();
}
开发者ID:ktok07b6,项目名称:scc,代码行数:14,代码来源:typecheck_main.cpp

示例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;
}
开发者ID:cmj0121,项目名称:Zerg,代码行数:28,代码来源:cfg.cpp

示例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;
    }
}
开发者ID:Elv13,项目名称:Umbrello-ng,代码行数:48,代码来源:ast_utils.cpp

示例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);
}
开发者ID:gendx,项目名称:compiler,代码行数:16,代码来源:main.cpp

示例15: SourceMgr

C2Sema::C2Sema(SourceManager& sm_, DiagnosticsEngine& Diags_, AST& ast_, clang::Preprocessor& PP_)
    : SourceMgr(sm_)
    , Diags(Diags_)
    , typeContext(ast_.getTypeContext())
    , ast(ast_)
    , PP(PP_)
{}
开发者ID:unixaaa,项目名称:c2compiler,代码行数:7,代码来源:C2Sema.cpp


注:本文中的AST类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。