Exemplo n.º 1
0
 internal CallerVariable(IReferenceGraph graph, BindingSymbol symbol)
     : base(graph)
 {
     _ = symbol.DataType.UnderlyingReferenceType()
         ?? throw new ArgumentException("Must be a reference type", nameof(symbol));
     Symbol = symbol;
 }
Exemplo n.º 2
0
        public CallerVariable AddCallerVariable(BindingSymbol symbol)
        {
            var variable = new CallerVariable(this, symbol);

            callerVariables.Add(variable.Symbol, variable);
            Dirty();
            return(variable);
        }
Exemplo n.º 3
0
        public Variable AddVariable(BindingSymbol symbol)
        {
            var variable = new Variable(this, symbol);

            variables.Add(variable.Symbol, variable);
            Dirty();
            return(variable);
        }
        public VariableFlags Set(BindingSymbol symbol, bool value)
        {
            // TODO if setting to the current value, don't need to clone
            var newFlags = Clone();

            newFlags.flags[symbolMap[symbol]] = value;
            return(newFlags);
        }
Exemplo n.º 5
0
        public void EndVariableScope(BindingSymbol variable)
        {
            if (!variables.Remove(variable, out var place))
            {
                throw new Exception($"Variable '{variable.Name}' does not exist in the graph.");
            }

            place.Freed();
            Dirty();
        }
Exemplo n.º 6
0
 public BorrowExpression(
     TextSpan span,
     DataType dataType,
     ExpressionSemantics semantics,
     BindingSymbol referencedSymbol,
     IExpression referent)
     : base(span, dataType, semantics)
 {
     ReferencedSymbol = referencedSymbol;
     Referent         = referent;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Declare a variable in the current scope
 /// </summary>
 public void VariableDeclared(BindingSymbol symbol)
 {
     variables.Add(symbol);
 }
 public VariableDeclaration VariableFor(BindingSymbol symbol)
 {
     return(variables.Single(v => v.Symbol == symbol));
 }
        public VariableDeclaration AddParameter(bool mutableBinding, DataType type, Scope scope, BindingSymbol symbol)
        {
            var variable = new VariableDeclaration(true, mutableBinding, type.ToNonConstantType(),
                                                   new Variable(variables.Count), scope, symbol);

            variables.Add(variable);
            return(variable);
        }
 public Variable?TryGetVariableFor(BindingSymbol variableSymbol)
 {
     return(ReferenceGraph.TryGetVariableFor(variableSymbol));
 }
        //private void Add(Object obj)
        //{
        //    if (objects.TryAdd(obj.OriginSyntax, obj))
        //    {
        //        AddReferences(obj);
        //        this.Dirty();
        //    }
        //}

        //public void Add(TempValue? temp)
        //{
        //    if (temp is null) return; // for convenience
        //    if (tempValues.Add(temp))
        //    {
        //        AddReferences(temp);
        //        Dirty();
        //    }
        //}

        //private void Add(Variable? variable)
        //{
        //    if (variable is null) return; // for convenience
        //    variables.Add(variable.Symbol, variable);
        //    AddReferences(variable);
        //    Dirty();
        //}

        //private void AddReferences(MemoryPlace place)
        //{
        //    foreach (var reference in place.References)
        //        Add(reference.Referent);
        //}

        public void EndVariableScope(BindingSymbol variable)
        {
            ReferenceGraph.EndVariableScope(variable);
        }
Exemplo n.º 12
0
 public Variable?TryGetVariableFor(BindingSymbol variableSymbol)
 {
     return(variables.TryGetValue(variableSymbol, out var variable) ? variable : null);
 }
Exemplo n.º 13
0
 public Variable GetVariableFor(BindingSymbol variableSymbol)
 {
     // Variable needs to have already been declared
     return(variables[variableSymbol]);
 }
 public bool?this[BindingSymbol symbol] => symbolMap.TryGetValue(symbol, out var i) ? (bool?)flags[i] : null;