Compiler exceptions

This commit is contained in:
Michael Schimmel
2025-11-25 15:27:57 +01:00
parent d84509c034
commit 4e508d90a5
8 changed files with 62 additions and 28 deletions
+8 -5
View File
@@ -11,6 +11,9 @@ uses
Myc.Ast.Types;
type
// Exception specific to scope resolution and definition errors
EScopeException = class(Exception);
IExecutionScope = interface;
IScopeDescriptor = interface;
IScopeLayout = interface;
@@ -357,7 +360,7 @@ function TScopeBuilder.Define(const Name: string): Integer;
begin
// Rule: Shadowing / Redefinition in the same scope is forbidden.
if FMap.ContainsKey(Name) then
raise Exception.CreateFmt('Variable "%s" is already defined in this scope.', [Name]);
raise EScopeException.CreateFmt('Variable "%s" is already defined in this scope.', [Name]);
// Allocate a new slot
Result := FNextSlot;
@@ -598,7 +601,7 @@ begin
end;
end;
else
raise EInvalidOpException.Create('Cannot capture an unresolved address.');
raise EScopeException.Create('Cannot capture an unresolved address.');
end;
end;
@@ -613,7 +616,7 @@ begin
// NOTE: Runtime redefinition is generally restricted in this dynamic Define
// (typically used for Root/Global definitions).
if FNameToIndex.ContainsKey(id) then
raise Exception.CreateFmt('Variable "%s" is already defined in this scope.', [Name]);
raise EScopeException.CreateFmt('Variable "%s" is already defined in this scope.', [Name]);
index := Length(FValues);
SetLength(FValues, index + 1);
@@ -734,7 +737,7 @@ begin
Result := item.Value;
end;
else
raise EInvalidOpException.Create('Cannot get value for an unresolved address.');
raise EScopeException.Create('Cannot get value for an unresolved address.');
end;
end;
@@ -810,7 +813,7 @@ begin
pItem.Value := Value;
end;
else
raise EInvalidOpException.Create('Cannot set value for an unresolved address.');
raise EScopeException.Create('Cannot set value for an unresolved address.');
end;
end;