Esempio n. 1
0
	//打印表达式列表
	int TSyntaxTreeAnalyse::PrintExpr(const char  * sPrefix ,ST_EXPR * pstExpr,int offset,int iLogType)
	{
//#if 0
		if (NULL == pstExpr)
		{
			return 0;
		}
		OutPutInfo(iLogType,"%s[%s]op=[%s],addr[%p],calcflag=[%s],sTorken=[%s],valueaddr[%p],exprlValue[%lld],exprsValue[%s],valueSize[%d],exprailas[%s],pColumn[%p]",
			GetOffSet(offset),sPrefix,TokenName[pstExpr->iOpcode],pstExpr,
			DescribeExprCalcFlag(pstExpr).c_str(),
			ReplaceNull(pstExpr->sTorken),
			pstExpr->pExprValue,
			pstExpr->pExprValue->lValue,
			ReplaceNull(pstExpr->pExprValue->sValue),
			pstExpr->pExprValue->iSize,
			ReplaceNull(pstExpr->pExprValue->sAlias),
			pstExpr->pExprValue->pColumn);	

		PrintExpr("left",pstExpr->pLeft,offset+1, iLogType);
		PrintExpr("right",pstExpr->pRight,offset+1, iLogType);
		if (NULL != pstExpr->pFunc)
		{
			PrintExprList(pstExpr->pFunc->pFuncArgs,offset+1, iLogType);
		}
//#endif
		return 0;
	}
Esempio n. 2
0
	//打印整个语法树
	int TSyntaxTreeAnalyse::Print(TMdbSqlParser * pSqlParser,int iLogType)
	{
//#if 0
		ST_SQL_STRUCT & stSqlStruct = pSqlParser->m_stSqlStruct;
		OutPutInfo(iLogType,"#################SqlStruct start################");
		OutPutInfo(iLogType,"==========================================");
		OutPutInfo(iLogType,"Insert(%d),delete(%d),update(%d),select(%d)",TK_INSERT,TK_DELETE,TK_UPDATE,TK_SELECT);
		OutPutInfo(iLogType,"[type = %d],[tablename = %s][alias = %s][pMdbTable = %p][pShmDSN= %p][pScanAllIndex= %p][vIndexUsed=%d]",
			stSqlStruct.iSqlType,
			ReplaceNull(stSqlStruct.sTableName),
			ReplaceNull(stSqlStruct.sAlias),
			stSqlStruct.pMdbTable,stSqlStruct.pShmDSN,
			stSqlStruct.pScanAllIndex,
			stSqlStruct.vIndexUsed.size());
		OutPutInfo(iLogType,"===========[index used]==================");
		PrintIndex(stSqlStruct.vIndexUsed,0,iLogType);
		OutPutInfo(iLogType,"===========[column list]==================");
		PrintExprList(stSqlStruct.pColList,0,iLogType);
		OutPutInfo(iLogType,"===========[where]========================");
		PrintExpr("root",stSqlStruct.pWhere,0,iLogType);
		OutPutInfo(iLogType,"===========[group by]========================");
		PrintExprList(stSqlStruct.pGroupby,0,iLogType);
		OutPutInfo(iLogType,"===========[having]========================");
		PrintExpr("root",stSqlStruct.pHaving,0,iLogType);
		OutPutInfo(iLogType,"===========[optimised where]==================");
		PrintWhereClause(iLogType,stSqlStruct.tWhereOrClause);
		OutPutInfo(iLogType,"===========[orderby]======================");
		PrintExprList(stSqlStruct.pOrderby,0,iLogType);
		OutPutInfo(iLogType,"===========[limit]========================");
		PrintExpr("root",stSqlStruct.pstLimit,0,iLogType);
		OutPutInfo(iLogType,"===========[offset]=======================");
		PrintExpr("root",stSqlStruct.pstOffset,0,iLogType);
		OutPutInfo(iLogType,"===========[idlist]=======================");
		PrintIdList(stSqlStruct.pstIdList,0,iLogType);
		OutPutInfo(iLogType,"==========================================");
		PrintValues(pSqlParser,iLogType);
		OutPutInfo(iLogType,"#################SqlStruct end#################");

    	_ST_DDL_SQL_STRUCT * pstDDLSqlStruct = pSqlParser->m_pDDLSqlStruct;
		OutPutInfo(iLogType,"###############DDLSqlStruct start##############");
    	if(pstDDLSqlStruct)
    	{
        	OutPutInfo(iLogType,"[sqltype = [%d][%d]][IfNE = %d]",pstDDLSqlStruct->iSqlType[0],pstDDLSqlStruct->iSqlType[1]
        															,pstDDLSqlStruct->bIfNE);
        	PrintTable(pstDDLSqlStruct->pTable,iLogType);
    	}
		OutPutInfo(iLogType,"###############DDLSqlStruct end################");
//#endif
		return 0;
	}
