public override bool Replace(Node oldValue, Node newValue)
 {
   return
     Replace(Value, oldValue, newValue, n => Value = n)
     ||
     base.Replace(oldValue, newValue);
 }
Example #2
0
    public ParenExpression(Expression expression)
    {
      Expression = expression;
      SourceOffset = expression.SourceOffset;

      Use(Expression);
    }
Example #3
0
 public override bool Replace(Node oldValue, Node newValue)
 {
   return
     Replace(Expression, oldValue, newValue, n => Expression = n)
     ||
     base.Replace(oldValue, newValue);
 }
Example #4
0
    public LogicalAndExpression(Expression left, Expression right, TernaryExpression implementation)
      : base(left, right)
    {
      Implementation = implementation;

      //Implementation.AddUser(this.User);
    }
Example #5
0
 public GuardedCast(Expression expression)
     : base(expression)
 {
     ProfileIndex = -1;
     IsRequired = true;
     ICIndex = -1;
 }
Example #6
0
 public mdr.ValueTypes GetType(Expression expression)
 {
   mdr.ValueTypes type;
   if (!ExpressionTypes.TryGetValue(expression, out type))
     type = mdr.ValueTypes.Unknown;
   return type;
 }
Example #7
0
    public ExpressionStatement(Expression expression)
    {
      Debug.Assert(expression != null, "Expression statement must have an expression");
      Expression = expression;
      SourceOffset = expression.SourceOffset;

      Use(Expression);
    }
Example #8
0
    public CaseClause(Expression expression, BlockStatement body)
    {
      Expression = expression;
      Body = body;
      SourceOffset = body.SourceOffset;

      Use(Expression);
    }
Example #9
0
 /// <summary>
 /// For now we have only ParenExpression that wraps stuff. 
 /// we may add more in the future
 /// </summary>
 Expression GetEquivalent(Expression exp)
 {
   var parenExp = exp as ParenExpression;
   if (parenExp != null)
     return parenExp.Expression;
   else
     return exp;
 }
Example #10
0
    ///// <summary>
    ///// we need to read Expression into a temporary and then use in each case.Comparison
    ///// </summary>
    //public WriteIdentifierExpression Result { get; set; }

    public SwitchStatement(Expression expression, List<CaseClause> caseClauses)
    {
      Expression = expression;
      CaseClauses = caseClauses;// new List<CaseClause>();
      SourceOffset = expression.SourceOffset;

      Use(Expression);
      Use(CaseClauses);
    }
Example #11
0
 private void AssignToImplicitReturn(Expression expression)
 {
   Debug.Assert(expression == _currExpressionStatement.Expression, "Invalid situation!");
   expression.RemoveUser(_currExpressionStatement); //to avoid user complications!
   var assign = new WriteIdentifierExpression(_implicitReturn, expression);
   //_currExpressionStatement.Expression = assign;
   _currExpressionStatement.Replace(_currExpressionStatement.Expression, assign);
   TerminateCurrBlock();
 }
    public WriteIdentifierExpression(JSSymbol symbol, Expression value)
      : base(symbol)
    {
      Debug.Assert(value != null, "Value cannot be null");
      symbol.Writers.Add(this);

      Value = value;
      SourceOffset = value.SourceOffset;

      Use(Value);
    }
Example #13
0
    public CallExpression(ToFunction function, Expression thisArg, List<Expression> arguments, bool isDirectEvalCall)
      : base(function, arguments)
    {
      ThisArg = thisArg;
      Use(ThisArg);

      IsDirectEvalCall = isDirectEvalCall;

      m.Util.Diagnose.Debug.Assert(
        !IsDirectEvalCall
        || ThisArg == null
        , "Invalid situation! DirectEvalCall cannot have a this argument");
      
    }
Example #14
0
 public PositiveExpression(Expression expression)
   : base(expression)
 { }
Example #15
0
 public VoidExpression(Expression expression)
   : base(expression)
 { }
Example #16
0
 public DivideExpression(Expression left, Expression right)
   : base(left, right)
 { }
Example #17
0
 public WriteTemporaryExpression(Expression value)
 {
   Users = new List<Node>();
   Value = value;
   Use(Value);
 }
Example #18
0
 public InstanceOfExpression(Expression left, Expression right)
   : base(left, right)
 { }
Example #19
0
 public NotEqualExpression(Expression left, Expression right)
   : base(left, right)
 {
 }
Example #20
0
 public AdditionExpression(Expression left, Expression right)
   : base(left, right)
 { }
Example #21
0
 protected override void Visit(Expression node) { Visit((Node)node); }
Example #22
0
 public BitwiseNotExpression(Expression expression)
   : base(expression)
 { }
