Compiler exceptions
This commit is contained in:
+11
-15
@@ -11,9 +11,6 @@ uses
|
||||
Myc.Ast.Types;
|
||||
|
||||
type
|
||||
// Exception specific to scope resolution and definition errors
|
||||
EScopeException = class(Exception);
|
||||
|
||||
IExecutionScope = interface;
|
||||
IScopeDescriptor = interface;
|
||||
IScopeLayout = interface;
|
||||
@@ -359,8 +356,8 @@ end;
|
||||
function TScopeBuilder.Define(const Name: string): Integer;
|
||||
begin
|
||||
// Rule: Shadowing / Redefinition in the same scope is forbidden.
|
||||
if FMap.ContainsKey(Name) then
|
||||
raise EScopeException.CreateFmt('Variable "%s" is already defined in this scope.', [Name]);
|
||||
// The Client (Binder) must ensure this name is not already taken before calling Define.
|
||||
Assert(not FMap.ContainsKey(Name), 'Scope Error: Variable "' + Name + '" is already defined in this scope builder.');
|
||||
|
||||
// Allocate a new slot
|
||||
Result := FNextSlot;
|
||||
@@ -574,6 +571,8 @@ var
|
||||
targetScope: TExecutionScope;
|
||||
i: Integer;
|
||||
begin
|
||||
Assert(Address.Kind <> akUnresolved, 'Scope Error: Cannot capture an unresolved address.');
|
||||
|
||||
case Address.Kind of
|
||||
akUpvalue:
|
||||
begin
|
||||
@@ -600,8 +599,6 @@ begin
|
||||
TMonitor.Exit(targetScope);
|
||||
end;
|
||||
end;
|
||||
else
|
||||
raise EScopeException.Create('Cannot capture an unresolved address.');
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -613,10 +610,9 @@ begin
|
||||
NeedNameToIndex;
|
||||
id := GetNameID(Name);
|
||||
|
||||
// NOTE: Runtime redefinition is generally restricted in this dynamic Define
|
||||
// (typically used for Root/Global definitions).
|
||||
if FNameToIndex.ContainsKey(id) then
|
||||
raise EScopeException.CreateFmt('Variable "%s" is already defined in this scope.', [Name]);
|
||||
// NOTE: Runtime redefinition is generally restricted in this dynamic Define.
|
||||
// The Client must ensure uniqueness.
|
||||
Assert(not FNameToIndex.ContainsKey(id), 'Scope Error: Variable "' + Name + '" is already defined in this execution scope.');
|
||||
|
||||
index := Length(FValues);
|
||||
SetLength(FValues, index + 1);
|
||||
@@ -719,6 +715,8 @@ function TExecutionScope.GetValues(const Address: TResolvedAddress): TDataValue;
|
||||
var
|
||||
item: TScopeItem;
|
||||
begin
|
||||
Assert(Address.Kind <> akUnresolved, 'Scope Error: Cannot get value for an unresolved address.');
|
||||
|
||||
case Address.Kind of
|
||||
akUpvalue:
|
||||
begin
|
||||
@@ -736,8 +734,6 @@ begin
|
||||
else
|
||||
Result := item.Value;
|
||||
end;
|
||||
else
|
||||
raise EScopeException.Create('Cannot get value for an unresolved address.');
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -795,6 +791,8 @@ var
|
||||
targetScope: TExecutionScope;
|
||||
i: Integer;
|
||||
begin
|
||||
Assert(Address.Kind <> akUnresolved, 'Scope Error: Cannot set value for an unresolved address.');
|
||||
|
||||
case Address.Kind of
|
||||
akUpvalue:
|
||||
begin
|
||||
@@ -812,8 +810,6 @@ begin
|
||||
else
|
||||
pItem.Value := Value;
|
||||
end;
|
||||
else
|
||||
raise EScopeException.Create('Cannot set value for an unresolved address.');
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user