Esempio n. 3
0
void GenTestCase(int no)
{
  Node *n1, *n2;
  unsigned v0;
  printf("void test%d(void)\n{\n", no);
  printf("  printf(\"-- Test %d (seed: %u) --\\n\");\n", no, mySeed);
  printf("  {\n");
  printf("    int failed = 0;\n");
  ReInit();
  n1 = GenCommaExpr();
  PrintDecls(n1);
  printf("    unsigned v0 = (");
  PrintExpr(n1);
  printf(");\n");
  n2 = DupExpr(n1);
  v0 = Eval(n2);
  CheckVars(n2);
  printf("    if (v0 != %uu) ", v0);
  printf("{ failed = 1; printf(\"v0 != %uu\\n\"); }\n", v0);
  printf("    if (failed)\n      printf(\"Test %d failed\\n\");\n", no);
  printf("    errors += failed;\n");
  printf("  }\n");
  printf("  printf(\"\\n\");\n");
  printf("}\n\n");
  DelNode(n1);
  DelNode(n2);
}
Esempio n. 4
0
void ExprIOreport( EXPR *expr )
    {
    EXPR *text ;

    text = PrintExpr( expr, 1 ) ;
    IOreport( "%s", StringValue( dynamic_cast<STRING*>( text ) ) ) ;
    delete text ;
    }
Esempio n. 5
0
void ExprIOerror( EXPR *expr )
    {
    EXPR *text ;

    text = PrintExpr( expr, 1 ) ;
    fprintf( stderr, "%s", StringValue( dynamic_cast<STRING*>( text ) ) ) ;
    delete text ;
    }
Esempio n. 6
0
static void
outputGasDirective(FILE *f, const char *prefix, AST *expr)
{
    fprintf(f, "\t\t%s\t", prefix);
    if (expr)
        PrintExpr(f, expr);
    else
        fprintf(f, "0");
}
Esempio n. 7
0
/*
 * print constant declarations
 */
static void
PrintConstant(FILE *f, AST *ast)
{
    if (IsFloatConst(ast)) {
        PrintFloat(f, EvalConstExpr(ast));
        return;
    }
    PrintExpr(f, ast);
}
Esempio n. 8
0
EXPR* Print( const EXPR* expr, int indent )
    {
    EXPR *result ;

    result = Indent( indent ) ;
    result->Append( PrintExpr( expr, 0 ) ) ;
    result->Append( "\n" ) ;
    return result ;
    }
Esempio n. 9
0
void PrintExpr(Node* n)
{
  switch (n->type)
  {
  case 'L':
    printf("v%d", n->varNum);
    break;
  case '?':
    PrintExpr(n->child[2]);
    printf(" ? ");
    PrintExpr(n->child[0]);
    printf(" : ");
    PrintExpr(n->child[1]);
    break;
  default:
    PrintExpr(n->child[0]);
    printf(" %c ", n->type);
    PrintExpr(n->child[1]);
    break;
  }
}
Esempio n. 10
0
	//打印where 段
	int TSyntaxTreeAnalyse::PrintWhereClause(int iLogType,ST_WHERE_OR_CLAUSE & stWhereOrClause)
	{
		int iRet = 0;
		size_t i = 0;
		for(i = 0;i < stWhereOrClause.m_vAndClause.size();++i)
		{
			OutPutInfo(iLogType,"++++++Or Clause[%u]+++++++",i);
			size_t j = 0;
			for(j = 0; j < stWhereOrClause.m_vAndClause[i].m_vExpr.size();++j)
			{
				PrintExpr("And Clause",stWhereOrClause.m_vAndClause[i].m_vExpr[j],1,iLogType);
			}
		}
		return iRet;
	}
