Ejemplo n.º 1
0
    /// <summary>
    /// Merges the data of the other scope into this scope
    /// </summary>
    /// <param name="other"></param>
    public void Merge(Scope other)
    {
      Debug.Assert(ContainerFunction == null && other.ContainerFunction == null, "Cannot merge scopes that are already assigned to their container function!");
      Trace.Fail("This is not yet fully implemented, if you get here, you need to finish it");

      _flags |= other._flags;
      AstCost += other.AstCost;
      Returns.AddRange(other.Returns);
      Invocations.AddRange(other.Invocations);
      _subFunctions.AddRange(other._subFunctions);

      foreach (var otherSymbol in other.Symbols)
      {
        Debug.Assert(GetSymbol(otherSymbol.Name) == null, "Symbol {0} already exists in the scope; merge the symbols usages is not yet implemented!", otherSymbol.Name);
        
        var thisSymbol = GetOrAddSymbol(otherSymbol.Name);

        switch (thisSymbol.SymbolType)
        {
          case JSSymbol.SymbolTypes.Unknown:
            thisSymbol.SymbolType = otherSymbol.SymbolType;
            thisSymbol.ParameterIndex = otherSymbol.ParameterIndex;
            thisSymbol.SubFunctionIndex = otherSymbol.SubFunctionIndex;
            //thisSymbol.AncestorDistance = otherSymbol.AncestorDistance;
            thisSymbol.Readers.AddRange(otherSymbol.Readers);
            thisSymbol.Writers.AddRange(otherSymbol.Writers);
            break;
          default:
            throw new NotImplementedException();
        }
      }
    }
Ejemplo n.º 2
0
    public JSSymbol(string name, Scope containingScope, int index)
    {
      Name = name;
      ContainerScope = containingScope;
      Index = index;

      ValueIndex = mdr.Runtime.InvalidIndex;
      ParameterIndex = mdr.Runtime.InvalidIndex;
      FieldId = mdr.Runtime.InvalidFieldId;
      SubFunctionIndex = mdr.Runtime.InvalidIndex;
      //AncestorDistance = mdr.Runtime.InvalidIndex;

      ValueType = mdr.ValueTypes.Unknown;
    }
Ejemplo n.º 3
0
    public Scope(Scope outerScope)
    {
      OuterScope = outerScope;
      if (OuterScope != null)
      {
        IndexInOuterScope = OuterScope.InnerScopes.Count;
        OuterScope.InnerScopes.Add(this);
      }
      else
        IndexInOuterScope = mdr.Runtime.InvalidIndex;

      _subFunctions = new List<JSFunctionMetadata>();
    }