port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Linq;
namespace Intromat.Model.Compiler
{
public class ScopeDefinition
{
public ScopeDefinition(string identifier)
{
Identifier = identifier;
}
public string Identifier { get; }
public List<IVariableDefinition> Variables { get; } = new();
}
public class CompilerContext
{
public Stack<ScopeDefinition> VariablesScopesStack { get; } = new();
public string FindFreeVariableName()
{
return "v" + VariablesScopesStack.SelectMany(s => s.Variables).Count();
}
public void AddVariableToCurrentScope(IVariableDefinition variable)
{
VariablesScopesStack.Peek().Variables.Add(variable);
}
public void EnterNewScope(string scopeIdentifier)
{
VariablesScopesStack.Push(new ScopeDefinition(scopeIdentifier));
}
public void LeaveScope()
{
VariablesScopesStack.Pop();
}
public bool IsInScope(IVariableDefinition variable)
{
if (variable == null) return false;
return VariablesScopesStack.Any(s => s.Variables.Contains(variable));
}
}
}