Class ProcedureDeclaration

Direct Known Subclasses:
StandardProcedure, SwitchDeclaration

public class ProcedureDeclaration extends BlockDeclaration

Procedure Declaration.

Simula Standard: 5.4 Procedure declaration

     procedure-declaration
         = [ type ] PROCEDURE procedure-heading ; procedure-body
     
           procedure-heading
               = procedure-identifier [ formal-parameter-part ; [ mode-part ] specification-part ] 
               
              procedure-identifier = identifier
               
              formal-parameter-part = "(" formal-parameter { , formal-parameter } ")"
           
                 formal-parameter = identifier
           
              specification-part = specifier identifier-list { ; specifier identifier-list }
           
                 specifier
                     = type [ ARRAY | PROCEDURE ]
                     | LABEL
                     | SWITCH 
               
              mode-part
                  = name-part [ value-part ]
                  | value-part [ name-part ]
           
                 name-part = NAME identifier-list ;
           
                 value-part = VALUE identifier-list ;
           
              identifier-list = identifier { , identifier }
               
           procedure-body = statement

This class is prefix to StandardProcedure and SwitchDeclaration.

Link to GitHub: Source File.

Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

    • result

      Result in case of Type Procedure
    • parameterList

      public ObjectList<Parameter> parameterList
      Parameter list.
    • myVirtual

      public VirtualMatch myVirtual

      Virtual Match indicator.

      If myVirtual != null, this Procedure is a Virtual Match.

      Set during doChecking.

  • Constructor Details

    • ProcedureDeclaration

      protected ProcedureDeclaration(String identifier, int declarationKind)
      Create a new ProcedureDeclaration.
      Parameters:
      identifier - procedure identifier
      declarationKind - procedure or switch
    • ProcedureDeclaration

      public ProcedureDeclaration()
      Default constructor used by Attribute File I/O
  • Method Details

    • expectProcedureDeclaration

      public static ProcedureDeclaration expectProcedureDeclaration(Type type)

      Parse and build a ProcedureDeclaration.

      Syntax:
      
           procedure-declaration
               = [ type ] PROCEDURE procedure-heading ; procedure-body
           
                 procedure-heading
                     = procedure-identifier [ formal-parameter-part ; [ mode-part ] specification-part ] 
                     
                 procedure-identifier = identifier
      

      Precondition: Declaration.type PROCEDURE is already read.

      Parameters:
      type - procedure's type
      Returns:
      a newly created ProcedureDeclaration
    • acceptModePart

      private static boolean acceptModePart(Vector<Parameter> pList)

      Parse Utility: Accept mode-part and set matching parameter's mode.

        mode-part
           = name-part [ value-part ]
           | value-part [ name-part ]
                 
        name-part = NAME identifier-list ;
                 
        value-part = VALUE identifier-list ;
                 
        identifier-list = identifier { , identifier }
      
      Parameters:
      pList - the parameter list
      Returns:
      true: if mode-part was present.
    • expectSpecificationPart

      private static void expectSpecificationPart(ProcedureDeclaration proc)

      Parse Utility: Accept Procedure Parameter specification-part updating Parameter's type and kind.

      Syntax:
      
          specification-part
                = specifier identifier-list { ; specifier identifier-list }
          
             specifier = Type | [Type] ARRAY | [Type] PROCEDURE ] | LABEL | SWITCH
      
      Parameters:
      proc - the procedure declaration
    • expectProcedureBody

      private static void expectProcedureBody(ProcedureDeclaration proc)

      Parse Utility: Expect procedure-body. In case of a compound-statement, updating the procedure's declaration and statement lists.

      Syntax:
                     
             procedure-body = statement
      
      Parameters:
      proc - the procedure
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass

      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • findVisibleAttributeMeaning

      public Meaning findVisibleAttributeMeaning(String ident)
      Description copied from class: DeclarationScope
      Find visible attribute's Meaning
      Overrides:
      findVisibleAttributeMeaning in class DeclarationScope
      Parameters:
      ident - attribute identifier
      Returns:
      the resulting Meaning
    • doJavaCoding

      public void doJavaCoding()
      Description copied from class: SyntaxClass
      Output Java code.
      Overrides:
      doJavaCoding in class SyntaxClass
    • edFormalParameterList

      private String edFormalParameterList(boolean isInlineMethod, boolean addStaticLink)
      Java Coding Utility: Edit the formal parameter list
      Parameters:
      isInlineMethod - true if generating an inline method, otherwise false
      addStaticLink - add static link as 0'th parameter
      Returns:
      the resulting Java code
    • doProcedureCoding

      private void doProcedureCoding()
      Generate java source code for this Procedure.
    • doCodeConstructor

      private void doCodeConstructor()
      Generate Java source code for the constructor.
    • doCodePrepareFormal

      private void doCodePrepareFormal()
      Generate Java source code prepared for 'call formal procedure'.
    • codeProcedureBody

      protected void codeProcedureBody()
      Coding Utility: codeProcedureBody. Redefined in SwitchDeclaration.
    • buildClassFile

      public byte[] buildClassFile()
      Description copied from class: DeclarationScope
      Build Class File
      Specified by:
      buildClassFile in class DeclarationScope
      Returns:
      Class File bytes
    • tryBuildClassFile

      private byte[] tryBuildClassFile(ClassDesc CD_ThisClass)
      Try to build classFile for this ProcedureDeclaration
      Parameters:
      CD_ThisClass - this class descriptor
      Returns:
      class file bytes
    • MTD_Constructor

      private MethodTypeDesc MTD_Constructor(boolean withParams)

      Create the MethodTypeDesc for the constructor.

      Example: (Lsimula/runtime/RTS_RTObject;IID)V

      Also used by PrefixedBlockDeclaration.

      Parameters:
      withParams - true: create MethodTypeDesc with parameters.
      Returns:
      the MethodTypeDesc for the constructor
    • getResultFieldRefEntry

      public FieldRefEntry getResultFieldRefEntry(ConstantPoolBuilder pool)
      ClassFile coding utility: getResultFieldRefEntry
      Parameters:
      pool - the ConstantPoolBuilder to use
      Returns:
      a FieldRefEntry
    • edConstructorSignature

      public String edConstructorSignature()
      Description copied from class: BlockDeclaration
      Edit the ConstructorSignature.
      Overrides:
      edConstructorSignature in class BlockDeclaration
      Returns:
      the ConstructorSignature String.
    • buildConstructor

      private void buildConstructor(MethodBuilder methodBuilder)

      Generate byteCode for the Constructor.

          public Program'name(RTS_RTObject staticLink, par, par ...) {
              super(staticLink);
      		   // Parameter assignment to locals
      		   BBLK();
      		   // Declaration Code
      		   _STM();
      	   }
      
      Parameters:
      methodBuilder - the MethodBuilder to use.
    • buildConstructor2

      private void buildConstructor2(MethodBuilder methodBuilder)

      Generate byteCode for the Constructor.

          public Program'name(RTS_RTObject staticLink, par, par ...) {
              super(staticLink);
      		   // Parameter assignment to locals
      		   BBLK();
      		   // Declaration Code
      		   _STM();
      	   }
      
         // Constructor in case of Formal/Virtual Procedure Call
         public adHoc000_PPP(RTS_RTObject _SL) {
             super(_SL,n); // Expecting n parameters
         }
      
      Parameters:
      methodBuilder - the MethodBuilder to use.
    • buildSetPar

      private void buildSetPar(MethodBuilder methodBuilder)

      Generate byteCode for the Constructor.

          public adHoc000_R setPar(Object param) {
             try {
                switch(_nParLeft--) {
                   case 1: p_SFD=procValue(param); break;
                   case 2: ... ...
                   default: throw new RTS_SimulaRuntimeError("Too many parameters");
                }
             } catch(ClassCastException e) {
                 throw new RTS_SimulaRuntimeError("Wrong type of parameter: "+param,e);
             }
             return(this);
          }
      
      Parameters:
      methodBuilder - the MethodBuilder to use.
    • build_SWITCH

      private void build_SWITCH(CodeBuilder.BlockCodeBuilder codeBuilder)
      ClassFile coding utility: Build switch
      Parameters:
      codeBuilder - the codeBuilder to use.
    • buildDeclaration

      public void buildDeclaration(ClassBuilder classBuilder, BlockDeclaration encloser)
      Description copied from class: Declaration
      Output Java ByteCode. Treat Declaration.
      Overrides:
      buildDeclaration in class Declaration
      Parameters:
      classBuilder - the classBuilder to use.
      encloser - the owning block.
    • buildInitAttribute

      public void buildInitAttribute(CodeBuilder codeBuilder)
      Description copied from class: Declaration
      Output Java ByteCode. Build init code for an Attribute.
      Overrides:
      buildInitAttribute in class Declaration
      Parameters:
      codeBuilder - the codeBuilder to use.
    • build_STM_BODY

      protected void build_STM_BODY(CodeBuilder codeBuilder, Label begScope, Label endScope)
      Generate byteCode for the '_STM' method.
      Overrides:
      build_STM_BODY in class BlockDeclaration
      Parameters:
      codeBuilder - the CodeBuilder
      begScope - label
      endScope - label
    • buildMethod_RESULT

      private void buildMethod_RESULT(CodeBuilder codeBuilder)
      Generate byteCode for the '_RESULT' method.
      Parameters:
      codeBuilder - the CodeBuilder
    • print

      public void print(int indent)
      Description copied from class: SyntaxClass
      Utility print method.
      Overrides:
      print in class SyntaxClass
      Parameters:
      indent - number of spaces leading the line
    • printTree

      public void printTree(int indent, Object head)
      Description copied from class: SyntaxClass
      Utility print syntax tree method.
      Overrides:
      printTree in class SyntaxClass
      Parameters:
      indent - number of spaces leading the lines
      head - the head of the tree.
    • toString

      public String toString()
      Overrides:
      toString in class BlockDeclaration
    • writeObject

      public void writeObject(AttributeOutputStream oupt) throws IOException
      Description copied from class: SyntaxClass
      Write a SyntaxClass object to a AttributeOutputStream.
      Overrides:
      writeObject in class SyntaxClass
      Parameters:
      oupt - the AttributeOutputStream to write to.
      Throws:
      IOException - if something went wrong.
    • readObject

      public static ProcedureDeclaration readObject(AttributeInputStream inpt) throws IOException
      Read and return an object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Returns:
      the object read from the stream.
      Throws:
      IOException - if something went wrong.