Class ClassDeclaration

Direct Known Subclasses:
PrefixedBlockDeclaration, StandardClass

public class ClassDeclaration extends BlockDeclaration

Simula Class Declaration.


Simula Standard: 5.5 Class declaration

class-declaration = [ prefix ] main-part

  prefix = class-identifier

  main-part = CLASS class-identifier
              [ formal-parameter-part ; [ value-part ] specification-part ] ;
              [ protection-part ; ]
              [ virtual-part ; ]
              class-body
  
     class-identifier = identifier

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

     value-part = VALUE identifier-list

     specification-part = class-parameter-specifier  identifier-list ; { class-parameter-specifier  identifier-list ; }
              class-parameter-specifier = Type | [Type] ARRAY 

     protection-part = protection-specification { ; protection-specification }
              protection-specification = HIDDEN identifier-list | HIDDEN PROTECTED identifier-list
                                       | PROTECTED identifier-list | PROTECTED HIDDEN identifier-list

     virtual-part = VIRTUAL: virtual-spec ; { virtual-spec ; }
        virtual-spec
            = virtual-specifier identifier-list
            | PROCEDURE procedure-identifier  procedure-specification
            
               virtual-Specifier = [ type ] PROCEDURE | LABEL | SWITCH
               
               procedure-specification = IS procedure-declaration

     
     class-body = statement | split-body
     
        split-body = initial-operations inner-part final-operations
        
           initial-operations = ( BEGIN | block-head ; ) { statement ; }
        
           inner-part = [ label : ] INNER ;

           final-operations
              = END
              | ; statement { ; statement } END

This class is prefix to StandardClass and PrefixedBlockDeclaration.

