Class ProcedureDeclaration
- Direct Known Subclasses:
StandardProcedure
,SwitchDeclaration
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 Summary
FieldsModifier and TypeFieldDescriptionVirtual Match indicator.Parameter list.Result in case of Type ProcedureFields inherited from class simula.compiler.syntaxClass.declaration.BlockDeclaration
currentBlock, isContextFree, isMainModule, labelcodeList, labelContext, labelContextStack, lastLineNumber, nLocalVariables, prevBlock, statements
Fields inherited from class simula.compiler.syntaxClass.declaration.DeclarationScope
CLASSFILE_ALREADY_GENERATED, declarationList, hasLocalClasses, isPreCompiledFromFile, labelList, sourceBlockLevel, sourceFileName
Fields inherited from class simula.compiler.syntaxClass.declaration.Declaration
declarationKind, declaredIn, externalIdent, identifier, isProtected, type
Fields inherited from class simula.compiler.syntaxClass.SyntaxClass
CHECKED, lineNumber, OBJECT_SEQU
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault constructor used by Attribute File I/Oprotected
ProcedureDeclaration
(String identifier, int declarationKind) Create a new ProcedureDeclaration. -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
acceptModePart
(Vector<Parameter> pList) Parse Utility: Accept mode-part and set matching parameter's mode.protected void
build_STM_BODY
(CodeBuilder codeBuilder, Label begScope, Label endScope) Generate byteCode for the '_STM' method.private void
build_SWITCH
(CodeBuilder.BlockCodeBuilder codeBuilder) ClassFile coding utility: Build switchbyte[]
Build Class Fileprivate void
buildConstructor
(MethodBuilder methodBuilder) Generate byteCode for the Constructor.private void
buildConstructor2
(MethodBuilder methodBuilder) Generate byteCode for the Constructor.void
buildDeclaration
(ClassBuilder classBuilder, BlockDeclaration encloser) Output Java ByteCode.void
buildInitAttribute
(CodeBuilder codeBuilder) Output Java ByteCode.private void
buildMethod_RESULT
(CodeBuilder codeBuilder) Generate byteCode for the '_RESULT' method.private void
buildSetPar
(MethodBuilder methodBuilder) Generate byteCode for the Constructor.protected void
Coding Utility: codeProcedureBody.void
Perform semantic checking.private void
Generate Java source code for the constructor.private void
Generate Java source code prepared for 'call formal procedure'.void
Output Java code.private void
Generate java source code for this Procedure.Edit the ConstructorSignature.private String
edFormalParameterList
(boolean isInlineMethod, boolean addStaticLink) Java Coding Utility: Edit the formal parameter listprivate static void
Parse Utility: Expect procedure-body.static ProcedureDeclaration
Parse and build a ProcedureDeclaration.private static void
Parse Utility: Accept Procedure Parameter specification-part updating Parameter's type and kind.Find visible attribute's MeaningClassFile coding utility: getResultFieldRefEntryprivate MethodTypeDesc
MTD_Constructor
(boolean withParams) Create the MethodTypeDesc for the constructor.void
print
(int indent) Utility print method.void
Utility print syntax tree method.static ProcedureDeclaration
Read and return an object.toString()
private byte[]
tryBuildClassFile
(ClassDesc CD_ThisClass) Try to build classFile for this ProcedureDeclarationvoid
Write a SyntaxClass object to a AttributeOutputStream.Methods inherited from class simula.compiler.syntaxClass.declaration.BlockDeclaration
addLeadingLabel, allocateLocalVariable, build_TRY_CATCH, buildIsMethodDetachUsed, buildIsQPSystemBlock, buildMethod_STM, buildMethodMain, codeMethodMain, codeStatements, codeSTMBody, currentClassDesc, expectFormalParameterPart, getConstructorMethodTypeDesc, hasAccumLabel, hasDeclaredLabel, isBlockWithLocalClasses, isQPSystemBlock, nearestEnclosingBlock, printStatementList
Methods inherited from class simula.compiler.syntaxClass.declaration.DeclarationScope
buildAndLoadOrAddClassFile, buildCTX, buildCTX, buildCTX2, createJavaClassFile, doBuildClassFile, edCTX, edCTX, edJavaClassName, edScope, edScopeChain, findLabelMeaning, findMeaning, findProcedure, getBytesFromFile, getClassDesc, getRTBlockLevel, loadOrAddClassFile, modifyIdentifier, prefixLevel, prep, printDeclarationList, printStaticChain, scopeID
Methods inherited from class simula.compiler.syntaxClass.declaration.Declaration
acceptDeclaration, buildDeclarationCode, checkAlreadyDefined, getFieldIdentifier, getJavaIdentifier, isCompatibleClasses, verifyTree
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, buildByteCode, doDeclarationCoding, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, SET_SEMANTICS_CHECKED, setLineNumber, toJavaCode
-
Field Details
-
result
Result in case of Type Procedure -
parameterList
Parameter list. -
myVirtual
Virtual Match indicator.
If myVirtual != null, this Procedure is a Virtual Match.
Set during doChecking.
-
-
Constructor Details
-
ProcedureDeclaration
Create a new ProcedureDeclaration.- Parameters:
identifier
- procedure identifierdeclarationKind
- procedure or switch
-
ProcedureDeclaration
public ProcedureDeclaration()Default constructor used by Attribute File I/O
-
-
Method Details
-
expectProcedureDeclaration
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
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
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
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 classSyntaxClass
-
findVisibleAttributeMeaning
Description copied from class:DeclarationScope
Find visible attribute's Meaning- Overrides:
findVisibleAttributeMeaning
in classDeclarationScope
- Parameters:
ident
- attribute identifier- Returns:
- the resulting Meaning
-
doJavaCoding
public void doJavaCoding()Description copied from class:SyntaxClass
Output Java code.- Overrides:
doJavaCoding
in classSyntaxClass
-
edFormalParameterList
Java Coding Utility: Edit the formal parameter list- Parameters:
isInlineMethod
- true if generating an inline method, otherwise falseaddStaticLink
- 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 classDeclarationScope
- Returns:
- Class File bytes
-
tryBuildClassFile
Try to build classFile for this ProcedureDeclaration- Parameters:
CD_ThisClass
- this class descriptor- Returns:
- class file bytes
-
MTD_Constructor
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
ClassFile coding utility: getResultFieldRefEntry- Parameters:
pool
- the ConstantPoolBuilder to use- Returns:
- a FieldRefEntry
-
edConstructorSignature
Description copied from class:BlockDeclaration
Edit the ConstructorSignature.- Overrides:
edConstructorSignature
in classBlockDeclaration
- Returns:
- the ConstructorSignature String.
-
buildConstructor
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
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
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
ClassFile coding utility: Build switch- Parameters:
codeBuilder
- the codeBuilder to use.
-
buildDeclaration
Description copied from class:Declaration
Output Java ByteCode. Treat Declaration.- Overrides:
buildDeclaration
in classDeclaration
- Parameters:
classBuilder
- the classBuilder to use.encloser
- the owning block.
-
buildInitAttribute
Description copied from class:Declaration
Output Java ByteCode. Build init code for an Attribute.- Overrides:
buildInitAttribute
in classDeclaration
- Parameters:
codeBuilder
- the codeBuilder to use.
-
build_STM_BODY
Generate byteCode for the '_STM' method.- Overrides:
build_STM_BODY
in classBlockDeclaration
- Parameters:
codeBuilder
- the CodeBuilderbegScope
- labelendScope
- label
-
buildMethod_RESULT
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 classSyntaxClass
- Parameters:
indent
- number of spaces leading the line
-
printTree
Description copied from class:SyntaxClass
Utility print syntax tree method.- Overrides:
printTree
in classSyntaxClass
- Parameters:
indent
- number of spaces leading the lineshead
- the head of the tree.
-
toString
- Overrides:
toString
in classBlockDeclaration
-
writeObject
Description copied from class:SyntaxClass
Write a SyntaxClass object to a AttributeOutputStream.- Overrides:
writeObject
in classSyntaxClass
- Parameters:
oupt
- the AttributeOutputStream to write to.- Throws:
IOException
- if something went wrong.
-
readObject
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.
-