Class BlockDeclaration

Direct Known Subclasses:
ClassDeclaration, MaybeBlockDeclaration, ProcedureDeclaration

public abstract class BlockDeclaration extends DeclarationScope

Block Declaration.

This class is prefix to ClassDeclaration, ProcedureDeclaration and MaybeBlockDeclaration.

It contains a number of useful fields and methods common to its subclasses.

Link to GitHub: Source File.

Author:
Øystein Myhre Andersen
  • Field Details

    • isMainModule

      protected boolean isMainModule
      If true; this is the outermost Subblock or Prefixed Block.
    • statements

      public ObjectList<Statement> statements
      The statements belonging to this block.
    • lastLineNumber

      public int lastLineNumber
      Last source line number
    • isContextFree

      public boolean isContextFree
      If true; all member methods are independent of context
    • labelContext

      public static BlockDeclaration labelContext
      Compiler state: Points to the BlockDeclaration whose Statements are being built. Used by LabelList.labelBinding to find the right JUMP_TABLE.
    • labelContextStack

      public static Stack<BlockDeclaration> labelContextStack
      Label Context Stack
    • currentBlock

      public static BlockDeclaration currentBlock
      The DeclarationScope that currently is being built
    • prevBlock

      protected BlockDeclaration prevBlock
      The previous value of 'currentBlock'
    • nLocalVariables

      public int nLocalVariables

      Number of Local Variables allocated so far.

      Note: First Local Variable is used by the outermost try-catch block.

    • labelcodeList

      protected Vector<String> labelcodeList
      The leading labels.
  • Constructor Details

    • BlockDeclaration

      protected BlockDeclaration(String identifier)

      Create a new BlockDeclaration with the given identifier.

      Used by expectMaybeBlock, i.e. CompoundStatement, SubBlock or PrefixedBlock.

      Parameters:
      identifier - the given identifier
    • BlockDeclaration

      private BlockDeclaration(String identifier, int declarationKind)

      Create a new BlockDeclaration.

      This constructor is only used by ClassDeclaration. ProcedureDeclaration and MaybeBlockDeclaration.

      Parameters:
      identifier - the block identifier
      declarationKind - the declaration kind
  • Method Details

    • currentClassDesc

      public static ClassDesc currentClassDesc()
      Get current ClassDesc.
      Returns:
      the current ClassDesc.
    • allocateLocalVariable

      public int allocateLocalVariable(Type type)
      Allocate slot for a local variable.
      Parameters:
      type - variable's type.
      Returns:
      slot for a local variable.
    • expectFormalParameterPart

      protected static void expectFormalParameterPart(Vector<Parameter> pList)

      Parse Utility: Expect formal-parameter-part and build the parameter list.

      Syntax:
      
          formal-parameter-part = "(" identifier { , identifier } ")"
      

      Precondition: BEGPAR is already read.

      Parameters:
      pList - the parameter list
    • isBlockWithLocalClasses

      protected boolean isBlockWithLocalClasses()
      Returns true if this block has local class(es).
      Returns:
      true if this block has local class(es)
    • isQPSystemBlock

      protected boolean isQPSystemBlock()

      Returns true if this block is a QPS System block.

      QPS System is any block with local class(es)

      Returns:
      true if this block is a QPS System block
    • addLeadingLabel

      public void addLeadingLabel(String labelcode)
      ClassFile coding utility: AD'HOC Leading Label
      Parameters:
      labelcode - argument
    • hasDeclaredLabel

      protected boolean hasDeclaredLabel()
      Returns true if this block has one ore more local declared labels.
      Returns:
      true if this block has one ore more local declared labels.
    • hasAccumLabel

      protected boolean hasAccumLabel()
      Returns true if this block has one ore more accumulated labels.
      Returns:
      true if this block has one ore more accumulated labels.
    • nearestEnclosingBlock

      protected BlockDeclaration nearestEnclosingBlock()
      Returns the nearest Enclosing Block or null.
      Returns:
      the nearest Enclosing Block or null.
    • codeSTMBody

      protected void codeSTMBody()
      ClassFile coding utility: Code STM body
    • codeStatements

      protected void codeStatements()
      ClassFile coding utility: Code statements
    • codeMethodMain

      protected void codeMethodMain()
      ClassFile coding utility: Code Method Main
    • buildIsQPSystemBlock

      protected void buildIsQPSystemBlock(CodeBuilder codeBuilder)

      Generate byteCode for the 'isQPSystemBlock' method.

      public boolean isQPSystemBlock() { return(true); }

      Parameters:
      codeBuilder - the CodeBuilder
    • buildIsMethodDetachUsed

      void buildIsMethodDetachUsed(CodeBuilder codeBuilder)

      Generate byteCode for the 'buildIsMethodDetachUsed' method.

      public boolean isDetachUsed() { return(true); }

      Parameters:
      codeBuilder - the CodeBuilder
    • edConstructorSignature

      public String edConstructorSignature()
      Edit the ConstructorSignature.
      Returns:
      the ConstructorSignature String.
    • getConstructorMethodTypeDesc

      public MethodTypeDesc getConstructorMethodTypeDesc()
      Get the Constructors MethodTypeDesc.
      Returns:
      the Constructors MethodTypeDesc.
    • buildMethod_STM

      protected void buildMethod_STM(CodeBuilder codeBuilder)
      Generate byteCode for the '_STM' method.
      Parameters:
      codeBuilder - the CodeBuilder
    • build_STM_BODY

      protected void build_STM_BODY(CodeBuilder codeBuilder, Label begScope, Label endScope)
      ClassFile coding utility: Build byteCode for the '_STM' method.
      Parameters:
      codeBuilder - the codeBuilder to use.
      begScope - label
      endScope - label
    • build_TRY_CATCH

      protected void build_TRY_CATCH(CodeBuilder codeBuilder, Label begScope, Label endScope)

      ClassFile coding utility: Build byteCode for the try-catch part of the '_STM' method.

         adHoc000 _THIS=(adHoc000)_CUR;
         _LOOP:while(_JTX>=0) {
             try {
                 _JUMPTABLE(_JTX); // For ByteCode Engineering
                 // ... Simple Statement code
                 break _LOOP;
             }
             catch(RTS_LABEL q) {
                 RTS_RTObject._TREAT_GOTO_CATCH_BLOCK(_THIS, q);
                 _JTX=q.index; continue _LOOP; // EG. GOTO Lx
             }
         }
      
      Parameters:
      codeBuilder - the codeBuilder to use.
      begScope - label
      endScope - label
    • buildMethodMain

      void buildMethodMain(CodeBuilder codeBuilder)

      Generate byteCode for the 'main' method.

          public static void main(String[] argv) {
              RTS_UTIL.BPRG(progid, argv);
              RTS_UTIL_RUN_STM(new userProg(_CTX, ...));
          }
      
      Parameters:
      codeBuilder - the CodeBuilder
    • printStatementList

      protected void printStatementList(int indent)
      Debug utility: print StatementList.
      Parameters:
      indent - the indentation.
    • toString

      public String toString()
      Overrides:
      toString in class Object