Esempio n. 11
0
EXPR* ARRAY::Text( bool protect ) const
    {
    EXPR* result = String( "" ) ;
    if( protect )
	result->Append( "[" ) ;
    for( unsigned i = 0 ; i < used ; i++ )
	{
	result->Append( PrintExpr( list[i], 0 ) ) ;
	if( i < used - 1 )
	    result->Append( ", " ) ;
	}
    if( protect )
	result->Append( "]" ) ;
    return result ;
    }
Esempio n. 12
0
	//打印表达式列表
	int TSyntaxTreeAnalyse::PrintExprList(ST_EXPR_LIST * pstExprList,int offset,int iLogType)
	{
//#if 0
		if (NULL != pstExprList)
		{	
			OutPutInfo(iLogType,"%s======List start=====",GetOffSet(offset));
			int i = 0;
			for (i = 0;i<pstExprList->iItemNum;i++)
			{
				OutPutInfo(iLogType,"%sitem[%d]",GetOffSet(offset),i);
				ST_EXPR_ITEM & Item = pstExprList->pExprItems[i];
				OutPutInfo(iLogType,"%sname=[%-10s],span=[%s]",GetOffSet(offset),ReplaceNull(Item.sName),ReplaceNull(Item.sSpan));
				PrintExpr("root",Item.pExpr,offset,iLogType);
			}
			OutPutInfo(iLogType,"%s======List end======",GetOffSet(offset));
		}
//#endif
		return 0;
	}
Esempio n. 13
0
	//打印索引信息
	int TSyntaxTreeAnalyse::PrintIndex(std::vector< _ST_INDEX_VALUE> & vIndexValue,int offset,int iLogType)
	{
//#if 0
		std::vector< _ST_INDEX_VALUE>::iterator itor = vIndexValue.begin();
		for(;itor != vIndexValue.end();++itor)
		{
			OutPutInfo(iLogType,"%s index[%s]",GetOffSet(offset),itor->pstTableIndex->pIndexInfo->sName);
			int i = 0;
			for(i = 0; i < MAX_INDEX_COLUMN_COUNTS;++i)
			{
				if(itor->pExprArr[i] != NULL)
				{
					PrintExpr("Expr:",itor->pExprArr[i],offset +1 ,iLogType);
				}
			}
		}
//#endif
		return 0;
	}
