coins.sym
Interface Subp

All Superinterfaces:
Sym, Sym0
All Known Implementing Classes:
SubpImpl

public interface Subp
extends Sym

Subp interface

  Subp (subprogram) class interface.

  Subprogram means such program construct as procedure, function,
  method, constructor, destructor, statement function, library
  function, etc.
  Each subprogram has its local symbol table which is maintained
  by pushSymbolTable, popSymbolTable, reopenSymbolTable in
  Sym interface.
  To define a subprogram, write such statement sequence as follows
  (see guidance.txt):
     Subp lMain = sym.defineSubp("main".intern(), symRoot.typeInt);
     //-- int printf(char* pFormat, ...);
     Subp lPrintf = sym.defineSubp("printf".intern(), symRoot.typeInt);
     Type lCharPtr = sym.pointerType(symRoot.typeChar);
     SymTable lLocalSymTable1 = symRoot.symTableRoot.pushSymTable(lPrintf);
     Param lParam1 = sym.defineParam("pFormat".intern(),symRoot.typeStringAny);
     lPrintf.addParam(lParam1);
     lPrintf.setOptionalParam();
     lPrintf.setVisibility(Sym.SYM_EXTERN);
     lPrintf.closeSubpHeader();
     lLocalSymTable1.popSymTable();
     lLocalSymTable2 = symRoot.symTableRoot.pushSymTable(lMain);
     lMain.closeSubpHeader();
     ....
  Enhancement is required to implement object oriented languages.
    (method overloading, etc.)
  Related methods:
    To traverse local symbols declared in this subprogram,
      use getSymNestIterator() of SymTable get by getSymTable().
    To traverse local variables declared in this subprogram,
      use getVarIterator() of SymTable get by getSymTable().
    To traverse formal parameters of this subprogram,
      use iterator() of IrList get by getParamList().
    See methods of SubpDefinition interface such as
      getLirBody,
      initiationProcedure, addInitiationStmt, etc.
    See methods of SubpFlow interface such as
      getEntryBBlock, etc.
    See methods of DataFlow interface such as
      getBBlockList, etc.


Field Summary
 
Fields inherited from interface coins.sym.Sym
KIND_NAME, VISIBILITY
 
Fields inherited from interface coins.sym.Sym0
FLAG_ADDRESS_TAKEN, FLAG_CASTLESS_SUBP, FLAG_COMMON, FLAG_COMPLEX_STRUCT, FLAG_DERIVED_SYM, FLAG_GENERATED_SYM, FLAG_INCOMPLETE_TYPE, FLAG_POINTER_OPERATION, FLAG_REGION_ELEM, FLAG_RESERVED_NAME, FLAG_SIZEOF_TAKEN, FLAG_UNFIXED_SIZE, FLAG_UNIFORM_SIZE, FLAG_VALUE_IS_ASSIGNED, KIND_AREG, KIND_BOOL_CONST, KIND_CHAR_CONST, KIND_CONST_FIRST, KIND_CONST_LAST, KIND_ELEM, KIND_EXP_ID, KIND_FLOAT_CONST, KIND_INT_CONST, KIND_LABEL, KIND_MREG, KIND_NAMED_CONST, KIND_OTHER, KIND_PARAM, KIND_REMOVED, KIND_STRING_CONST, KIND_SUBP, KIND_TAG, KIND_TYPE, KIND_VAR, SYM_COMPILE_UNIT, SYM_EXTERN, SYM_PRIVATE, SYM_PROTECTED, SYM_PUBLIC
 
