📄 cp_process.c
字号:
/*Copyright (c) 2000, 2001, Red Hat, Inc.This file is part of Source-Navigator.Source-Navigator is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public License as publishedby the Free Software Foundation; either version 2, or (at your option)any later version.Source-Navigator is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith Source-Navigator; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA.*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <tcl.h>#include "crossrefP.h"#include "operator.h"#include "longstr.h"#include "srchtbl.h"/* Valid debugging macros for this file: #define PRINT #define PRINT_EXPR #define PRINT_OPERATOR*/#define null_safe(x) ((x)==0?(""):(x))#define ProcTypeAssign( Proc, Proc2 ) Proc.Type = Proc2.Type, Proc2.Type = 0#define ProcNameAssign( Proc, Proc2 ) Proc.name = Proc2.name, Proc2.name = 0; \ Proc.lineno_beg = Proc2.lineno_beg; \ Proc.charno_beg = Proc2.charno_beg; \ Proc.lineno_end = Proc2.lineno_end; \ Proc.charno_end = Proc2.charno_end#define ProcScopAssign( Proc, Proc2 ) Proc.scope = Proc2.scope, Proc2.scope = 0typedef struct sProc Proc_t;struct sProc{ Type_t Type; char *name; char *scope;#ifdef PRINT_EXPR char ac[10000];#endif int lineno_beg; int charno_beg; int lineno_end; int charno_end;};static Proc_t f_expr( Expr_t Expr, int access, char *scope, int call, int pass );/* static Proc_t f_exprlist( List_t ListExpr, int access, char *scope, char *arglist, int pass ); 15.01.98 rigo */static Proc_t f_exprlist( List_t ListExpr, int access, char *scope, LongString *parglist, int pass ); /* 15.01.98 rigo */static Type_t get_variable_type( char *scope_global, char *scope, char *name, int lineno_beg, int charno_beg, int lineno_end, int charno_end, char *sope_ret, char *type_ret, char *define_ret, int *paf_type_ret, int *paf_scope_ret );static Type_t get_function_type( char *scope_global, char *scope, char *name, char *arglist, int lineno_beg, int charno_beg, int lineno_end, int charno_end, char *sope_ret, char *type_ret, char *define_ret, int *paf_type_ret, int *paf_scope_ret );static void ProcDestroy( int i, Proc_t Proc );static char *strdup_m( char *pc );static char *f_TypeToScope( Type_t Type );static char *get_scope( char *name );static char *get_name( char *name );static int my_Get_symbol( char *scope_global, char *scope, char *name, char *arg_list, char *scope_ret, char *type_ret, char *define_ret, int exact );static char *paf_type_to_string( int paf_type );static Type_t f_OperatorCall2( char *pcOperator, Type_t Type1, Type_t Type2, int access, int lineno );static int tab;extern void f_ExprProcess( Expr_t Expr ){ Proc_t Proc;/* char ac[1000]; */ Proc = f_expr( Expr, READ, 0, 0, 0 );#ifdef PRINT_EXPR printf( "expression: %s\n", Proc.ac );#endif/* f_TypeToString( Proc.Type, ac, 1 ); *//* printf( "type: %s\n", ac ); */ ProcDestroy( 99, Proc );}static Proc_t f_expr( Expr_t Expr, int access, char *scope, int call, int pass ){ char *pcOperator;/* char arglist[10000]; 15.01.98 rigo */ LongString arglist; /* 15.01.98 rigo */ Proc_t Proc; Proc_t Proc1; Proc_t Proc2; Proc_t Proc3; tab++; Proc.Type = 0; Proc.name = 0; Proc.scope = 0; Proc1.Type = 0; Proc1.name = 0; Proc1.scope = 0; Proc2.Type = 0; Proc2.name = 0; Proc2.scope = 0; Proc3.Type = 0; Proc3.name = 0; Proc3.scope = 0;#if 0 /* 15.01.98 rigo : ez mar nem kell */#define MAX_EXPR_DEPTH 150 /* Zsolt Koppany, 30-dec-97 */ if (tab >= MAX_EXPR_DEPTH) { static int printed = FALSE; tab--; if (!printed) { printed = TRUE; fprintf(stderr,"To deep (> %d) expressions!\n",MAX_EXPR_DEPTH); } return Proc; }#endif if( Expr == 0 ) { f_InternalError( 52 ); return Proc; }#ifdef PRINT_OPERATOR printf( "%*.*soperator: %d\n", tab*4, tab*4, "", Expr->_operator );#endif switch( Expr->_operator ) { case OPERATOR_KOMMA : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( ",", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc2 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s, %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 1, Proc1 ); ProcDestroy( 2, Proc2 ); break; case OPERATOR_ASSIGN : pcOperator = "=" ; goto label1; case OPERATOR_MULTassign : pcOperator = "*=" ; goto label1; case OPERATOR_DIVassign : pcOperator = "/=" ; goto label1; case OPERATOR_MODassign : pcOperator = "%=" ; goto label1; case OPERATOR_PLUSassign : pcOperator = "+=" ; goto label1; case OPERATOR_MINUSassign : pcOperator = "-=" ; goto label1; case OPERATOR_LSassign : pcOperator = "<<="; goto label1; case OPERATOR_RSassign : pcOperator = ">>="; goto label1; case OPERATOR_ANDassign : pcOperator = "&=" ; goto label1; case OPERATOR_ERassign : pcOperator = "^=" ; goto label1; case OPERATOR_ORassign : pcOperator = "|=" ; goto label1;label1: Proc1 = f_expr( Expr->Expr1, WRITE, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ , scope, 0, pass ); Proc.Type = f_OperatorCall2( pcOperator, Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc1 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s %s %s", Proc1.ac, pcOperator, Proc2.ac );#endif ProcDestroy( 3, Proc1 ); ProcDestroy( 4, Proc2 ); break; case OPERATOR_CONDITIONAL : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc3 = f_expr( Expr->Expr3, READ, scope, 0, pass ); ProcTypeAssign( Proc, Proc2 ); Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "(%s?%s:%s)", Proc1.ac, Proc2.ac, Proc3.ac );#endif ProcDestroy( 5, Proc1 ); ProcDestroy( 6, Proc2 ); ProcDestroy( 7, Proc3 ); break; case OPERATOR_OROR : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( "||", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { Proc.Type = f_TypeCreateInt(); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s || %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 8, Proc1 ); ProcDestroy( 9, Proc2 ); break; case OPERATOR_ANDAND : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( "&&", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { Proc.Type = f_TypeCreateInt(); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s && %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 10, Proc1 ); ProcDestroy( 11, Proc2 ); break; case OPERATOR_OR : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( "|", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc1 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s | %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 12, Proc1 ); ProcDestroy( 13, Proc2 ); break; case OPERATOR_ER : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( "'", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc1 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s ^ %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 14, Proc1 ); ProcDestroy( 15, Proc2 ); break; case OPERATOR_AND : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( "&", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc1 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s & %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 16, Proc1 ); ProcDestroy( 17, Proc2 ); break; case OPERATOR_EQ : pcOperator = "=="; goto label2; case OPERATOR_NE : pcOperator = "!="; goto label2; case OPERATOR_L : pcOperator = "<" ; goto label2; case OPERATOR_G : pcOperator = ">" ; goto label2; case OPERATOR_LE : pcOperator = ">="; goto label2; case OPERATOR_GE : pcOperator = "<="; goto label2;label2: Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( pcOperator, Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { Proc.Type = f_TypeCreateInt(); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s %s %s", Proc1.ac, pcOperator, Proc2.ac );#endif ProcDestroy( 18, Proc1 ); ProcDestroy( 19, Proc2 ); break; case OPERATOR_LS : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( "<<", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc1 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s << %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 20, Proc1 ); ProcDestroy( 21, Proc2 ); break; case OPERATOR_RS : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( ">>", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc1 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s >> %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 22, Proc1 ); ProcDestroy( 23, Proc2 ); break; case OPERATOR_PLUS : pcOperator = "+"; goto label3; case OPERATOR_MINUS : pcOperator = "-"; goto label3; case OPERATOR_MULT : pcOperator = "*"; goto label3; case OPERATOR_DIV : pcOperator = "/"; goto label3;label3: Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( pcOperator, Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc1 ); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s %s %s", Proc1.ac, pcOperator, Proc2.ac );#endif ProcDestroy( 24, Proc1 ); ProcDestroy( 25, Proc2 ); break; case OPERATOR_MOD : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); Proc.Type = f_OperatorCall2( "%", Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { Proc.Type = f_TypeCreateInt(); } Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s %% %s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 26, Proc1 ); ProcDestroy( 27, Proc2 ); break; case OPERATOR_DOTstar : pcOperator = ".*" ; goto label4; case OPERATOR_ARROWstar : pcOperator = "->*"; goto label4;label4: Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, f_TypeToScope( Proc1.Type ), 0, pass ); Proc.Type = f_OperatorCall2( pcOperator, Proc1.Type, Proc2.Type, access, 0 ); if( Proc.Type == 0 ) { ProcTypeAssign( Proc, Proc2 ); } f_TypeDelPointer( Proc.Type ); Proc.name = 0; Proc.scope = 0;#ifdef PRINT_EXPR sprintf( Proc.ac, "%s%s%s", Proc1.ac, pcOperator, Proc2.ac );#endif ProcDestroy( 28, Proc1 ); ProcDestroy( 29, Proc2 ); break; case OPERATOR_CAST : Proc1 = f_expr( Expr->Expr1, READ, scope, 0, pass ); Proc2 = f_expr( Expr->Expr2, READ, scope, 0, pass ); ProcTypeAssign( Proc, Proc1 ); ProcNameAssign( Proc, Proc2 ); ProcScopAssign( Proc, Proc2 );#ifdef PRINT_EXPR sprintf( Proc.ac, "(%s)%s", Proc1.ac, Proc2.ac );#endif ProcDestroy( 30, Proc1 ); ProcDestroy( 31, Proc2 ); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -