Class: KipperSemanticChecker
compiler.KipperSemanticChecker
Kipper Semantic Checker, which asserts that semantic logic and cohesion is valid and throws errors in case that an invalid use of tokens is detected.
Since
0.7.0
Hierarchy
-
↳
KipperSemanticChecker
Table of contents
Constructors
Properties
Methods
- assertError
- builtInNotDefined
- error
- getExistingReference
- getJumpStatementParent
- getReference
- getReturnStatementParent
- globalCanBeGenerated
- globalCanBeRegistered
- identifierNotUsed
- notImplementedError
- refTargetDefined
- setTracebackData
- validAssignment
- validFunctionBody
- validVariableDeclaration
Constructors
constructor
• new KipperSemanticChecker(programCtx)
Parameters
| Name | Type |
|---|---|
programCtx |
KipperProgramContext |
Overrides
KipperSemanticsAsserter.constructor
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:54
Properties
col
• Protected col: undefined | number
Inherited from
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-error-handler.ts:16
ctx
• Protected ctx: undefined | CompilableASTNode<SemanticData, TypeData>
Inherited from
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-error-handler.ts:17
filePath
• Protected filePath: undefined | string
Inherited from
KipperSemanticsAsserter.filePath
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-error-handler.ts:18
line
• Protected line: undefined | number
Inherited from
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-error-handler.ts:15
programCtx
• Readonly programCtx: KipperProgramContext
Inherited from
KipperSemanticsAsserter.programCtx
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-asserter.ts:18
stream
• Protected stream: undefined | KipperFileStream
Inherited from
KipperSemanticsAsserter.stream
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-error-handler.ts:19
Methods
assertError
▸ Protected assertError(error, overwriteCtx?): KipperError
Updates the given error and adds the proper traceback data, and returns it.
Parameters
| Name | Type | Description |
|---|---|---|
error |
KipperError |
The error to update. |
overwriteCtx? |
CompilableASTNode<SemanticData, TypeData> |
The context to overwrite the current context with. This is used when a parent checks children semantics in order to provide the correct traceback data and errors occur in the children. |
Returns
The Kipper error.
Inherited from
KipperSemanticsAsserter.assertError
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-asserter.ts:33
builtInNotDefined
▸ builtInNotDefined(identifier): void
Asserts that the passed identifier does not exist as a built-in global.
Throws
If the identifier is already used by a built-in global.
Since
0.7.0
Parameters
| Name | Type | Description |
|---|---|---|
identifier |
string |
The identifier to check. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:145
error
▸ Protected error(error): KipperError
Updates the error and adds the proper traceback data, and returns it.
This function also automatically logs the error.
Parameters
| Name | Type | Description |
|---|---|---|
error |
KipperError |
The error to update. |
Returns
The Kipper error.
Inherited from
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-error-handler.ts:52
getExistingReference
▸ getExistingReference(identifier, scope): ScopeDeclaration
Tries to fetch the function, and if it fails it will throw an UnknownReferenceError.
Since
0.7.0
Parameters
| Name | Type | Description |
|---|---|---|
identifier |
string |
The identifier to fetch. |
scope |
Scope<any, any, any> |
The scope to search in. |
Returns
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:74
getJumpStatementParent
▸ getJumpStatementParent(jmpStatement): IterationStatement<IterationStatementSemantics, IterationStatementTypeSemantics>
Searches for the parent of the specified jump statement (either 'break' or 'continue' and asserts that it is an iteration statement.)
Throws
If the parent is not an iteration statement.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
jmpStatement |
JumpStatement |
The jump statement. |
Returns
IterationStatement<IterationStatementSemantics, IterationStatementTypeSemantics>
The parent iteration statement if found.
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:260
getReference
▸ Protected getReference(identifier, scope): undefined | ScopeDeclaration
Tries to find a reference for the given identifier and scope.
Since
0.8.0
Parameters
| Name | Type | Description |
|---|---|---|
identifier |
string |
The identifier to search for. |
scope |
Scope<any, any, any> |
The scope to search in. |
Returns
undefined | ScopeDeclaration
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:64
getReturnStatementParent
▸ getReturnStatementParent(retStatement): KipperCallable
Searches for the parent of the specified return statement and asserts that it is a function.
Throws
If the parent is not a function.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
retStatement |
ReturnStatement |
The return statement. |
Returns
The parent function if found.
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:231
globalCanBeGenerated
▸ globalCanBeGenerated(identifier): void
Asserts that the passed identifier is a valid built-in global that has a generator function in the this.programCtx.target.builtInGenerator BuiltInGenerator of the target.
Throws
If there is no generator function for the passed identifier.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
identifier |
string |
The identifier to check. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:177
globalCanBeRegistered
▸ globalCanBeRegistered(identifier): void
Asserts that a new global with the passed identifier may be created.
Throws
If the identifier is already used by a built-in global.
Since
0.7.0
Parameters
| Name | Type | Description |
|---|---|---|
identifier |
string |
The identifier to check. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:157
identifierNotUsed
▸ identifierNotUsed(declaration, identifier, scopeCtx): void
Recursively ensures that the identifier does not overwrite any declarations in this scope or parent scopes.
Throws
If the identifier is already used by a variable.
Throws
If the identifier is already used by a function.
Throws
If the identifier is already used by a parameter.
Throws
If the identifier is already in use by a built-in function.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
declaration |
Declaration<DeclarationSemantics, DeclarationTypeSemantics> |
The declaration to check. |
identifier |
string |
The identifier to search for in this scope and its parent scopes. |
scopeCtx |
Scope<any, any, any> |
The context instance of the scope. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:105
notImplementedError
▸ notImplementedError(error): KipperNotImplementedError
Modifies the metadata for a KipperNotImplementedError
Since
0.7.0
Parameters
| Name | Type | Description |
|---|---|---|
error |
KipperNotImplementedError |
The KipperNotImplementedError instance. |
Returns
Inherited from
KipperSemanticsAsserter.notImplementedError
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-asserter.ts:54
refTargetDefined
▸ refTargetDefined(ref): void
Asserts that the passed ref is defined and has a value assigned that can be used.
Throws
If the reference is undefined.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
ref |
ScopeDeclaration |
The reference that should be checked. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:88
setTracebackData
▸ setTracebackData(data): void
Sets the traceback related metadata that will be used to create a traceback for an KipperError instance.
In case that data.ctx is set and other fields are missing, these fields will be filled up using the data in the data.ctx AST node ctx instance.
Since
0.8.0
Parameters
| Name | Type | Description |
|---|---|---|
data |
Object |
The traceback data that will be used to initialise an KipperError instance. |
data.col? |
number |
- |
data.ctx? |
CompilableASTNode<SemanticData, TypeData> |
- |
data.filePath? |
string |
- |
data.line? |
number |
- |
data.stream? |
KipperFileStream |
- |
Returns
void
Inherited from
KipperSemanticsAsserter.setTracebackData
Defined in
kipper/core/src/compiler/semantics/analyser/err-handler/semantics-error-handler.ts:29
validAssignment
▸ validAssignment(leftExp): void
Asserts that the passed expression is valid.
Throws
If the left-hand side of the assignment is invalid.
Since
0.7.0
Parameters
| Name | Type | Description |
|---|---|---|
leftExp |
Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> |
The left-hand side of the assignment. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:190
validFunctionBody
▸ validFunctionBody(body): void
Asserts that the passed function body is valid.
Throws
If the function body is missing or invalid.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
body |
undefined | CompilableNodeChild |
The function body. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:218
validVariableDeclaration
▸ validVariableDeclaration(decl): void
Asserts that the variable declaration is valid.
Throws
If the variable is a constant and has no value assigned.
Parameters
| Name | Type | Description |
|---|---|---|
decl |
VariableDeclaration |
The variable declaration. |
Returns
void
Defined in
kipper/core/src/compiler/semantics/analyser/semantic-checker.ts:205