Class: CompoundStatement
compiler.CompoundStatement
Compound statement class, which represents a compound statement containing other items in the Kipper language and is compilable using translateCtxAndChildren.
Hierarchy
Statement<CompoundStatementSemantics,CompoundStatementTypeSemantics>↳
CompoundStatement
Implements
Table of contents
Constructors
Properties
- _antlrRuleCtx
- _children
- _errors
- _innerScope
- _parent
- _scopeCtx
- _semanticData
- _skippedSemanticAnalysis
- _skippedSemanticTypeChecking
- _skippedTargetSemanticAnalysis
- _typeSemantics
- checkForWarnings
- primarySemanticAnalysis
- primarySemanticTypeChecking
- targetCodeGenerator
- targetSemanticAnalysis
- kind
- ruleName
Accessors
- antlrRuleCtx
- children
- codeGenerator
- compileConfig
- errors
- hasFailed
- innerScope
- kind
- parent
- parser
- programCtx
- ruleName
- scope
- scopeCtx
- semanticAnalyser
- semanticData
- skippedSemanticAnalysis
- skippedSemanticTypeChecking
- sourceCode
- target
- tokenStream
- typeSemantics
Methods
- addError
- addNewChild
- ensureSemanticallyValid
- ensureTypeSemanticallyValid
- getAntlrRuleChildren
- getSemanticData
- getTypeSemanticData
- handleSemanticError
- hasSideEffects
- recursivelyCheckForWarnings
- semanticAnalysis
- semanticTypeChecking
- semanticallyAnalyseChildren
- semanticallyTypeCheckChildren
- targetSemanticallyAnalyseChildren
- translateCtxAndChildren
- wrapUpSemanticAnalysis
Constructors
constructor
• new CompoundStatement(antlrRuleCtx, parent)
Parameters
| Name | Type |
|---|---|
antlrRuleCtx |
CompoundStatementContext |
parent |
CompilableNodeParent |
Overrides
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:69
Properties
_antlrRuleCtx
• Readonly Private _antlrRuleCtx: CompoundStatementContext
The private field '_antlrRuleCtx' that actually stores the variable data, which is returned inside the this.antlrRuleCtx.
Implementation of
Overrides
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:27
_children
• Protected Readonly _children: Statement<StatementSemantics, StatementTypeSemantics>[]
Implementation of
Overrides
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:65
_errors
• Protected _errors: KipperError[]
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:44
_innerScope
• Private Readonly _innerScope: LocalScope
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:67
_parent
• Protected _parent: CompilableNodeParent
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:46
_scopeCtx
• Protected _scopeCtx: undefined | ScopeNode<LocalScope | FunctionScope> | KipperProgramContext
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:45
_semanticData
• Protected _semanticData: undefined | CompoundStatementSemantics
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/ast-node.ts:48
_skippedSemanticAnalysis
• Protected _skippedSemanticAnalysis: boolean
Implementation of
ScopeNode._skippedSemanticAnalysis
Inherited from
Statement._skippedSemanticAnalysis
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:45
_skippedSemanticTypeChecking
• Protected _skippedSemanticTypeChecking: boolean
Implementation of
ScopeNode._skippedSemanticTypeChecking
Inherited from
Statement._skippedSemanticTypeChecking
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:46
_skippedTargetSemanticAnalysis
• Protected _skippedTargetSemanticAnalysis: boolean
Implementation of
ScopeNode._skippedTargetSemanticAnalysis
Inherited from
Statement._skippedTargetSemanticAnalysis
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:47
_typeSemantics
• Protected _typeSemantics: undefined | CompoundStatementTypeSemantics
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/ast-node.ts:49
checkForWarnings
• checkForWarnings: undefined = undefined
Semantically analyses the code inside this AST node and checks for possible warnings or problematic code.
This will log all warnings using programCtx.logger and store them in warnings.
Since
0.9.0
Implementation of
Overrides
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:126
primarySemanticAnalysis
• primarySemanticAnalysis: undefined = undefined
Performs the semantic analysis for this Kipper token. This will log all warnings using programCtx.logger and throw errors if encountered.
This will not run in case that this.hasFailed is true, as that indicates that the semantic analysis of the children has already failed and as such no parent node should run type checking.
Implementation of
ScopeNode.primarySemanticAnalysis
Overrides
Statement.primarySemanticAnalysis
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:108
primarySemanticTypeChecking
• primarySemanticTypeChecking: undefined = undefined
Performs type checking for this AST Node. This will log all warnings using programCtx.logger and throw errors if encountered.
This will not run in case that this.hasFailed is true, as that indicates that the type checking of the children has already failed and as such no parent node should run type checking.
Since
0.7.0
Implementation of
ScopeNode.primarySemanticTypeChecking
Overrides
Statement.primarySemanticTypeChecking
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:118
targetCodeGenerator
• Readonly targetCodeGenerator: TargetASTNodeCodeGenerator<CompoundStatement, TranslatedCodeLine[]>
Code generator function that is specific for the target.
Since
0.10.0
Implementation of
Overrides
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:129
targetSemanticAnalysis
• Readonly targetSemanticAnalysis: undefined | TargetASTNodeSemanticAnalyser<CompoundStatement>
Semantic analyser function that is specific for the target.
This only should perform logical analysis and not interpret the code/modify the semanticData field.
Since
0.10.0
Implementation of
ScopeNode.targetSemanticAnalysis
Overrides
Statement.targetSemanticAnalysis
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:128
kind
▪ Static Readonly kind: 16
The static kind for this AST Node.
Since
0.11.0
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:33
ruleName
▪ Static Readonly ruleName: "RULE_compoundStatement"
The static rule name for this AST Node.
Since
0.11.0
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:51
Accessors
antlrRuleCtx
• get antlrRuleCtx(): CompoundStatementContext
The antlr context containing the antlr4 metadata for this statement.
Returns
Implementation of
ScopeNode.antlrRuleCtx
Overrides
Statement.antlrRuleCtx
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:88
children
• get children(): Statement<StatementSemantics, StatementTypeSemantics>[]
The children of this parse token.
Returns
Statement<StatementSemantics, StatementTypeSemantics>[]
Implementation of
ScopeNode.children
Overrides
Statement.children
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:81
codeGenerator
• get codeGenerator(): KipperTargetCodeGenerator
The code generator, which will generate the code for this specific token into the this.target target language.
Since
0.8.0
Returns
Implementation of
ScopeNode.codeGenerator
Inherited from
Statement.codeGenerator
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:122
compileConfig
• get compileConfig(): EvaluatedCompileConfig
The compilation config for the program of this AST node.
Since
0.10.0
Returns
Implementation of
ScopeNode.compileConfig
Inherited from
Statement.compileConfig
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:87
errors
• get errors(): KipperError[]
The errors that were caused by this node. Includes all errors from children.
Since
0.10.0
Returns
Implementation of
ScopeNode.errors
Inherited from
Statement.errors
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:95
hasFailed
• get hasFailed(): boolean
Returns true if the this.primarySemanticAnalysis semantic analysis or this.primarySemanticTypeChecking type checking of this node or any children nodes failed.
This indicates that the node is not valid and can not be translated.
Since
0.10.0
Returns
boolean
Implementation of
ScopeNode.hasFailed
Inherited from
Statement.hasFailed
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:118
innerScope
• get innerScope(): LocalScope
Returns the inner scope of this CompoundStatement, which is automatically created when using a compound statement.
Since
0.10.0
Returns
Implementation of
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:97
kind
• get kind(): 16
Returns the kind of this AST node. This represents the specific type of the antlrRuleCtx that this AST node wraps.
This may be compared using the rule fields, for example RULE_statement.
Since
0.10.0
Returns
16
Implementation of
ScopeNode.kind
Overrides
Statement.kind
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:43
parent
• get parent(): CompilableNodeParent
Returns the parent that has this node as a child.
Since
0.8.0
Returns
Implementation of
ScopeNode.parent
Inherited from
Statement.parent
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:59
parser
• get parser(): KipperParser
The parser that generated the parse tree and antlr rule context.
Since
0.8.0
Returns
Implementation of
ScopeNode.parser
Inherited from
Statement.parser
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:97
programCtx
• get programCtx(): KipperProgramContext
The file context instance containing the metadata for the listener and this AST node.
Since
0.8.0
Returns
Implementation of
ScopeNode.programCtx
Inherited from
Statement.programCtx
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:79
ruleName
• get ruleName(): "RULE_compoundStatement"
Returns the rule name of this AST Node. This represents the specific type of the antlrRuleCtx that this AST node wraps.
This may be compared using the rule fields, for example RULE_statement.
Since
0.11.0
Returns
"RULE_compoundStatement"
Implementation of
ScopeNode.ruleName
Overrides
Statement.ruleName
Defined in
kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts:61
scope
• get scope(): LocalScope | GlobalScope
The scope of this AST node.
Since
0.8.0
Returns
Implementation of
ScopeNode.scope
Inherited from
Statement.scope
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:130
scopeCtx
• get scopeCtx(): ScopeNode<LocalScope | FunctionScope> | KipperProgramContext
The context / AST node of the scope.
Since
0.8.0
Returns
ScopeNode<LocalScope | FunctionScope> | KipperProgramContext
Implementation of
ScopeNode.scopeCtx
Inherited from
Statement.scopeCtx
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:142
semanticAnalyser
• get semanticAnalyser(): KipperTargetSemanticAnalyser
The translation-specific semantic analyser, which will perform semantic analysis specific for the this.target target language.
Since
0.8.0
Returns
Implementation of
ScopeNode.semanticAnalyser
Inherited from
Statement.semanticAnalyser
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:164
semanticData
• get semanticData(): undefined | Semantics
Returns the semantic data of this AST node.
Since
0.8.0
Returns
undefined | Semantics
Implementation of
ScopeNode.semanticData
Inherited from
Statement.semanticData
Defined in
kipper/core/src/compiler/ast/ast-node.ts:78
• set semanticData(value): void
Sets the semantic data of this AST node.
Since
0.8.0
Parameters
| Name | Type | Description |
|---|---|---|
value |
undefined | Semantics |
The semantic data that should be written onto this AST node. |
Returns
void
Implementation of
ScopeNode.semanticData
Inherited from
Statement.semanticData
Defined in
kipper/core/src/compiler/ast/ast-node.ts:87
skippedSemanticAnalysis
• get skippedSemanticAnalysis(): boolean
Returns true if the this.primarySemanticAnalysis semantic analysis of this node was skipped, due to required semantic data being missing. This indicates that the node is impossible to analyse as the required semantic data from other nodes is missing.
Returns
boolean
Implementation of
ScopeNode.skippedSemanticAnalysis
Inherited from
Statement.skippedSemanticAnalysis
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:127
skippedSemanticTypeChecking
• get skippedSemanticTypeChecking(): boolean
Returns true if the this.primarySemanticTypeChecking type checking of this node was skipped, due to required semantic data being missing. This indicates that the node is impossible to type check as the required semantic data from other nodes is missing.
Since
0.10.0
Returns
boolean
Implementation of
ScopeNode.skippedSemanticTypeChecking
Inherited from
Statement.skippedSemanticTypeChecking
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:137
sourceCode
• get sourceCode(): string
The Kipper source code that was used to generate this CompilableASTNode.
Any left-over whitespaces will be removed using trim().
Since
0.8.0
Returns
string
Implementation of
ScopeNode.sourceCode
Inherited from
Statement.sourceCode
Defined in
kipper/core/src/compiler/ast/ast-node.ts:131
target
• get target(): KipperCompileTarget
The compilation translation for this specific token.
Since
0.8.0
Returns
Implementation of
ScopeNode.target
Inherited from
Statement.target
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:113
tokenStream
• get tokenStream(): TokenStream
Returns the token stream source for this token.
Since
0.8.0
Returns
TokenStream
Implementation of
ScopeNode.tokenStream
Inherited from
Statement.tokenStream
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:105
typeSemantics
• get typeSemantics(): undefined | TypeSemantics
Returns the type data of this AST node.
Since
0.10.0
Returns
undefined | TypeSemantics
Implementation of
ScopeNode.typeSemantics
Inherited from
Statement.typeSemantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:95
• set typeSemantics(value): void
Sets the type data of this AST node.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
value |
undefined | TypeSemantics |
The semantic data that should be written onto this AST node. |
Returns
void
Implementation of
ScopeNode.typeSemantics
Inherited from
Statement.typeSemantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:104
Methods
addError
▸ addError(error): void
Adds the specified error to the list of errors caused by this node.
This is not the same as reportError, since that function automatically logs the error as well and this function does not! This is only intended to keep track if a node has failed.
Parameters
| Name | Type | Description |
|---|---|---|
error |
KipperError |
The error to add. |
Returns
void
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:106
addNewChild
▸ addNewChild(newChild): void
Adds new child ctx item to this AST node. The child item should be in the order that they appeared in the this.antlrCtx parse tree.
This will also automatically set the parent of newChild to this instance.
Since
0.8.0
Parameters
| Name | Type |
|---|---|
newChild |
CompilableNodeChild |
Returns
void
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:78
ensureSemanticallyValid
▸ Protected ensureSemanticallyValid(): void
Ensures that this node successfully passed the semantic analysis. This will be primarily used by statements and declarations, which depend on other nodes to be semantically valid.
This is done by checking if the hasFailed property is set to true and if the semanticData property is undefined. If both of these conditions are met, then the node failed in an intended way and the parent should not continue processing, as it will cause errors.
This is used to help the control flow and also to ensure that other nodes do not try to access the semantic data of a node that failed, as that would cause an UndefinedSemanticsError.
Intentionally this will also likely cause an UndefinedSemanticsError in case the semantic data is missing and hasFailed is returning false. Since that's an automatic contradiction, it's better to ignore it here and let the UndefinedSemanticsError be thrown later.
Throws
If the child failed and the semantic data is undefined. Note that this is not like UndefinedSemanticsError, as that error is thrown when the semantic data is undefined in an unintended or unexpected way. This error on the other will be handled by the compiler and influence the control flow.
Since
0.10.0
Returns
void
Implementation of
ScopeNode.ensureSemanticallyValid
Inherited from
Statement.ensureSemanticallyValid
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:171
ensureTypeSemanticallyValid
▸ Protected ensureTypeSemanticallyValid(): void
Ensures that this node successfully passed the type checking step of semantic analysis. This will be primarily used by statements and declarations, which depend on other nodes to be semantically valid.
This is done by checking if the hasFailed property is set to true and if the typeSemantics property is undefined. If both of these conditions are met, then the child failed in an intended way and the parent should not continue processing, as it will cause errors.
This is used to help the control flow and also to ensure that the parent node does not try to access the type semantic data of a child node that has failed.
Intentionally this will also likely cause an UndefinedSemanticsError in case the semantic data is missing and hasFailed is returning false. Since that's an automatic contradiction, it's better to ignore it here and let the UndefinedSemanticsError be thrown later.
Throws
If the child failed and the semantic data is undefined. Note that this is not like UndefinedSemanticsError, as that error is thrown when the semantic data is undefined in an unintended or unexpected way. This error on the other will be handled by the compiler and influence the control flow.
Since
0.10.0
Returns
void
Implementation of
ScopeNode.ensureTypeSemanticallyValid
Inherited from
Statement.ensureTypeSemanticallyValid
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:198
getAntlrRuleChildren
▸ getAntlrRuleChildren(): ParseTree[]
Returns the children of the antlrRuleCtx and throws an error in case they are undefined.
Throws
If antlrRuleCtx.children is undefined.
Since
0.8.0
Returns
ParseTree[]
Implementation of
ScopeNode.getAntlrRuleChildren
Inherited from
Statement.getAntlrRuleChildren
Defined in
kipper/core/src/compiler/ast/ast-node.ts:159
getSemanticData
▸ getSemanticData(): CompoundStatementSemantics
Returns the semantic data of this AST node and throws an error in case it is undefined.
Throws
If semanticData is undefined.
Since
0.8.0
Returns
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/ast-node.ts:172
getTypeSemanticData
▸ getTypeSemanticData(): CompoundStatementTypeSemantics
Returns the type semantic data of this AST node and throws an error in case it is undefined.
Throws
UndefinedSemanticsError If semanticData is undefined.
Since
0.10.0
Returns
CompoundStatementTypeSemantics
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/ast-node.ts:185
handleSemanticError
▸ Protected handleSemanticError(error): void
Handles the specified error that occurred during the semantic analysis of this node in a standardised way.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
error |
KipperError | Error |
The error to handle. |
Returns
void
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:146
hasSideEffects
▸ hasSideEffects(): boolean
Returns whether this AST node has any side effects. This means that the node will change the state of the program in some way and not only return a value.
This specifically can mean it assigns or modifies a variable, calls a function, or throws an error.
Since
0.11.0
Returns
boolean
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/compilable-ast-node.ts:89
recursivelyCheckForWarnings
▸ recursivelyCheckForWarnings(): Promise<void>
Recursively checks for warnings by calling this function on all this.children children and calling checkForWarnings on this class as well.
Since
0.10.0
Returns
Promise<void>
Implementation of
ScopeNode.recursivelyCheckForWarnings
Inherited from
Statement.recursivelyCheckForWarnings
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:338
semanticAnalysis
▸ semanticAnalysis(): Promise<void>
Semantically analyses the code inside this AST node and all this.children children nodes.
This function will recursively call itself on the this.children instances and analyse the deepest children nodes first, working up as the tokens get more complex. This way the parent tokens can access the semantics of the children and properly process itself.
This function will set the this.semanticData property and allow the use of this.getSemanticData, without getting any error.
Since
0.8.0
Returns
Promise<void>
Implementation of
Inherited from
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:230
semanticTypeChecking
▸ semanticTypeChecking(): Promise<void>
Performs type checking on this AST node and all this.children children nodes. This uses the this.semanticData semantic data that was evaluated during this.semanticAnalysis semantic analysis.
Since
0.10.0
Returns
Promise<void>
Implementation of
ScopeNode.semanticTypeChecking
Inherited from
Statement.semanticTypeChecking
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:269
semanticallyAnalyseChildren
▸ Protected semanticallyAnalyseChildren(): Promise<void>
Runs semanticAnalysis of all children nodes.
Since
0.10.0
Returns
Promise<void>
Implementation of
ScopeNode.semanticallyAnalyseChildren
Inherited from
Statement.semanticallyAnalyseChildren
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:209
semanticallyTypeCheckChildren
▸ Protected semanticallyTypeCheckChildren(): Promise<void>
Runs semanticTypeChecking of all children nodes.
Since
0.10.0
Returns
Promise<void>
Implementation of
ScopeNode.semanticallyTypeCheckChildren
Inherited from
Statement.semanticallyTypeCheckChildren
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:254
targetSemanticallyAnalyseChildren
▸ Protected targetSemanticallyAnalyseChildren(): Promise<void>
Runs semanticTypeChecking of all children nodes.
Since
0.10.0
Returns
Promise<void>
Implementation of
ScopeNode.targetSemanticallyAnalyseChildren
Inherited from
Statement.targetSemanticallyAnalyseChildren
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:295
translateCtxAndChildren
▸ translateCtxAndChildren(): Promise<TranslatedCodeLine[]>
Generates the typescript code for this item, and all children (if they exist).
Every item in the array represents a single line of code.
Returns
Implementation of
ScopeNode.translateCtxAndChildren
Inherited from
Statement.translateCtxAndChildren
Defined in
kipper/core/src/compiler/ast/nodes/statements/statement.ts:71
wrapUpSemanticAnalysis
▸ wrapUpSemanticAnalysis(): Promise<void>
Wrap-up semantic analysis, which analyses this AST node and all this.children children nodes, and checks whether they are semantically valid for the this.target target language. This uses the this.semanticData semantic data and this.typeData type data that was evaluated during the previous this.semanticAnalysis semantic analysis and this.semanticTypeChecking type checking steps.
Since
0.10.0
Returns
Promise<void>
Implementation of
ScopeNode.wrapUpSemanticAnalysis
Inherited from
Statement.wrapUpSemanticAnalysis
Defined in
kipper/core/src/compiler/ast/analysable-ast-node.ts:312