AST Types

This commit is contained in:
Michael Schimmel
2025-10-25 19:19:55 +02:00
parent 5a289492a3
commit 85f2e02893
2 changed files with 40 additions and 142 deletions
+19
View File
@@ -10,6 +10,7 @@ uses
Myc.Data.Scalar,
Myc.Data.Value,
Myc.Ast.Nodes,
Myc.Ast.Types,
Myc.Ast.Scope;
type
@@ -67,8 +68,12 @@ type
// Common base class for AST nodes to reduce boilerplate.
TAstNode = class(TInterfacedObject, IAstNode)
private
FStaticType: IStaticType;
public
constructor Create;
function Accept(const Visitor: IAstVisitor): TDataValue; virtual; abstract;
property StaticType: IStaticType read FStaticType write FStaticType;
end;
TConstantNode = class(TAstNode, IConstantNode)
@@ -324,6 +329,14 @@ begin
if not (AValue.Kind in [vkScalar, vkText, vkVoid]) then
raise EArgumentException.Create('IConstantNode only supports Scalar, Text, and Void values.');
FValue := AValue;
case AValue.Kind of
vkScalar: StaticType := TTypes.FromScalarKind(AValue.AsScalar.Kind);
vkText: StaticType := TTypes.Text;
vkVoid: StaticType := TTypes.Void;
else
StaticType := TTypes.Unknown; // Should not happen due to validation above
end;
end;
function TConstantNode.Accept(const Visitor: IAstVisitor): TDataValue;
@@ -988,4 +1001,10 @@ begin
Result := TVariableDeclarationNode.Create(AIdentifier, AInitializer);
end;
constructor TAstNode.Create;
begin
inherited;
FStaticType := TTypes.Unknown;
end;
end.