Skip to content

Commit

Permalink
initialized/declared type symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepami committed Oct 14, 2023
1 parent e7c542d commit cc3eacd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Interpreter.Lib/IR/CheckSemantics/Variables/Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ public abstract class Symbol
public abstract string Id { get; }
public abstract Type Type { get; }
public SymbolState State { get; protected set; } = SymbolState.Declared;

public void SetInitialized()
{
if (State is not SymbolState.Declared)
throw new InvalidOperationException(
message: "Only declared symbols can be initialized");

State = SymbolState.Initialized;
}
}

public enum SymbolState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ public void Resolve()
{
var declarationToResolve = _declarationsToResolve.Dequeue();

var type = declarationToResolve.SymbolTable
.FindSymbol<TypeSymbol>(declarationToResolve.TypeId)
.Type;
var typeSymbol = declarationToResolve.SymbolTable
.FindSymbol<TypeSymbol>(declarationToResolve.TypeId);

var resolvingCandidates = declarationToResolve.SymbolTable
.GetAvailableSymbols()
Expand All @@ -43,10 +42,11 @@ public void Resolve()

foreach (var referenceSymbol in resolvingCandidates)
{
type.ResolveReference(
typeSymbol.Type.ResolveReference(
referenceSymbol.Type,
referenceSymbol.Id);
}
typeSymbol.SetInitialized();
}
}
}

0 comments on commit cc3eacd

Please sign in to comment.