Class BlockDeclaration
- Direct Known Subclasses:
ClassDeclaration
,MaybeBlockDeclaration
,ProcedureDeclaration
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 Summary
FieldsModifier and TypeFieldDescriptionstatic BlockDeclaration
The DeclarationScope that currently is being builtboolean
If true; all member methods are independent of contextprotected boolean
If true; this is the outermost Subblock or Prefixed Block.The leading labels.static BlockDeclaration
Compiler state: Points to the BlockDeclaration whose Statements are being built.static Stack
<BlockDeclaration> Label Context Stackint
Last source line numberint
Number of Local Variables allocated so far.protected BlockDeclaration
The previous value of 'currentBlock'The statements belonging to this block.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
ConstructorsModifierConstructorDescriptionprotected
BlockDeclaration
(String identifier) Create a new BlockDeclaration with the given identifier.private
BlockDeclaration
(String identifier, int declarationKind) Create a new BlockDeclaration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLeadingLabel
(String labelcode) ClassFile coding utility: AD'HOC Leading Labelint
allocateLocalVariable
(Type type) Allocate slot for a local variable.protected void
build_STM_BODY
(CodeBuilder codeBuilder, Label begScope, Label endScope) ClassFile coding utility: Build byteCode for the '_STM' method.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.(package private) void
buildIsMethodDetachUsed
(CodeBuilder codeBuilder) Generate byteCode for the 'buildIsMethodDetachUsed' method.protected void
buildIsQPSystemBlock
(CodeBuilder codeBuilder) Generate byteCode for the 'isQPSystemBlock' method.protected void
buildMethod_STM
(CodeBuilder codeBuilder) Generate byteCode for the '_STM' method.(package private) void
buildMethodMain
(CodeBuilder codeBuilder) Generate byteCode for the 'main' method.protected void
ClassFile coding utility: Code Method Mainprotected void
ClassFile coding utility: Code statementsprotected void
ClassFile coding utility: Code STM bodystatic ClassDesc
Get current ClassDesc.Edit the ConstructorSignature.protected static void
expectFormalParameterPart
(Vector<Parameter> pList) Parse Utility: Expect formal-parameter-part and build the parameter list.Get the Constructors MethodTypeDesc.protected boolean
Returns true if this block has one ore more accumulated labels.protected boolean
Returns true if this block has one ore more local declared labels.protected boolean
Returns true if this block has local class(es).protected boolean
Returns true if this block is a QPS System block.protected BlockDeclaration
Returns the nearest Enclosing Block or null.protected void
printStatementList
(int indent) Debug utility: print StatementList.toString()
Methods inherited from class simula.compiler.syntaxClass.declaration.DeclarationScope
buildAndLoadOrAddClassFile, buildClassFile, buildCTX, buildCTX, buildCTX2, createJavaClassFile, doBuildClassFile, edCTX, edCTX, edJavaClassName, edScope, edScopeChain, findLabelMeaning, findMeaning, findProcedure, findVisibleAttributeMeaning, getBytesFromFile, getClassDesc, getRTBlockLevel, loadOrAddClassFile, modifyIdentifier, prefixLevel, prep, printDeclarationList, printStaticChain, scopeID
Methods inherited from class simula.compiler.syntaxClass.declaration.Declaration
acceptDeclaration, buildDeclaration, buildDeclarationCode, buildInitAttribute, checkAlreadyDefined, getFieldIdentifier, getJavaIdentifier, isCompatibleClasses, verifyTree
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, buildByteCode, doChecking, doDeclarationCoding, doJavaCoding, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, print, printTree, readObject, SET_SEMANTICS_CHECKED, setLineNumber, toJavaCode, writeObject
-
Field Details
-
isMainModule
protected boolean isMainModuleIf true; this is the outermost Subblock or Prefixed Block. -
statements
The statements belonging to this block. -
lastLineNumber
public int lastLineNumberLast source line number -
isContextFree
public boolean isContextFreeIf true; all member methods are independent of context -
labelContext
Compiler state: Points to the BlockDeclaration whose Statements are being built. Used by LabelList.labelBinding to find the right JUMP_TABLE. -
labelContextStack
Label Context Stack -
currentBlock
The DeclarationScope that currently is being built -
prevBlock
The previous value of 'currentBlock' -
nLocalVariables
public int nLocalVariablesNumber of Local Variables allocated so far.
Note: First Local Variable is used by the outermost try-catch block.
-
labelcodeList
-
-
Constructor Details
-
BlockDeclaration
Create a new BlockDeclaration with the given identifier.
Used by expectMaybeBlock, i.e. CompoundStatement, SubBlock or PrefixedBlock.
- Parameters:
identifier
- the given identifier
-
BlockDeclaration
Create a new BlockDeclaration.
This constructor is only used by ClassDeclaration. ProcedureDeclaration and MaybeBlockDeclaration.
- Parameters:
identifier
- the block identifierdeclarationKind
- the declaration kind
-
-
Method Details
-
currentClassDesc
-
allocateLocalVariable
Allocate slot for a local variable.- Parameters:
type
- variable's type.- Returns:
- slot for a local variable.
-
expectFormalParameterPart
-
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
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
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
Generate byteCode for the 'isQPSystemBlock' method.
public boolean isQPSystemBlock() { return(true); }
- Parameters:
codeBuilder
- the CodeBuilder
-
buildIsMethodDetachUsed
Generate byteCode for the 'buildIsMethodDetachUsed' method.
public boolean isDetachUsed() { return(true); }
- Parameters:
codeBuilder
- the CodeBuilder
-
edConstructorSignature
Edit the ConstructorSignature.- Returns:
- the ConstructorSignature String.
-
getConstructorMethodTypeDesc
Get the Constructors MethodTypeDesc.- Returns:
- the Constructors MethodTypeDesc.
-
buildMethod_STM
Generate byteCode for the '_STM' method.- Parameters:
codeBuilder
- the CodeBuilder
-
build_STM_BODY
ClassFile coding utility: Build byteCode for the '_STM' method.- Parameters:
codeBuilder
- the codeBuilder to use.begScope
- labelendScope
- label
-
build_TRY_CATCH
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
- labelendScope
- label
-
buildMethodMain
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
-