Example #1
0
    public FunctionDeclarationStatement MakeFunctionDeclarationStatement(Scope scope, IIdentifier name, IIdentifierList parameters,
                                                                         IStatement statement, Scope newScope)
    {
      Debug.Assert(newScope.IsFunctionDeclaration == true, "The FunctionDeclaration scope is not properly marked");

      var func = MakeFunctionExpression(scope, name, parameters, statement, newScope);
      //After making the func expression, we are sure name.Symbol belongs to scope
      return new FunctionDeclarationStatement(func, MakeWriteIdentifierExpression(((Identifier)name).Symbol, func));
    }
Example #2
0
        public FunctionDeclarationStatement MakeFunctionDeclarationStatement(Scope scope, IIdentifier name, IIdentifierList parameters,
                                                                             IStatement statement, Scope newScope)
        {
            Debug.Assert(newScope.IsFunctionDeclaration == true, "The FunctionDeclaration scope is not properly marked");

            var func = MakeFunctionExpression(scope, name, parameters, statement, newScope);

            //After making the func expression, we are sure name.Symbol belongs to scope
            return(new FunctionDeclarationStatement(func, MakeWriteIdentifierExpression(((Identifier)name).Symbol, func)));
        }
Example #3
0
    public FunctionExpression MakeFunctionExpression(Scope scope, IIdentifier name, IIdentifierList parameters,
                                                     IStatement statement, Scope newScope)
    {
      var namedParams = parameters as List<ReadIdentifierExpression>;
      Debug.Assert(namedParams.Count == 0 || newScope.IsFunction, "parameters must be declared in a function scope");
      for (var i = 0; i < namedParams.Count; ++i)
      {
        var symbol = namedParams[i].Symbol;
        Debug.Assert(newScope.GetSymbol(symbol.Name) == symbol && symbol.ContainerScope == newScope, "Invalid situation, parameter symbol is not in the newScope");
        symbol.SymbolType = JSSymbol.SymbolTypes.Local; //already know symbol.ContainerScope.IsFunction, so no need for hoisting
        symbol.ParameterIndex = i;
      }

      var funcName = name as ReadIdentifierExpression;
      if (newScope.IsFunctionDeclaration)
      {
        Debug.Assert(funcName != null, "the function declaration must have a name");
        Debug.Assert(scope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == scope, "Name of function declaration must exist in the outer scope");
        DeclareHoistedLocal(funcName.Symbol); //This is defined now in its scope!
      }
      else if (newScope.IsProgram)
      {
        Debug.Assert(funcName == null, "program scope cannot have a name!");
      }
      else
      {
        Debug.Assert(newScope.IsFunction == true, "The FunctionExpression scope is not properly marked");
        if (funcName != null)
        {
          Debug.Assert(newScope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == newScope, "Name of function expression must exist in its own scope");
          funcName.Symbol.SymbolType = JSSymbol.SymbolTypes.Local; //This is defined now in its scope, & we already know funcName.Symbol.ContainerScope.IsFunction, so no need for hoisting
        }
      }

      var func = new FunctionExpression(newScope, funcName, namedParams, (BlockStatement)statement);

      var metadata = new JSFunctionMetadata(func);
      func.Metadata = metadata;
      if (scope != null) scope.AddSubFunction(metadata);

      return func;
    }
Example #4
0
        public FunctionExpression MakeFunctionExpression(Scope scope, IIdentifier name, IIdentifierList parameters,
                                                         IStatement statement, Scope newScope)
        {
            var namedParams = parameters as List <ReadIdentifierExpression>;

            Debug.Assert(namedParams.Count == 0 || newScope.IsFunction, "parameters must be declared in a function scope");
            for (var i = 0; i < namedParams.Count; ++i)
            {
                var symbol = namedParams[i].Symbol;
                Debug.Assert(newScope.GetSymbol(symbol.Name) == symbol && symbol.ContainerScope == newScope, "Invalid situation, parameter symbol is not in the newScope");
                symbol.SymbolType     = JSSymbol.SymbolTypes.Local; //already know symbol.ContainerScope.IsFunction, so no need for hoisting
                symbol.ParameterIndex = i;
            }

            var funcName = name as ReadIdentifierExpression;

            if (newScope.IsFunctionDeclaration)
            {
                Debug.Assert(funcName != null, "the function declaration must have a name");
                Debug.Assert(scope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == scope, "Name of function declaration must exist in the outer scope");
                DeclareHoistedLocal(funcName.Symbol); //This is defined now in its scope!
            }
            else if (newScope.IsProgram)
            {
                Debug.Assert(funcName == null, "program scope cannot have a name!");
            }
            else
            {
                Debug.Assert(newScope.IsFunction == true, "The FunctionExpression scope is not properly marked");
                if (funcName != null)
                {
                    Debug.Assert(newScope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == newScope, "Name of function expression must exist in its own scope");
                    funcName.Symbol.SymbolType = JSSymbol.SymbolTypes.Local; //This is defined now in its scope, & we already know funcName.Symbol.ContainerScope.IsFunction, so no need for hoisting
                }
            }

            var func = new FunctionExpression(newScope, funcName, namedParams, (BlockStatement)statement);

            var metadata = new JSFunctionMetadata(func);

            func.Metadata = metadata;
            if (scope != null)
            {
                scope.AddSubFunction(metadata);
            }

            return(func);
        }