Esempio n. 14
0
static void
outputGasDataList(FILE *f, const char *prefix, AST *ast)
{
    int reps;
    AST *sub;
    char *comma = "";
    AST *origval = NULL;

    fprintf(f, "\t\t%s\t", prefix);
    while (ast) {
        sub = ast->left;
        if (sub->kind == AST_ARRAYDECL) {
            origval = ast->left->left;
            reps = EvalPasmExpr(ast->left->right);
        } else if (sub->kind == AST_STRING) {
            const char *ptr = sub->d.string;
            unsigned val;
            while (*ptr) {
                val = (*ptr++) & 0xff;
                if (val >= ' ' && val < 0x7f) {
                    fprintf(f, "%s'%c'", comma, val);
                } else {
                    fprintf(f, "%s%d", comma, val);
                }
                comma = ", ";
            }
            reps = 0;
        } else {
            origval = ast->left;
            reps = 1;
        }
        while (reps > 0) {
            fprintf(f, "%s", comma);
            PrintExpr(f, origval);
            comma = ", ";
            --reps;
        }
        ast = ast->right;
    }
}
Esempio n. 15
0
Expr* EvalLet(Env* env, Expr* expr, Expr* cont){
  Expr* bindings = expr->next;
  Expr* bind;
  Env* new_env = malloc(sizeof(Env));
  init_env(new_env, env);

  PrintExpr(bindings);
  while(bindings != NULL){
      printf("type is %d\n", bindings->type);
    if(bindings->type == Pair_Exp){

      bind = bindings->u.list->u.list;
      char *symbol = get_symbol_element(bind);
      printf("symbolis %s", symbol);
      printf("type is %d\n", bind->next->type);
      Expr* val_expr = Eval(env,dup( bind->next), cont);
       PrintExpr(val_expr);
       
       puts("Bindings");
       PrintExpr(bindings);
       record_expr(new_env, symbol, val_expr);
       puts("Bindings 2");
       PrintExpr(bindings);
    }
    //    puts("aaa");
    //    printf("bindings->next is %d\n", bindings->next == NULL);
    //    printf("next bind expr's type is %d\n", bindings->type);
    puts("DEBUG");
    PrintExpr(bindings);
   bindings = GetSecond(bindings); 
   PrintExpr(bind->next->next);

  }
  puts("out let");
  return Eval(new_env, expr->next->next, cont);
}
Esempio n. 16
0
void print_test( int x, int y )
{
	printf( "printf:\n\tx + y = [%d]\n", x + y );
	PrintExpr( x + y );
}
Esempio n. 17
0
EXPR* OPER::Text( bool protect ) const
    {
    int i ;
    EXPR* result ;

    for( i = 0 ; OperTab[i].op ; i++ )
	{
	if( OperTab[i].op == oper )
	    break ;
	}
    if( OperTab[i].op == OPER_ERROR )
	{
	IOerror( IO_WARN, "PrintExpr",
	    "unknown OPERATOR type 0x%02x", oper ) ;
	return String( "<unknown operator>" ) ;
	}
    if( OperTab[i].style == SF )
	{
	result = String( OperTab[i].name ) ;
	result->Append( "(" ) ;
	if( Eleft )
	    {
	    result->Append(" " ) ;
	    result->Append( PrintExpr( Eleft, 1 ) ) ;
	    }
	if( Eright )
	    {
	    result->Append( ", " ) ;
	    result->Append( PrintExpr( Eright, 1 ) ) ;
	    }
	result->Append( " )" ) ;
	return result ;
	}
    if( OperTab[i].style == SU )
	{
	result = String( "" ) ;
	if( !protect )
	    result->Append( "( " ) ;
	result->Append( OperTab[i].name ) ;
	result->Append( PrintExpr( Eleft, 0 ) ) ;
	if( !protect )
	    result->Append( " )" ) ;
	return result ;
	}
    if( OperTab[i].style == SB )
	{
	result = String( "" ) ;
	if( !protect )
	    result->Append( "( " ) ;
	result->Append( PrintExpr( Eleft, 0 ) ) ;
	result->Append( " " ) ;
	result->Append( OperTab[i].name ) ;
	result->Append( " " ) ;
	result->Append( PrintExpr( Eright, 0 ) ) ;
	if( !protect )
	    result->Append( " )" ) ;
	return result ;
	}
    if( OperTab[i].style == SE )		/* unprotected op */
	{
	result = PrintExpr( Eleft, 0 ) ;
	result->Append( " " ) ;
	result->Append( OperTab[i].name ) ;
	result->Append( " " ) ;
	result->Append( PrintExpr( Eright, 0 ) ) ;
	return result ;
	}
    if( OperTab[i].style == SD )		/* units */
	{
	result = PrintExpr( Eleft, 0 ) ;
	result->Append( " «" ) ;
	result->Append( PrintExpr( Eright, 1 ) ) ;
	result->Append( "»" ) ;
	return result ;
	}
    if( OperTab[i].style == SS )		/* unit set */
	{
	result = PrintExpr( Eleft, 0 ) ;
	result->Append( " = «" ) ;
	result->Append( PrintExpr( Eright, 1 ) ) ;
	result->Append( "»" ) ;
	return result ;
	}
    if( OperTab[i].style == SA )		/* array set */
	{
	result = PrintExpr( Eleft, 0 ) ;
	result->Append( "[" ) ;
	result->Append( PrintExpr( Eright, 1 ) ) ;
	result->Append( "]" ) ;
	return result ;
	}

    IOerror( IO_WARN, "PrintExpr", "unknown OPERATOR style" ) ;
    return String( "$error" ) ;
    }