Method Summary
 void addParam(Param pParam)
          addParam
 void addParamType(Type pParamType)
          addParamType Add parameter type to a temporal parameter type list.
 void addToCallList(Subp pCallee)
          addToCallList Add pCallee as a subprogram to the call list of this subprogram.
 void addToErrorCount(int pCount)
          addToErrorCount Add pCount to the number of syntax/semantic error counter of this subprogram.
 void buildLabelRefList()
          Build the list of labels defined in the subprogram so as getLabelDefList() returns proper list, and build the list of LabelNode for every labels to show the label node refering them.
 void closeSubpHeader()
          closeSubpHeader
 void closeSubpPrototype()
          closeSubpPrototype
 IrList getCallList()
          getCallList Get the list of subprograms called in this subprogram.
 Label getEndLabel()
          getEndLabel setEndLabel Get/set a label attached to the exit point of this subprogram.
 int getErrorCount()
          getErrorCount Get the number of syntax/semantic errors of this subprogram.
 java.lang.Object getFlowInf()
          Get/set information locally used for flow analysis, optimization, parallelyzation, etc.
 Stmt getHirBody()
          getHirBody
 Subp getNextSubp()
          getNextSubp Get the subprogram next to this one having the same scope as this.
 java.lang.Object getOptInf()
           
 java.lang.Object getParallelInf()
           
 IrList getParamList()
          getParamList Get the parameter list of this subprogram.
 IrList getParamTypeList()
          getParamTypeList Get the parameter type list of this subprogram.
 Type getReturnValueType()
          getReturnValueType Get the return value type of this subprogram.
 Label getStartLabel()
          getStartLabel setStartLabel Get/set a label attached to the entry point of this subprogram.
 Stmt getStmtWithLabel(Label pLabel)
          getStmtWithLabel Get the HIR Stmt attached with pLabel.
 SubpDefinition getSubpDefinition()
          getSubpDefinition Get the SubpDefinition node defining the IR body of this subprogram.
 int getSubpKind()
          getSubpKind Get subprogram kind: (subpOrdinary/subpMember/subpConstructor/subpDestructor).
 SymTable getSymTable()
          getSymTable Get the symbol table local to this subprogram.
 int getVisibility()
          getVisibility
 boolean hasNoParamSpec()
          
 boolean hasOptionalParam()
          hasOptionalParam
 boolean isSafeArrayAll()
           
 void printLabelRefList()
          Print the label reference list built by buildLabelRefList().
 void resetLabelLink()
          resetLabelLink Reset label reference list of labels in this subprogram.
 void setEndLabel(Label pLabel)
           
 void setFlowInf(java.lang.Object pInf)
           
 void setHirBody(Stmt pHirBody, Label pStartLabel, Label pEndLabel)
          setHirBody
 void setNextSubp(Subp pNext)
          setNextSubp Set pNext as the subprogram next to this one and make the original next subprogram as the next one of pNext.
 void setNoParamSpec()
          Permit any number of parameters of any type for this subprogram.
 void setOptInf(java.lang.Object pInf)
           
 void setParallelInf(java.lang.Object pInf)
           
 void setReturnValueType(Type pType)
          setReturnValueType Set the return value type of this subprogram.
 void setStartLabel(Label pLabel)
           
 void setSubpDefinition(SubpDefinition pSubpDefinition)
          setSubpDefinition Set the SubpDefinition node defining the IR body of this subprogram.
 void setSubpKind(int pSubpKind)
          setSubpKind Set subprogram kind (subpOrdinary/subpMember/subpConstructor/subpDestructor).
 void setSymTable(SymTable pSymTalbe)
          setSymTable Set the symbol table local to this subprogram.
 void setVisibility(int pVisibility)
          SetVisibility Sset the visibility attribute of the subprogram.
 
Methods inherited from interface coins.sym.Sym
baseType, boolConst, charConst, defineVar, derivedSym, floatConst, getDefinedColumn, getDefinedInName, getDefinedLine, getInf, getNameOrNull, getOrAddInf, getOriginalSym, getOriginalSym, getPureName, getSymKindName, getWork, intConst, intObject, isRemoved, makeCstring, makeCstringWithTrailing0, makeEnumTypeName, makeJavaString, makeStructUnionTypeName, makeSubpTypeName, makeVectorTypeName, makeVectorTypeName, makeVectorTypeName, namedConst, pointerType, pointerType, pointerType, regionType, remove, setDefinedFile, setDefinedIn, setDefinedLine, setRecordedIn, setSymKind, setSymType, setUniqueNameSym, setWork, stringConstFromQuotedString, symbol, toStringDetail, toStringShort, vectorType, vectorType, vectorType, vectorTypeUnfixed
 
Methods inherited from interface coins.sym.Sym0
charConst, definedType, defineElem, defineLabel, defineParam, defineSubp, defineVar, enumType, floatConst, getDefinedFile, getDefinedIn, getFlag, getName, getNextSym, getRecordedIn, getSymKind, getSymType, getUniqueName, intConst, isGlobal, namedConst, pointerType, setFlag, stringConst, structType, subpType, unionType, vectorType, vectorTypeUnfixed
 

Method Detail

getNextSubp

public Subp getNextSubp()
getNextSubp Get the subprogram next to this one having the same scope as this. Default sequence is defined according to the order of creation by defineUnique, etc. in SymInterface, but it may also be set by setNextSubp.

Returns:
the next subprogram which has the same DefinedIn as this subprogram. If there is no next subprogram, then return null.

setNextSubp

public void setNextSubp(Subp pNext)
setNextSubp Set pNext as the subprogram next to this one and make the original next subprogram as the next one of pNext.

Parameters:
pNext - subprogram defined in the same scope as this subprogram.

getSubpKind

