Skip to content

Commit

Permalink
minor (#663): added better semantic data types
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzholzbauer committed Jul 23, 2024
1 parent 6d5e09e commit 13faeb7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To use development versions of Kipper download the
- Implemented internal generic spread argument `T...`, which allows multiple arguments to be passed to a single
parameter inside of a generic type specifier.
- Implemented constant `NaN`, which represents the `NaN` value in JavaScript (Not a Number).
([#671](https://github.com/Kipper-Lang/Kipper/issues/671))
([#671](https://github.com/Kipper-Lang/Kipper/issues/671))
- New module:
- `semantics/runtime-built-ins`, which contains runtime built-in functions, variables and types.
- `semantics/runtime-internals`, which contains the runtime internal functions.
Expand Down
1 change: 0 additions & 1 deletion kipper/core/KipperLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ False : 'false';

// typeof operator
Typeof : 'typeof';
DefFunc : 'def';

// Constant undefined, void and null identifiers
Void : 'void';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* @since 0.8.0
*/
import type { TypeSpecifierExpressionSemantics } from "../type-specifier-expression-semantics";
import type { Expression } from "../../expression";
import type { ProcessedType } from "../../../../../semantics";

/**
* Semantics for AST Node {@link TypeofTypeSpecifierExpression}.
* @since 0.8.0
*/
export interface TypeofTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics {
/**
* The expression to evaluate the type of.
* @since 0.8.0
* The checked type for this typeof expression.
* @since 0.12.0
*/
object: Expression;
evaluatedType: ProcessedType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { CompilableASTNode } from "../../../../compilable-ast-node";
import { TypeSpecifierExpression } from "../type-specifier-expression";
import type { TypeofTypeSpecifierExpressionContext } from "../../../../../lexer-parser";
import { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../lexer-parser";
import { KipperNotImplementedError } from "../../../../../../errors";
import { RawType } from "../../../../../semantics";

/**
* Typeof type specifier expression, which represents a runtime typeof expression evaluating the type of a value.
Expand Down Expand Up @@ -81,13 +81,13 @@ export class TypeofTypeSpecifierExpression extends TypeSpecifierExpression<
* the children has already failed and as such no parent node should run type checking.
*/
public async primarySemanticAnalysis(): Promise<void> {
const objectToValidate = this.children[0];
const expression = this.children[0];

this.programCtx.semanticCheck(this);

this.semanticData = {
object: objectToValidate,
rawType: objectToValidate.getTypeSemanticData().evaluatedType,
evaluatedType: expression.getTypeSemanticData().evaluatedType,
rawType: new RawType(expression.sourceCode)
};
}

Expand All @@ -102,7 +102,7 @@ export class TypeofTypeSpecifierExpression extends TypeSpecifierExpression<
this.programCtx.semanticCheck(this);

this.typeSemantics = {
storedType: semanticData.object.getTypeSemanticData().evaluatedType,
storedType: semanticData.object.g,
evaluatedType: semanticData.object.getTypeSemanticData().evaluatedType,
};
}
Expand Down
11 changes: 4 additions & 7 deletions test/kipper-files/typeof.kip
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
interface X {
a: str;
b: num;
}

var y: X = {
a: "hello",
b: 5
a: num;
b: str;
};

var x: typeof(null);

0 comments on commit 13faeb7

Please sign in to comment.