Link to GitHub: Source File.

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

    • parameterList

      ObjectList<Parameter> parameterList
      The parameter list.
    • virtualSpecList

      protected ObjectList<VirtualSpecification> virtualSpecList
      The virtual spec list.
    • virtualMatchList

      protected Vector<VirtualMatch> virtualMatchList
      The virtual match list.
    • protectedList

      The protected list.
    • hiddenList

      public ObjectList<HiddenSpecification> hiddenList
      The hidden list.
    • statements1

      public ObjectList<Statement> statements1
      Possible statements before inner. If this is non-null then 'statements' contains the statements after inner
    • prefix

      public String prefix
      Class Prefix in case of a SubClass or Prefixed Block.
    • prefixClass

      public ClassDeclaration prefixClass
      Class Prefix in case of a SubClass or Prefixed Block. Set by coChecking
    • detachUsed

      public boolean detachUsed
      Set true when attribute procedure 'detach' is used in/on this class.
    • isLoaded

      private boolean isLoaded
      Indicates if this class is loaded.
  • Constructor Details

    • ClassDeclaration

      protected ClassDeclaration(String identifier)
      Create a new ClassDeclaration.
      Parameters:
      identifier - the given identifier
  • Method Details

    • expectClassDeclaration

      public static ClassDeclaration expectClassDeclaration(String prefix)

      Parse Class Declaration.

      
      Syntax:
      
      class-declaration = [ prefix ] main-part
      
        prefix = class-identifier
      
        main-part = CLASS class-identifier
                    [ formal-parameter-part ; [ value-part ] specification-part ] ;
                    [ protection-part ; ]
                    [ virtual-part ; ]
                    class-body
      
      
      Parameters:
      prefix - class identifier
      Returns:
      the resulting ClassDeclaration
    • acceptValuePart

      private static void acceptValuePart(Vector<Parameter> pList)

      Parse utility: Accept value part and set matching parameter's mode.

      Syntax:
                   VALUE identifier-list ;
      
      Parameters:
      pList - Parameter list
    • acceptParameterSpecificationPart

      private static void acceptParameterSpecificationPart(Vector<Parameter> pList)

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

      Syntax:
      
          specification-part
                = class-parameter-specifier identifier-list { ; class-parameter-specifier identifier-list }
          
             class-parameter-specifier = Type | [Type] ARRAY
      
      Parameters:
      pList - the parameter list
    • acceptProtectionPart

      private static void acceptProtectionPart(ClassDeclaration cls)

      Parse Utility: Accept protection-part updating Hidden and Protected lists.

      Syntax:
      
           protection-part = protection-specification { ; protection-specification }
           
                protection-specification
                     = HIDDEN identifier-list
                     | HIDDEN PROTECTED identifier-list
                     | PROTECTED identifier-list
                     | PROTECTED HIDDEN identifier-list
      
      Parameters:
      cls - the ClassDeclaration
    • expectHiddenProtectedList

      private static void expectHiddenProtectedList(ClassDeclaration cls, boolean hidden, boolean prtected)

      Parse Utility: Expect Hidden Protected list.

      Syntax:
      
           identifier-list
      
      Parameters:
      cls - the ClassDeclaration
      hidden - if true, update the hidden list
      prtected - if true, update the protected list
    • expectClassBody

      private static void expectClassBody(ClassDeclaration cls)

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

      Syntax:
                     
           class-body = statement | split-body
           
              split-body = initial-operations inner-part final-operations
              
                 initial-operations = ( BEGIN | block-head ; ) { statement ; }
              
                 inner-part = [ label : ] INNER ;
      
                 final-operations
                    = END
                    | ; statement { ; statement } END
      
      Parameters:
      cls - the ClassDeclaration
    • isSubClassOf

      public boolean isSubClassOf(ClassDeclaration other)

      Checks if this class is a subclass of the 'other' class.

      Consider the class definitions:

       
           Class A ......;
         A Class B ......;
         B Class C ......;
      

      Then Class B is a subclass of Class A, While Class C is subclass of both B and A.

      Parameters:
      other - the other ClassDeclaration
      Returns:
      Boolean true iff this class is a subclass of the 'other' class.
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass

      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • checkHiddenList

      private void checkHiddenList()
      Perform sematic checking of the Hidden list.
    • checkProtectedList

      private void checkProtectedList()
      Perform sematic checking of the Protected list.
    • searchVirtualSpecList

      public VirtualSpecification searchVirtualSpecList(String ident)
      Utility: Search VirtualSpec-list for 'ident'
      Parameters:
      ident - argument
      Returns:
      a VirtualSpecification when it was found, otherwise null
    • prefixLevel

      public int prefixLevel()
      Returns the prefix level.
      Overrides:
      prefixLevel in class DeclarationScope
      Returns:
      the prefix level
    • findLocalAttribute

      public Declaration findLocalAttribute(String ident)
      Utility: Search for an attribute named 'ident'
      Parameters:
      ident - argument
      Returns:
      a ProcedureDeclaration when it was found, otherwise null
    • findLocalProcedure

      ProcedureDeclaration findLocalProcedure(String ident)
      Utility: Search Declaration-list for a procedure named 'ident'
      Parameters:
      ident - argument
      Returns:
      a ProcedureDeclaration when it was found, otherwise null
    • findRemoteAttributeMeaning

      public Meaning findRemoteAttributeMeaning(String ident)
      Find Remote Attribute's Meaning.
      Parameters:
      ident - attribute identifier
      Returns:
      the resulting Meaning
    • searchProtectedList

      public ProtectedSpecification searchProtectedList(String ident)
      Utility: Search Protected-list for 'ident'
      Parameters:
      ident - argument
      Returns:
      a ProtectedSpecification when it was found, otherwise null
    • withinScope

      private static boolean withinScope(DeclarationScope otherScope)
      Checks if the other scope is this scope or any of the prefixes.
      Parameters:
      otherScope - the other scope
      Returns:
      true if the other scope is this scope or any of the prefixes
    • 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
    • searchHiddenList

      HiddenSpecification searchHiddenList(String ident)
      Utility: Search Hidden-list for 'ident'
      Parameters:
      ident - argument
      Returns:
      a HiddenSpecification when it was found, otherwise null
    • getPrefixClass

      public ClassDeclaration getPrefixClass()
      Returns the prefix ClassDeclaration or null.
      Returns:
      the prefix ClassDeclaration or null
    • hasRealPrefix

      boolean hasRealPrefix()
      Check if this class has a real prefix.
      Returns:
      true if this class has a real prefix, otherwise false.
    • isDetachUsed

      public boolean isDetachUsed()
      Returns true if detach is called in/on this class.
      Returns:
      true if detach is called in/on this class
    • parameterIterator

      public Iterator<Parameter> parameterIterator()
      Iterates through all class parameters.
      Returns:
      a ClassParameterIterator
    • doJavaCoding

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

      private void doCodeConstructor()
      Java Coding Utility: Code the constructor.
    • edFormalParameterList

      protected String edFormalParameterList()

      Edit the formal parameter list

      Also used by subclass PrefixedBlockDeclaration.

      Returns:
      the resulting Java code
    • codeStatements

      public void codeStatements()
      Description copied from class: BlockDeclaration
      ClassFile coding utility: Code statements
      Overrides:
      codeStatements in class BlockDeclaration
    • codeStatementsBeforeInner

      private void codeStatementsBeforeInner()
      Java coding utility: codeStatementsBeforeInner
    • codeStatementsAfterInner

      private void codeStatementsAfterInner()
      Java coding utility: codeStatementsAfterInner
    • codeClassStatements

      protected void codeClassStatements()
      Java coding utility: Code class statements.
    • edCompleteParameterList

      protected String edCompleteParameterList()
      Coding Utility: Edit the complete parameter list including all prefixes.
      Returns:
      the resulting Java code
    • superClassDesc

      public ClassDesc superClassDesc()
      Get super class ClassDesc.
      Returns:
      super class ClassDesc.
    • buildAndLoadOrAddClassFile

      protected void buildAndLoadOrAddClassFile() throws IOException
      Defined in DeclarationScope - Redefined in ClassDeclaration
      Overrides:
      buildAndLoadOrAddClassFile in class DeclarationScope
      Throws:
      IOException - if something went wrong.
    • 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, ClassDesc CD_SuperClass)
      Try to build classFile for this ClassDeclaration
      Parameters:
      CD_ThisClass - this class descriptor
      CD_SuperClass - super class descriprot
      Returns:
      class file bytes
    • edConstructorSignature

      public String edConstructorSignature()

      Edit the constructor signature.

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

      Also used by PrefixedBlockDeclaration.

      Overrides:
      edConstructorSignature in class BlockDeclaration
      Returns:
      the MethodTypeDesc for the constructor
    • buildConstructor

      protected void buildConstructor(CodeBuilder codeBuilder)

      Generate byteCode for the Constructor.

          public Program'name(RTS_RTObject staticLink, par, par ...) {
              super(staticLink);
      		   // Parameter assignment to locals
      		   BBLK();
      		   // Declaration Code
      		   _STM();
      	   }
      

      Also used by PrefixedBlockDeclaration

      Parameters:
      codeBuilder - the CodeBuilder
    • 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
    • clearLabelList

      private void clearLabelList()
      Clear the LabelList.
    • buildMethod_CatchingErrors_TRY_CATCH

      private void buildMethod_CatchingErrors_TRY_CATCH(CodeBuilder codeBuilder, Label begScope, Label endScope)
      Generate byteCode for the 'CatchingErrors_TRY_CATCH' method.
      Parameters:
      codeBuilder - the CodeBuilder
      begScope - label
      endScope - label
    • buildStatementsBeforeInner

      private void buildStatementsBeforeInner(CodeBuilder codeBuilder)
      ClassFile coding utility: buildStatementsBeforeInner
      Parameters:
      codeBuilder - the codeBuilder to use.
    • buildStatementsAfterInner

      private void buildStatementsAfterInner(CodeBuilder codeBuilder)
      ClassFile coding utility: buildStatementsAfterInner
      Parameters:
      codeBuilder - the codeBuilder to use.
    • 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 ClassDeclaration readObject(AttributeInputStream inpt) throws IOException
      Read and return a ClassDeclaration object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Returns:
      the object read from the stream.
      Throws:
      IOException - if something went wrong.