public int getSubpKind()
getSubpKind Get subprogram kind: (subpOrdinary/subpMember/subpConstructor/subpDestructor).

Returns:
the subprogram kind of this subprogram

setSubpKind

public void setSubpKind(int pSubpKind)
setSubpKind Set subprogram kind (subpOrdinary/subpMember/subpConstructor/subpDestructor).

Parameters:
pSubpKind - subprogram kind to be set to this subprogram.

getVisibility

public int getVisibility()
getVisibility
  Get the visibility attribute of the subprogram.
      (SYM_EXTERN, SYM_PUBLIC, SYM_PROTECTED, SYM_PRIVATE,
       SYM_COMPILE_UNIT)

Returns:
the visibility attribute of the subprogram

setVisibility

public void setVisibility(int pVisibility)
SetVisibility Sset the visibility attribute of the subprogram.

Parameters:
pVisibility - visibility attribute to be set by setVisibility. (SYM_EXTERN, SYM_PUBLIC, SYM_PROTECTED, SYM_PRIVATE, SYM_COMPILE_UNIT)

getSymTable

public SymTable getSymTable()
getSymTable Get the symbol table local to this subprogram. (The symbol table given by setSymTable.)

Returns:
the symbol table local to this subprogram.

setSymTable

public void setSymTable(SymTable pSymTalbe)
setSymTable Set the symbol table local to this subprogram. If the symbol table is nested, then give the outermost symbol table local to this subprogram.


getReturnValueType

public Type getReturnValueType()
getReturnValueType Get the return value type of this subprogram.

Returns:
the return value type.

setReturnValueType

public void setReturnValueType(Type pType)
setReturnValueType Set the return value type of this subprogram.

Parameters:
pType - the return value type.

getParamList

public IrList getParamList()
getParamList Get the parameter list of this subprogram. If it has no parameter, then return empty list. //##80 Before calling this method, closeSubpHeader should be called. The returned value may be incorrect if this is called before calling closeSubpHeader.

Returns:
the parameter list.

getParamTypeList

public IrList getParamTypeList()
getParamTypeList Get the parameter type list of this subprogram. If it has no parameter, then return null. If neither closeSubpHeader nore closeSubpPrototype is called before calling this method, getParamTypeList may return null.

Returns:
the list of parameter types.

addParam

public void addParam(Param pParam)
addParam
  Add parameter to the parameter list of this subprogram.
  If closeSubpPrototype has been called by processing
  prototype declaration, getParamTypeList will return
  the list of parameter types. It is recommended to check
  the consistency between prototype declaration and
  subprogram definition before calling addParam for
  each parameter. If null is returned by getParamTypeList,
  then prototype declaration is not yet given
  (closeSubpPrototype is not yet called.)
  See closeSubpHeader.


addParamType

public void addParamType(Type pParamType)
addParamType Add parameter type to a temporal parameter type list. See closeSubpPrototype.


closeSubpHeader

public void closeSubpHeader()
closeSubpHeader
  Finalize the header part of subprogram.
  This method will set subprogram type for this subprogram
  and set other inevitable information for this subprogram.
  Before calling this method, addParam, setOptionalParam,
  setVisibility should be called if required and return value type
  should be given if required as it is written
  in defineSubp of Sym interface.
  It is the responsibility of language dependent front end
  to check the consistency between prototype declaration and
  subprogram definition.
  If closeSubpPrototype has been called by processing
  prototype declaration, getParamTypeList will return
  the list of parameter types. It is recommended to check
  the consistency between prototype declaration and
  subprogram definition before calling addParam for
  each parameter. The closeSubpHeader will adjust
  the parameter type list according to the list get by
  getParamList and so the consistency check will not be
  effective after the call.


closeSubpPrototype

public void closeSubpPrototype()
closeSubpPrototype
  Finalize a prototype declaration of subprogram.
  This method will set subprogram type for this subprogram.
  Before calling this method, addParamType, setOptionalParam,
  setVisibility should be called if required and return value type
  should also be given if required.
  It is the responsibility of language dependent front end
  to check the consistency between prototype declaration and
  subprogram definition.
  Typical sequence of processing prototype declaration is:
    Subp lSubp = symRoot.sym.defineSubp("name".intern(), returnType);
    lSubp.resetParamTypeList(); // If multiple declaration is allowed.
    lSubp.addParamType(paramType1);
    lSubp.addParamType(paramType2);
    ....
    lSubp.setOptionalparam(); // only when optional parameter is given.
    lSubp.setVisibility(Sym.SYM_PUBLIC); // only if public.
    lSubp.closeSubpPrototype();


hasOptionalParam

