示例#1
0
文件: analyze.c 项目: JaneJung/cminus
/* Procedure traverse is a generic recursive 
 * syntax tree traversal routine:
 * it applies preProc in preorder and postProc 
 * in postorder to tree pointed to by t
 */
static void traverse( TreeNode * t,
		      void (* preProc) (TreeNode *),
		      void (* postProc) (TreeNode *) )
{
  if (t != NULL)
    { 
      if (t->scope > depth) depth = t->scope;
      if (t->nodekind == StmtK) {
	if (t->kind.stmt == IfK || t->kind.stmt == WhileK || t->kind.stmt == CompoundK)
	  location = 0;
      }
      preProc(t);
      { int i;
	for (i=0; i < MAXCHILDREN; i++) {
	  if (t->child[i] == NULL) continue;
	  if ( t->nodekind == StmtK && t->kind.stmt == CompoundK) {
	    t->child[i]->scope = t->scope + 1;
	  } 
	  else if(t->nodekind == DeclK && t->kind.decl == funK){
	    t->child[1]->scope = t->scope+1;
	    return_type = t->child[0]->type;
	  }
	  else {
	    t->child[i]->scope = t->scope;
	  }
	  traverse(t->child[i],preProc,postProc);
	}
      }
      deleteProc(t);
      postProc(t);
      if (t->sibling != NULL) t->sibling->scope = t->scope;
      traverse(t->sibling, preProc, postProc);
    }
}
示例#2
0
文件: analyze.c 项目: canslab/cminus
/* Procedure traverse is a generic recursive 
 * syntax tree traversal routine:
 * it applies preProc in preorder and postProc 
 * in postorder to tree pointed to by t
 */
static void traverse(TreeNode * t, void (*preProc)(TreeNode *), void (*postProc)(TreeNode *))
{
	if (t != NULL)
	{
		int locationBackup = gLocation;

		preProc(t);
		// gScope = 1, gLocation = 1
		{
			int i;
			// backup the scope before getting new scope
			char *scopeBackUp = gScope;

			// get new scope and save it to gScope
			gScope = getNewScope(t);

			for (i = 0; i < MAXCHILDREN; i++)
				traverse(t->child[i], preProc, postProc);

			free(gScope);
			gLocation = locationBackup;
			gScope = scopeBackUp;

		}

		postProc(t);
		traverse(t->sibling, preProc, postProc);
	}
}
/* Procedure traverse is a generic recursive 
 * syntax tree traversal routine:
 * it applies preProc in preorder and postProc 
 * in postorder to tree pointed to by t
 */
static void traverse( TreeNode * t, void (* preProc) (TreeNode *), void (* postProc) (TreeNode *) )
{ 
	if (t != NULL)
	{ 
		preProc(t);
		{ 
			int i;
			for (i=0; i < MAXCHILDREN; i++)
			{
				traverse(t->child[i],preProc,postProc);
			}
		}
		if(t->nodekind==StmtK&&t->kind.stmt==RoutineK)
		{
			/* if leaving a function declaration */
			if(funcPathI!=0)
			{
				/* if not leaving the main function,
                    then set current symbol table to the upper one */
				a_curFuncNum=funcPath[--funcPathI]; 
				st_setCurFuncNum(a_curFuncNum);
			}
		}
		
		postProc(t);
		traverse(t->sibling,preProc,postProc);
	}
}
示例#4
0
文件: analyze.c 项目: isairz/cminus
/* Procedure traverse is a generic recursive
 * syntax tree traversal routine:
 * it applies preProc in preorder and postProc
 * in postorder to tree pointed to by t
 */
static void traverse( TreeNode * t,
                      void (* preProc) (TreeNode *),
                      void (* postProc) (TreeNode *) )
{   if (t != NULL)
    {   preProc(t);
        {   int i;
            for (i=0; i < MAXCHILDREN; i++)
                traverse(t->child[i],preProc,postProc);
        }
        postProc(t);
        traverse(t->sibling,preProc,postProc);
    }
}
示例#5
0
/* Procedure traverse is a generic recursive
 * syntax tree traversal routine:
 * it applies prePro in preorder and postProc
 * in postorder to tree pointed to by t
 */