Example #23
0
      void DetectTargetFuncMetadata(JSFunctionMetadata functionMetadata, Invocation expression, Expression function)
      {
        // functions declared in the global scope can be overwritten by other functions or 
        // other scripts in the page, so do not resolve!

        var parenExp = function as ParenExpression;
        if (parenExp != null)
        {
          DetectTargetFuncMetadata(functionMetadata, expression, parenExp.Expression);
          return;
        }

        var toFunction = function as ToFunction;
        if (toFunction != null)
        {
          DetectTargetFuncMetadata(functionMetadata, expression, toFunction.Expression);
          return;
        }

        var funcExp = function as FunctionExpression;
        if (funcExp != null)
        {
          Debug.WriteLine(new JSSourceLocation(functionMetadata, expression), "  function expression detected.");
          expression.TargetFunctionMetadata = funcExp.Metadata;
          return;
        }
        else
        {
          var id = function as Identifier;
          if (id != null)
          {
            var symbol = id.Symbol;// _currFuncMetadata.GetSymbol(id.Text);
            Debug.WriteLine(new JSSourceLocation(functionMetadata, id), "Method call to {0}:", symbol.Name);
            Debug.Assert(symbol != null, new JSSourceLocation(functionMetadata, id), "Symbol cannot be null here!");
            
            if (symbol.ResolvedSymbol != null)
              symbol = symbol.ResolvedSymbol;
            var jsfunc = symbol.ContainerScope.ContainerFunction;
            //JSFunctionMetadata jsfunc = functionMetadata;
            //for (int i = 0; i < symbol.AncestorDistance; i++)
            //  jsfunc = jsfunc.ParentFunction;

            //if (!jsfunc.Scope.IsProgram) //do not resolve global function declaration targets
            if (!symbol.ContainerScope.IsProgram)
            {
              //symbol = jsfunc.Scope.GetSymbol(id.Symbol.Name);
              if (symbol.SubFunctionIndex != mdr.Runtime.InvalidIndex && symbol.NonLocalWritersCount == 0)
              {
                expression.TargetFunctionMetadata = jsfunc.SubFunctions[symbol.SubFunctionIndex];
                // we have found the corresponding JSFunctionImp instance
                Debug.WriteLine(new JSSourceLocation(jsfunc, expression), string.Format("function declaration found. JSFunctionImp name: {0}", jsfunc.SubFunctions[symbol.SubFunctionIndex].FullName));
              }
              else if (symbol.Writers.Count == 1)
              {
                // if a symbol is assigned once and the assigned expression is a function, we can find
                // the corresponding JSFunctionImp statically when the variable is called. For example: var x = function() {}; x();
                var wfunc = symbol.Writers[0].Value as FunctionExpression;
                if (wfunc != null)
                {
                  Debug.Write(new JSSourceLocation(functionMetadata, wfunc), "  function expression detected.");
                  expression.TargetFunctionMetadata = wfunc.Metadata;
                }
              }
            }
            else
              Debug.WriteLine(new JSSourceLocation(jsfunc, expression), "function {0} was not resolved because it was declared globally", jsfunc.Declaration);
          }
        }
        Debug.WriteLine("");
        return;
      }
Example #24
0
      protected override void Loop(LoopStatement loop, Statement initilization, Expression condition, Expression increment, Statement body, bool isDoWhile)
      {
        PushLocation(loop);

        var loopBegin = _ilGen.DefineLabel();
        var loopIncrement = _ilGen.DefineLabel();
        var loopCheck = _ilGen.DefineLabel();
        var loopEnd = _ilGen.DefineLabel();

        _labelInfos.PushLoop(loop, loopEnd, loopIncrement);

        VisitNode(initilization);

        ++_loopNestLevel;

        if (!isDoWhile)
          _ilGen.Br(loopCheck);

        _ilGen.MarkLabel(loopBegin);
        VisitNode(body);

        _ilGen.MarkLabel(loopIncrement);
        if (increment != null)
        {
          var stackState = _localVars.GetTemporaryStackState();
          VisitNode(increment);
          AsVoid();
          _localVars.PopTemporariesAfter(stackState);
        }

        _ilGen.MarkLabel(loopCheck);

        if (condition != null)
        {
          VisitNode(condition);
          AsBoolean();
          _ilGen.Brtrue(loopBegin);
        }
        else
          _ilGen.Br(loopBegin);

        _ilGen.MarkLabel(loopEnd);

        --_loopNestLevel;

        _labelInfos.PopLoop(loop);

        PopLocation();
      }
Example #25
0
 public BitwiseXorExpression(Expression left, Expression right)
   : base(left, right)
 { }
Example #26
0
 public MultiplyExpression(Expression left, Expression right)
   : base(left, right)
 { }
Example #27
0
 mdr.ValueTypes GetType(Expression node) { return node.ValueType; }
Example #28
0
 public InExpression(Expression left, Expression right)
   : base(left, right)
 { }
Example #29
0
 public SubtractionExpression(Expression left, Expression right)
   : base(left, right)
 { }
      protected override void Loop(LoopStatement loop, Statement initilization, Expression condition, Expression increment, Statement body, bool isDoWhile)
      {
        PushLocation(loop);

        VisitNode(initilization);

        ++_loopNestLevel;

        var breakIndexes = new LinkedList<int>();
        var continueIndexes = new LinkedList<int>();
        _labelInfos.PushLoop(loop, breakIndexes, continueIndexes);

        var gotoLoopCheckIndex = -1;
        if (!isDoWhile)
          gotoLoopCheckIndex = ReserveNewICIndex(); //Reserver a place and will generate the goto later

        var loopBeginIndex = GetCurrentICIndex() + 1;
        VisitNode(body);

        var loopIncrementIndex = GetCurrentICIndex() + 1;
        UpdateJumps(loopIncrementIndex, continueIndexes);
        if (increment != null)
        {
          VisitNode(increment);
          AsVoid();
        }

        if (gotoLoopCheckIndex != -1)
        {
          BeginICMethod("GotoLoopCheck");
          Br(GetCurrentICIndex() + 1);
          EndICMethod(gotoLoopCheckIndex);
        }

        if (condition != null)
        {
          VisitNode(condition);
          _stackModel.Pop(1);
          BeginICMethod("GotoLoopBegin");
          Brtrue(_stackModel.StackPointer, loopBeginIndex);
          EndICMethod();
        }
        else
        {
          BeginICMethod("GotoLoopBegin");
          Br(loopBeginIndex);
          EndICMethod();
        }

        UpdateJumps(GetCurrentICIndex() + 1, breakIndexes);

        --_loopNestLevel;

        _labelInfos.PopLoop(loop);

        PopLocation();
      }