sagexx_ug (1158317), страница 3
Текст из файла (страница 3)
Themain body of the function is a loop which scans the statements in the le in lexical order. Thevariable `s' is a pointer to a generic statement object. There are two ways to tell if a statement is aloop. One is to check to see if the variant is FOR\ NODE. The other way is to use a special castingfunction, in this case, `isSgForStmt()' which will check the variant and return a pointer cast tothe correct subclass or NULL if it is not a match. Because C++ is a strongly typed language, if wewish to apply the methods of the subclass, such a cast is necessary.
A function of the typeSgSUBCLASS * isSgSUBCLASS( SgBASECLASS *)is provided for each subclass of SgStatement, SgExpression and SgType. We feel that this mechanism is an eective way to use the strong typing of C++ to reduce errors.3.2 Header StatementsSgFuncHedrStmtRepresents functions, for all languages.Chapter 3: Statements18For base class, see [SgProcHedrStmt], page 27.class SgFuncHedrStmt: public SgProcHedrStmt {// Fortran and C function.// variant == FUNC_HEDRpublic:SgFuncHedrStmt(SgSymbol &name, SgStatement Body);SgFuncHedrStmt(SgSymbol &name, SgType &type, SgStatement Body);SgFuncHedrStmt(SgSymbol &name, SgSymbol &resultName, SgType &type,SgStatement Body);SgFuncHedrStmt(SgSymbol &name);SgFuncHedrStmt(char *name);SgSymbol * resultName(); // name of result variable.;intsetResultName(SgSymbol &symbol); // set name of result variable.;SgType *void};returnedType(); // type of returned valuesetReturnedType(SgType &type); // set type of returned valueSgFuncHedrStmt is used in the following places in the example programs: see [Restructure - addStuToProgram], page 135 see [Instrument - inMethodOfTheElement], page 149 see [Instrument - whichFunctionAmI], page 150 see [Dump Info - doRoutineHeader], page 176Member Functions:SgFuncHedrStmt(SgSymbol &name, SgStatement Body)SgFuncHedrStmt(SgSymbol &name, SgType &type, SgStatement Body)SgFuncHedrStmt(SgSymbol &name, SgSymbol &resultName, SgType &type, SgStatement Body)SgFuncHedrStmt(SgSymbol &name)SgFuncHedrStmt(char *name)SgSymbol * resultName()int setResultName(SgSymbol &symbol)SgType * returnedType()Chapter 3: Statements19void setReturnedType(SgType &type)SgBasicBlockStmtRepresents C basic blocks.For base class, see Section 3.1 [SgStatement], page 11.class SgBasicBlockStmt: public SgStatement {// in C we have: { body; }// variant == BASIC_BLOCKpublic:SgBasicBlockStmt();};SgBasicBlockStmt is used in the following places in the example programs: see [Expand Syntax - ReplaceWithGetElemPart], page 163Member Functions:SgBasicBlockStmt()SgClassStmtRepresents C++ classes.A class declaration consists of a name, a list of super classes, a body consisting of public, privateand protected functions and elds (called Vars here), and a list of variables that name instances,arrays of instances, pointers to instances and references to instances of the class.For base class, see Section 3.1 [SgStatement], page 11.class SgClassStmt: public SgStatement {// C++ class statement//class name : superclass_list ElementTypeOf collection_name {//body//} variables_list;// variant == CLASS_DECLChapter 3: Statementspublic:intSgSymbol *SgSymbol *void#if 0intSgExpressionSgExpression20SgClassStmt(int variant);SgClassStmt(SgSymbol &name);numberOfSuperClasses();name();superClass(int i);setSuperClass(int i, SgSymbol &symb);numberOfVars();// variables in variables_listvariable(int i); // i-th variable in variable_listcollectionName(); // if an ElementType class.// body manipulation functions.intnumberOfPublicVars();intnumberOfPrivateVars();intnumberOfProtectedVars();SgSymbol *publicVar(int i);SgSymbol *protectedVar(int i);SgSymbol *privateVar(int i);voidaddPublicVar(SgSymbol &s);voidaddPrivateVar(SgSymbol &s);voidaddProtectedVar(SgSymbol &s);intnumberOfPublicFuns();intnumberOfPrivateFuns();intnumberOfProtectedFuns();SgStatement * publicFun(int i);SgStatement * protectedFun(int i);SgStatement * privateFun(int i);voidaddPublicFun(SgStatement &s);voidaddPrivateFun(SgStatement &s);voidaddProtectedFun(SgStatement &s);#endif};SgClassStmt is used in the following places in the example programs: see [Expand Syntax - Init], page 166Member Functions:SgClassStmt(int variant)SgClassStmt(SgSymbol &name)int numberOfSuperClasses()SgSymbol * name()Chapter 3: StatementsSgSymbol * superClass(int i)void setSuperClass(int i, SgSymbol &symb)int numberOfVars()SgExpression variable(int i)SgExpression collectionName()int numberOfPublicVars()int numberOfPrivateVars()int numberOfProtectedVars()SgSymbol * publicVar(int i)SgSymbol * protectedVar(int i)SgSymbol * privateVar(int i)void addPublicVar(SgSymbol &s)void addPrivateVar(SgSymbol &s)void addProtectedVar(SgSymbol &s)int numberOfPublicFuns()int numberOfPrivateFuns()int numberOfProtectedFuns()SgStatement * publicFun(int i)SgStatement * protectedFun(int i)SgStatement * privateFun(int i)void addPublicFun(SgStatement &s)void addPrivateFun(SgStatement &s)void addProtectedFun(SgStatement &s)SgStructStmtRepresents C++ structures.21Chapter 3: StatementsFor base class, see [SgClassStmt], page 19.class SgStructStmt: public SgClassStmt {// basic C++ structure// struct name ;//body//} variables_list;// variant == STRUCT_DECLpublic:// consider like a class.SgStructStmt();SgStructStmt(SgSymbol &name);};Member Functions:SgStructStmt()SgStructStmt(SgSymbol &name)SgUnionStmtRepresents C++ unions.For base class, see [SgClassStmt], page 19.class SgUnionStmt: public SgClassStmt {// basic C++ structure// union name {//body//} variables_list;// variant == UNION_DECLpublic:// consider like a class.SgUnionStmt();SgUnionStmt(SgSymbol &name);};Member Functions:22Chapter 3: StatementsSgUnionStmt()SgUnionStmt(SgSymbol &name)SgEnumStmtRepresents C++ enumerations.For base class, see [SgClassStmt], page 19.class SgEnumStmt: public SgClassStmt {// basic C++ structure// enum name {//body//} variables_list;// variant == ENUM_DECLpublic:// consider like a class.SgEnumStmt();SgEnumStmt(SgSymbol &name);};Member Functions:SgEnumStmt()SgEnumStmt(SgSymbol &name)SgCollectionStmtRepresents pC++ collections.For base class, see [SgClassStmt], page 19.class SgCollectionStmt: public SgClassStmt {// basic C++ structure// collection name ;//body//} variables_list;// variant == COLLECTION_DECL23Chapter 3: Statementspublic:24SgCollectionStmt();SgCollectionStmt(SgSymbol &name);#if 0intnumberOfElemMethods();SgStatement * elementMethod(int i);voidaddElementMethod(SgStatement &s);#endifSgStatement * firstElementMethod();};SgCollectionStmt is used in the following places in the example programs: see [Instrument - ListCollections], page 153Member Functions:SgCollectionStmt()SgCollectionStmt(SgSymbol &name)int numberOfElemMethods()SgStatement * elementMethod(int i)void addElementMethod(SgStatement &s)SgStatement * rstElementMethod()SgProgHedrStmtRepresents Fortran program blocks.For base class, see Section 3.1 [SgStatement], page 11.class SgProgHedrStmt: public SgStatement {// fortran Program block// variant == PROG_HEDRChapter 3: Statementspublic:25SgSymbol &voidSgProgHedrStmt(PTR_BFND bif);SgProgHedrStmt(int variant);SgProgHedrStmt(SgSymbol &name, SgStatement Body);SgProgHedrStmt(SgSymbol &name);SgProgHedrStmt(char *name);name();setName(SgSymbol &symbol); // set program nameintSgSymbol *intSgStatementintSgStatementintSgSymbol *intSgStatementintSgStatementintSgStatementintSgStatementintSgStatementnumberOfFunctionsCalled(); // the number of functions calledcalledFunction(int i);// the i-th called functionnumberOfStmtFunctions();// the number of statement funcions;statementFunc(int i); // the i-th statement function;numberOfEntryPoints();// the number of entry points;entryPoint(int i); // the i-th entry point;numberOfParameters();// the number of parameters;parameter(int i);// the i-th parameternumberOfSpecificationStmts();specificationStmt(int i);numberOfExecutionStmts();executionStmt(int i);numberOfInternalFunctionsDefined();internalFunction(int i);numberOfInternalSubroutinesDefined();internalSubroutine(int i);numberOfInternalSubProgramsDefined();internalSubProgram(int i);*******#if 0SgSymbol &SgStatement endifintintaddVariable(SgType &T, char *name);//add a declaration for new variableaddCommonBlock(char *blockname, int noOfVars, SgSymbol *Vars); // addisSymbolInScope(SgSymbol &symbol);isSymbolDeclaredHere(SgSymbol &symbol);// global analysis dataintnumberOfVarsUsed(); // list of used variable access sectionsSgExpression * varsUsed(int i); // i-th var used section descriptorintnumberofVarsMod();// list of modifed variable access sectionsSgExpression * varsMod(int i);// i-th var mod section descriptor};SgProgHedrStmt is used in the following places in the example programs: see [Dump Info - doRoutineHeader], page 176Chapter 3: StatementsMember Functions:SgProgHedrStmt(PTR BFND bif)SgProgHedrStmt(int variant)SgProgHedrStmt(SgSymbol &name, SgStatement Body)SgProgHedrStmt(SgSymbol &name)SgProgHedrStmt(char *name)SgSymbol & name()void setName(SgSymbol &symbol)int numberOfFunctionsCalled()SgSymbol * calledFunction(int i)int numberOfStmtFunctions()SgStatement * statementFunc(int i)int numberOfEntryPoints()SgStatement * entryPoint(int i)int numberOfParameters()SgSymbol * parameter(int i)int numberOfSpecicationStmts()SgStatement * specicationStmt(int i)int numberOfExecutionStmts()SgStatement * executionStmt(int i)int numberOfInternalFunctionsDened()SgStatement * internalFunction(int i)int numberOfInternalSubroutinesDened()SgStatement * internalSubroutine(int i)int numberOfInternalSubProgramsDened()SgStatement * internalSubProgram(int i)SgSymbol & addVariable(SgType &T, char *name)26Chapter 3: Statements27SgStatement & addCommonBlock(char *blockname, int noOfVars, SgSymbol *Vars)int isSymbolInScope(SgSymbol &symbol)int isSymbolDeclaredHere(SgSymbol &symbol)int numberOfVarsUsed()SgExpression * varsUsed(int i)int numberofVarsMod()SgExpression * varsMod(int i)SgProcHedrStmtRepresents Fortran subroutines.For base class, see [SgProgHedrStmt], page 24.class SgProcHedrStmt: public SgProgHedrStmt {// Fortran subroutine// variant == PROC_HEDRpublic:SgProcHedrStmt(int variant);SgProcHedrStmt(SgSymbol &name, SgStatement Body);SgProcHedrStmt(SgSymbol &name);SgProcHedrStmt(char *name);voidAddArg(SgExpression &arg);intisRecursive(); // 1 if recursive.;intnumberOfEntryPoints();// the number of entry points// other than the main, 0 for C funcs.SgStatement * entryPoint(int i); // the i-th entry point// this is incorrect.
Takes only subroutines calls into account.// Should be modified to take function calls into account too.intnumberOfCalls();// number of calls to this proc.SgStatement * call(int i);// position of the i-th call.};SgProcHedrStmt is used in the following places in the example programs: see [Dump Info - doRoutineHeader], page 176Chapter 3: StatementsMember Functions:SgProcHedrStmt(int variant)SgProcHedrStmt(SgSymbol &name, SgStatement Body)SgProcHedrStmt(SgSymbol &name)SgProcHedrStmt(char *name)void AddArg(SgExpression &arg)int isRecursive()int numberOfEntryPoints()SgStatement * entryPoint(int i)int numberOfCalls()SgStatement * call(int i)SgBlockDataStmtRepresents Fortran block data statements.For base class, see Section 3.1 [SgStatement], page 11.class SgBlockDataStmt: public SgStatement {#if 0// Fortran Block Data statement// variant == BLOCK_DATApublic:SgBlockDataStmt(SgSymbol &name, SgStatement &body);SgSymbol * name(); // block data name if given;intsetName(SgSymbol &symbol);// set block data nameintint};Member Functions:isSymbolInScope(SgSymbol &symbol);isSymbolDeclaredHere(SgSymbol &symbol);28Chapter 3: Statements29SgBlockDataStmt(SgSymbol &name, SgStatement &body)SgSymbol * name()int setName(SgSymbol &symbol)int isSymbolInScope(SgSymbol &symbol)int isSymbolDeclaredHere(SgSymbol &symbol)SgModuleStmtRepresents Fortran 90 module statements.For base class, see Section 3.1 [SgStatement], page 11.class SgModuleStmt: public SgStatement {#if 0// Fortran 90 Module statement// variant == MODULE_STMTpublic:SgModuleStmt(SgSymbol &moduleName, SgStatement &body);SgModuleStmt(SgSymbol &moduleName);SgSymbol *voidmoduleName();setName(SgSymbol &symbol);intintintintnumberOfSpecificationStmts();numberOfRoutinesDefined();numberOfFunctionsDefined();numberOfSubroutinesDefined();SgStatementSgStatementSgStatementSgStatement};****// module name// set module namespecificationStmt(int i);routine(int i);function(int i);subroutine(int i);intintisSymbolInScope(SgSymbol &symbol);isSymbolDeclaredHere(SgSymbol &symbol);SgSymbol &addVariable(SgType &T, char *name);//add a declaration for new variableSgStatement * addCommonBlock(char *blockname, int noOfVars, SgSymbol *Vars); // add aChapter 3: StatementsMember Functions:SgModuleStmt(SgSymbol &moduleName, SgStatement &body)SgModuleStmt(SgSymbol &moduleName)SgSymbol * moduleName()void setName(SgSymbol &symbol)int numberOfSpecicationStmts()int numberOfRoutinesDened()int numberOfFunctionsDened()int numberOfSubroutinesDened()SgStatement * specicationStmt(int i)SgStatement * routine(int i)SgStatement * function(int i)SgStatement * subroutine(int i)int isSymbolInScope(SgSymbol &symbol)int isSymbolDeclaredHere(SgSymbol &symbol)SgSymbol & addVariable(SgType &T, char *name)SgStatement * addCommonBlock(char *blockname, int noOfVars, SgSymbol *Vars)SgInterfaceStmtRepresents Fortran 90 operator interface statements.For base class, see Section 3.1 [SgStatement], page 11.class SgInterfaceStmt: public SgStatement {#if 0// Fortran 90 Operator Interface Statement// variant == INTERFACE_STMTpublic:SgInterfaceStmt(SgSymbol &name, SgStatement &body,SgStatement &scope);30Chapter 3: Statements31SgSymbol *intinterfaceName();setName(SgSymbol &symbol);intnumberOfSpecificationStmts();// interface name if given// set interface nameSgStatement * specificationStmt(int i);intint};isSymbolInScope(SgSymbol &symbol);isSymbolDeclaredHere(SgSymbol &symbol);Member Functions:SgInterfaceStmt(SgSymbol &name, SgStatement &body, SgStatement &scope)SgSymbol * interfaceName()int setName(SgSymbol &symbol)int numberOfSpecicationStmts()SgStatement * specicationStmt(int i)int isSymbolInScope(SgSymbol &symbol)int isSymbolDeclaredHere(SgSymbol &symbol)3.3 Declaration StatementsSgDeclarationStatementFor base class, see Section 3.1 [SgStatement], page 11.class SgDeclarationStatement: public SgStatement {// Declaration class// abstract classpublic:SgDeclarationStatement(int variant);Chapter 3: StatementsSgExpression * varList();intnumberOfVars();SgExpression * var(int i);voiddeleteVar(int i);voiddeleteTheVar(SgExpression &var);voidaddVar(SgExpression &exp);};Member Functions:SgDeclarationStatement(int variant)SgExpression * varList()int numberOfVars()SgExpression * var(int i)void deleteVar(int i)void deleteTheVar(SgExpression &var)void addVar(SgExpression &exp)SgVarDeclStmtRepresents declaration statements, for all languages.For usage, see [SgSymbol Usage], page 108.For base class, see [SgDeclarationStatement], page 31.class SgVarDeclStmt: public SgDeclarationStatement {// Declaration Statement// variant == VAR_DECL32Chapter 3: Statements33public:// varRefValList is a list of low-level nodes of// variants VAR_REFs or ARRAY_REFs or ASSIGN_OPsSgVarDeclStmt(SgExpression &varRefValList,SgExpression &attributeList, SgType &type);SgVarDeclStmt(SgExpression &varRefValList, SgType &type);SgType *type(); // the type;intnumberOfAttributes(); // the number of F90 attributes;// the attributes are: PARAMETER_OP | PUBLIC_OP |//PRIVATE_OP | ALLOCATABLE_OP | EXTERNAL_OP |//OPTIONAL_OP | POINTER_OP | SAVE_OP TARGET_OP#if 0SgExpression & attribute(int i);#endifintnumberOfSymbols(); // the number of variables declared;SgSymbol *symbol(int i);voiddeleteSymbol(int i);voiddeleteTheSymbol(SgSymbol &symbol);SgExpression * initialValue(int i); // the initial value ofthe i-th variablevoidsetInitialValue(int i, SgExpression &initVal); // sets the initial val// an alternative way to initialize variables.