void
Analyze::traverse( TreeNode *t,
              void (* preProc)( TreeNode * ),
              void (* postProc)( TreeNode * ) )
{
    if ( t != NULL )
    {
        preProc( t );
        for ( int i = 0; i < MAXCHILDREN; i++ )
        {
            traverse( t->m_child[i], preProc, postProc );
        }
        postProc( t );
        traverse( t->m_sibling, preProc, postProc );
    }
}
static void traverse( TreeNode * t,
               void (* preProc) (TreeNode *),
               void (* postProc) (TreeNode *) )
{ if (t != NULL)
  { preProc(t);
    { int i;
      for (i=0; i < MAXCHILDREN; i++){
        traverse(t->child[i],preProc,postProc);
        if(t->nodekind==StmtK && t->kind.stmt==Compound && i==0)//local_declarations
          IdK_exception=0;
      }
    }
    postProc(t);
    traverse(t->sibling,preProc,postProc);
  }
}
示例#7
0
文件: tbl.c 项目: dbunker/SABR
void execute(treeNode *root){

	tempClausesFileGlobal = NULL;
	rootData *rdata = root->data;
	compilerDebug(rdata);
	postProc(rdata);
	
	linkedList fullTransNodes = expandTrans(rdata);
	indexList *varList = createVarList(rdata,fullTransNodes);
	
	linkedList clauseList = createLinked(Malloc,Free);
	clauseListGlobal = clauseList;
	
	// don't need to create clauses if only getting final result
	if(flagGlobal != FLAG_RESULT){
		processAllClauses(rdata,varList,clauseList,fullTransNodes);
	}
	
	if(flagGlobal == FLAG_DEBUG){
		printDebugClausesVars(DEBUG_CLAUSE_FILE,varList,clauseList);
	}
	
	if(flagGlobal == FLAG_CNF || flagGlobal == FLAG_DEBUG || flagGlobal == FLAG_RUN){
		printClauses(CNF_FILE,varList,clauseList);
	}
	
	if(flagGlobal == FLAG_RUN){
		runCnfSolver();
	}	

	if(flagGlobal == FLAG_RESULT || flagGlobal == FLAG_RUN){
		createSatOut(OUT_VARS_FILE,RESULT_FILE,rdata,varList,fullTransNodes);
	}
	
	if(flagGlobal != FLAG_RESULT){
		deleteFile(TEMP_CLAUSE_FILE);
	}
	
	Free(sabrDirGlobal);
	freeArch(root);
	
	destroyLinked(fullTransNodes,singleFree);
	destroyLinked(clauseList,singleFree);
	destroyVarIndex(varList);
}
示例#8
0
文件: QA.cpp 项目: bird-house/QA-DKRZ
int
QA::finally_data(int xCode)
{
  // post processing, but not for conditions which indicate
  // incomplete checking.
  if( getExitState() < 3 )
  {  // 3 or 4 interrupted any checking
    if( enablePostProc )
    {
      if( postProc() )
      {
        if( getExitState() == 63 )
            setExitState(1);  // this is considered a change

        notes->setCheckStatus(n_data, n_fail);
      }
    }
  }

  // read history from the qa-file.nc and append new entries
  appendToHistory();

  if( isCheckData )
  {
    // check for flags concerning the total data set,
    // but exclude the case of no record
    if( pIn->currRec > 0 )
      for( size_t j=0 ; j < qaExp.varMeDa.size() ; ++j )
        qaExp.varMeDa[j].qaData.checkFinally(qaExp.varMeDa[j].var);

    for( size_t j=0 ; j < qaExp.varMeDa.size() ; ++j )
    {
       // write qa-results attributes about statistics
       qaExp.varMeDa[j].qaData.setStatisticsAttribute(nc);

       // plausibility range checks about units
       qaExp.varMeDa[j].verifyPercent();
    }
  }

  return getExitState() ;
}