public boolean hasOptionalParam()
hasOptionalParam

Returns:
true if this subprogram has optional parameter (represented by ... in C in such way as int printf(char*, ...)) otherwise return false.

hasNoParamSpec

public boolean hasNoParamSpec()

Returns:
true if any number of parameters of any type are permitted in such case as extern sub(); sub(a); sub(a, b); in old C language style.

setNoParamSpec

public void setNoParamSpec()
Permit any number of parameters of any type for this subprogram.


getSubpDefinition

public SubpDefinition getSubpDefinition()
getSubpDefinition Get the SubpDefinition node defining the IR body of this subprogram. HIR definition and LIR definition can be get via SubpDefinition.

Returns:
the SubpDefinition node of this subprogram.

setSubpDefinition

public void setSubpDefinition(SubpDefinition pSubpDefinition)
setSubpDefinition Set the SubpDefinition node defining the IR body of this subprogram.

Parameters:
pSubpDefinition - the SubpDefinition node of this subprogram.

getStmtWithLabel

public Stmt getStmtWithLabel(Label pLabel)
getStmtWithLabel Get the HIR Stmt attached with pLabel.

Parameters:
pLabel - Label with which Stmt is to be searched.
Returns:
Stmt attached with pLabel. return null if no statement is found having pLabel.

getHirBody

public Stmt getHirBody()
getHirBody
  Get the procedural body in HIR of this subprogram.
  See SubpDefinition interface and
       getLirBody of SubpDefinition.
  Return the procedural body of this subprogram
      represented in HIR.
      If no procedural body is given in this compile unit (i.e.
      external subprogram) then return null.

Returns:
the procedural body of this subprogram.

setHirBody

public void setHirBody(Stmt pHirBody,
                       Label pStartLabel,
                       Label pEndLabel)
setHirBody
  Set the procedural body of this subprogram represented in high
  level intermediate representation (HIR).
  Usually this is invoked when SubpDefinition is created.
  pStartLabel, pEndLabel will be generated in SubpDefinition
  (See subpDefinition of HIR interface).

Parameters:
pHirBody - procedural body represented in HIR specifying operations to be performed when this subprogram is called.
pStartLabel - Label to be attached at entry point.
pEndLabel - Label to be attached at exit point.

buildLabelRefList

public void buildLabelRefList()
Build the list of labels defined in the subprogram so as getLabelDefList() returns proper list, and build the list of LabelNode for every labels to show the label node refering them. This method may be called by finishHir() of HIR interface.


printLabelRefList

public void printLabelRefList()
Print the label reference list built by buildLabelRefList().


resetLabelLink

public void resetLabelLink()
resetLabelLink Reset label reference list of labels in this subprogram. getLabelRefList() for labels will return null when resetLabelLink is called and addToHirList, addToLirList are not yet called.


getStartLabel

public Label getStartLabel()
getStartLabel setStartLabel Get/set a label attached to the entry point of this subprogram. The start label is attached by SubpDefinition and other classes are not required to worry about setting it.


setStartLabel

public void setStartLabel(Label pLabel)

getEndLabel

public Label getEndLabel()
getEndLabel setEndLabel Get/set a label attached to the exit point of this subprogram. The end label is attached by SubpDefinition and other classes are not required to worry about setting it.


setEndLabel

public void setEndLabel(Label pLabel)

getCallList

public IrList getCallList()
getCallList Get the list of subprograms called in this subprogram.

Returns:
list of subprograms called in this subprogram. See addToCallList.

addToCallList

public void addToCallList(Subp pCallee)
addToCallList Add pCallee as a subprogram to the call list of this subprogram. If pCallee is already in the call list, no addition is performed.

Parameters:
pCallee - a subprogram called in this subprogram.

isSafeArrayAll

public boolean isSafeArrayAll()
Returns:
true if #pragma safeArrayAll is specified.

getFlowInf

public java.lang.Object getFlowInf()
Get/set information locally used for flow analysis, optimization, parallelyzation, etc. of this subprogram. (##5) The information will not conflict with others and will not be destroyed by aliasing.


setFlowInf

public void setFlowInf(java.lang.Object pInf)

getOptInf

public java.lang.Object getOptInf()

setOptInf

public void setOptInf(java.lang.Object pInf)

getParallelInf

public java.lang.Object getParallelInf()

setParallelInf

public void setParallelInf(java.lang.Object pInf)

addToErrorCount

public void addToErrorCount(int pCount)
addToErrorCount Add pCount to the number of syntax/semantic error counter of this subprogram.


getErrorCount

public int getErrorCount()
getErrorCount Get the number of syntax/semantic errors of this subprogram.