Esempio n. 18
0
static void
outputGasInstruction(FILE *f, AST *ast)
{
    Instruction *instr;
    AST *operand[MAX_OPERANDS];
    AST *sub;
    int immflag = 0;
    int effects = 0;
    int i;
    int numoperands = 0;
    const char *opcode;

    instr = (Instruction *)ast->d.ptr;
    fprintf(f, "\t");
    /* print modifiers */
    sub = ast->right;
    while (sub != NULL) {
        if (sub->kind == AST_INSTRMODIFIER) {
            InstrModifier *mod = sub->d.ptr;
            if (!strncmp(mod->name, "if_", 3)) {
                fprintf(f, "%s ", mod->name);
            } else if (!strcmp(mod->name, "wz")) {
                effects |= GAS_WZ;
            } else if (!strcmp(mod->name, "wc")) {
                effects |= GAS_WC;
            } else if (!strcmp(mod->name, "wr")) {
                effects |= GAS_WR;
            } else if (!strcmp(mod->name, "nr")) {
                effects |= GAS_NR;
            } else if (!strcmp(mod->name, "#")) {
                immflag = 1;
            } else {
                ERROR(sub, "unknown modifier %s", mod->name);
            }
        } else if (sub->kind == AST_EXPRLIST) {
            if (numoperands >= MAX_OPERANDS) {
                ERROR(ast, "Too many operands to instruction");
                return;
            }
            operand[numoperands++] = sub->left;
        } else {
            ERROR(ast, "Internal error parsing instruction");
        }
        sub = sub->right;
    }

    /* print instruction opcode */
    opcode = instr->name;
    fprintf(f, "\t%s", opcode);
    /* now print the operands */
    for (i = 0; i < numoperands; i++) {
        if (i == 0)
            fprintf(f, "\t");
        else
            fprintf(f, ", ");
        if (immflag) {
            switch (instr->ops) {
            case CALL_OPERAND:
            case SRC_OPERAND_ONLY:
                if (i == 0) {
                    fprintf(f, "#");
                    immflag = 0;
                }
                break;
            default:
                if (i == 1) {
                    fprintf(f, "#");
                    immflag = 0;
                    if (instr->ops == TWO_OPERANDS)
                    {
                        current->fixImmediate = 1;
                    }
                }
                break;
            }
        }
        PrintExpr(f, operand[i]);
        current->fixImmediate = 0;
    }
    if (effects) {
        const char *comma = "";
        const char *effnames[] = { "wz", "wc", "nr", "wr" };
        fprintf(f, "\t");
        for (i = 0; i < 4; i++) {
            if (effects & (1<<i)) {
                fprintf(f, "%s%s", comma, effnames[i]);
                comma = ", ";
            }
        }
    }
}
Esempio n. 19
0
/*
* Routine: PrintExpr(expr_t *)
* Purpose: print out an expression to allow templates to be reconstructed
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
void 
PrintExpr(expr_t *pExpr)
{
	int i,
		bUseComma = 0;
	expr_t *pArg;
   char szFormat[20];

	/* handle the constants */
	if (pExpr->nFlags & EXPR_FL_CONST)
	{
		switch(i = pExpr->nFlags & (EXPR_TYPE_MASK ^ EXPR_FL_KEYWORD))
		{
		case EXPR_FL_INT:
			if (pExpr->nFlags & EXPR_FL_KEYWORD)
				printf("%s", KeywordText((int)pExpr->Value.nValue));
			else
				printf(HUGE_FORMAT, pExpr->Value.nValue);
			break;
		case EXPR_FL_CHAR:
			printf("\"%s\"", GetBuffer(pExpr->Value.pBuf));
			break;
		default:
			fprintf(stderr, "INTERNAL ERROR: unknown constant type %d\n", i);
			exit(1);
		}
		return;
	}
	
	/* handle the parameterized expressions */
	switch(pExpr->nFlags & EXPR_FUNC_MASK)
	{
	case EXPR_FL_FUNC:
		if (pExpr->nFlags & EXPR_FL_FUNC)
		{
			printf("%s(", KeywordText((int)pExpr->Value.nValue));
			for (pArg = (expr_t *)getHead(pExpr->ArgList); pArg; pArg = (expr_t *)getNext(pExpr->ArgList))
			{
				if (bUseComma)
					printf(",\n\t");
				PrintExpr(pArg);
				bUseComma = 1;
			}
			printf(")");
		}
		break;
	case EXPR_FL_REPL:
		sprintf(szFormat, "{\"%%s\", %s}", HUGE_FORMAT);
		printf(szFormat, GetBuffer(pExpr->Value.pBuf), pExpr->Value.nValue);
		break;
	case EXPR_FL_SUBST:
		printf("[%s]", GetBuffer(pExpr->Value.pBuf));
		break;
	default:
		fprintf(stderr, "INTERNAL ERROR: unknown expression type %x\n", pExpr->nFlags);
		exit(1);
	}
	
	return;
	
}