Oops that shouldn't have happened! Please enable Java-Script to use our site!
  • Class: AnalysableASTNode<Semantics, TypeSemantics>

    compiler.AnalysableASTNode

    A basic implementation of an AST node that can be semantically analysed and has a pre-defined behaviour for processing the AST. This class is intended to be extended by other AST nodes, more specifically CompilableASTNode.

    Since

    0.10.0

    Type parameters

    Name Type
    Semantics extends SemanticData = SemanticData
    TypeSemantics extends TypeData = TypeData

    Hierarchy

    Implements

    Table of contents

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    constructor

    Protected new AnalysableASTNode<Semantics, TypeSemantics>(antlrCtx, parent)

    Type parameters

    Name Type
    Semantics extends SemanticData = SemanticData
    TypeSemantics extends TypeData = TypeData

    Parameters

    Name Type
    antlrCtx KipperParserRuleContext
    parent AnalysableNodeParent

    Overrides

    ParserASTNode.constructor

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:49

    Properties

    _antlrRuleCtx

    Protected Readonly _antlrRuleCtx: KipperParserRuleContext

    Inherited from

    ParserASTNode._antlrRuleCtx

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:45


    _children

    Protected _children: AnalysableNodeChild[]

    Overrides

    ParserASTNode._children

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:42


    _errors

    Protected _errors: KipperError[]

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:44


    _parent

    Protected _parent: AnalysableNodeParent

    Overrides

    ParserASTNode._parent

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:43


    _semanticData

    Protected _semanticData: undefined | Semantics

    Inherited from

    ParserASTNode._semanticData

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:48


    _skippedSemanticAnalysis

    Protected _skippedSemanticAnalysis: boolean

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:45


    _skippedSemanticTypeChecking

    Protected _skippedSemanticTypeChecking: boolean

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:46


    _skippedTargetSemanticAnalysis

    Protected _skippedTargetSemanticAnalysis: boolean

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:47


    _typeSemantics

    Protected _typeSemantics: undefined | TypeSemantics

    Inherited from

    ParserASTNode._typeSemantics

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:49


    targetSemanticAnalysis

    Readonly Abstract targetSemanticAnalysis: undefined | TargetASTNodeSemanticAnalyser<any>

    Semantic analyser function that is specific for the target. This only should perform logical analysis and not interpret the code/modify the semanticData field.

    If this is undefined then it means there is no target specific semantic analysis that needs to be done.

    Since

    0.8.0

    Implementation of

    TargetAnalysableNode.targetSemanticAnalysis

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:378

    Accessors

    antlrRuleCtx

    get antlrRuleCtx(): KipperParserRuleContext

    The antlr rule context containing the antlr4 metadata for this AST node.

    Since

    0.8.0

    Returns

    KipperParserRuleContext

    Inherited from

    ParserASTNode.antlrRuleCtx

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:112


    children

    get children(): AnalysableNodeChild[]

    The children of this AST node.

    Since

    0.8.0

    Returns

    AnalysableNodeChild[]

    Overrides

    ParserASTNode.children

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:71


    compileConfig

    get compileConfig(): EvaluatedCompileConfig

    The compilation config for the program of this AST node.

    Since

    0.10.0

    Returns

    EvaluatedCompileConfig

    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

    KipperError[]

    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

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:118


    kind

    Abstract get kind(): number

    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 KipperParser rule fields, for example RULE_expression.

    Since

    0.10.0

    Returns

    number

    Inherited from

    ParserASTNode.kind

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:58


    parent

    get parent(): AnalysableNodeParent

    Returns the parent that has this node as a child.

    Since

    0.8.0

    Returns

    AnalysableNodeParent

    Overrides

    ParserASTNode.parent

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:63


    programCtx

    get programCtx(): KipperProgramContext

    The file context instance containing the metadata for the listener and this AST node.

    Since

    0.8.0

    Returns

    KipperProgramContext

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:79


    ruleName

    Abstract get ruleName(): string

    Returns the identifier of this AST node. This is a unique identifier that can be used to differentiate this AST node from other AST nodes.

    Since

    0.11.0

    Returns

    string

    Inherited from

    ParserASTNode.ruleName

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:65


    semanticData

    get semanticData(): undefined | Semantics

    Returns the semantic data of this AST node.

    Since

    0.8.0

    Returns

    undefined | Semantics

    Inherited from

    ParserASTNode.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

    Inherited from

    ParserASTNode.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

    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

    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

    Inherited from

    ParserASTNode.sourceCode

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:131


    typeSemantics

    get typeSemantics(): undefined | TypeSemantics

    Returns the type data of this AST node.

    Since

    0.10.0

    Returns

    undefined | TypeSemantics

    Inherited from

    ParserASTNode.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

    Inherited from

    ParserASTNode.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

    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 ParserASTNode<any, any>

    Returns

    void

    Inherited from

    ParserASTNode.addNewChild

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:150


    checkForWarnings

    Protected Optional Abstract checkForWarnings(): Promise<void>

    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.

    If this is undefined then it means there is no warning checks that needs to be done.

    Since

    0.9.0

    Returns

    Promise<void>

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:376


    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

    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

    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[]

    Inherited from

    ParserASTNode.getAntlrRuleChildren

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:159


    getSemanticData

    getSemanticData(): Semantics

    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

    Semantics

    Inherited from

    ParserASTNode.getSemanticData

    Defined in

    kipper/core/src/compiler/ast/ast-node.ts:172


    getTypeSemanticData

    getTypeSemanticData(): TypeSemantics

    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

    TypeSemantics

    Inherited from

    ParserASTNode.getTypeSemanticData

    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

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:146


    primarySemanticAnalysis

    Protected Optional Abstract primarySemanticAnalysis(): Promise<void>

    Semantically analyses the code inside this AST node.

    If this is undefined then it means there is no semantic analysis that needs to be done. This will also automatically make semanticData be defined as an empty object.

    Throws

    KipperError if the code is not valid.

    Since

    0.8.0

    Returns

    Promise<void>

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:357


    primarySemanticTypeChecking

    Protected Optional Abstract primarySemanticTypeChecking(): Promise<void>

    Type checks the code inside this AST node.

    If this is undefined then it means there is no type checking that needs to be done. This will also automatically make typeSemantics be defined as an empty object.

    Throws

    TypeError When a type mismatch or invalid usage is encountered.

    Since

    0.8.0

    Returns

    Promise<void>

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:367


    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>

    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>

    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>

    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>

    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>

    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>

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:295


    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>

    Defined in

    kipper/core/src/compiler/ast/analysable-ast-node.ts:312