Beispiel #1
0
 internal Try(Context context, AST body, AST identifier, TypeExpression type, AST handler, AST finally_block, bool finallyHasControlFlowOutOfIt, Context tryEndContext)
   : base(context) {
   this.body = body;
   this.type = type;
   this.handler = handler;
   this.finally_block = finally_block;
   ScriptObject current_scope = (ScriptObject)Globals.ScopeStack.Peek();
   while (current_scope is WithObject) //Can only happen at run time and only if there is an eval
     current_scope = current_scope.GetParent();
   this.handler_scope = null;
   this.field = null;
   if (identifier != null){
     this.fieldName = identifier.ToString();
     this.field = current_scope.GetField(this.fieldName, BindingFlags.Public|BindingFlags.Instance|BindingFlags.Static);
     if (this.field != null){
       if (type == null && (field is JSVariableField && field.IsStatic && ((JSVariableField)field).type == null) && !field.IsLiteral && !field.IsInitOnly)
         return; //preserve legacy semantics by using the existing variable
       if (((IActivationObject)current_scope).GetLocalField(this.fieldName) != null)
         identifier.context.HandleError(JSError.DuplicateName, false);
     }
     this.handler_scope = new BlockScope(current_scope);
     this.handler_scope.catchHanderScope = true;
     JSVariableField f = this.handler_scope.AddNewField(identifier.ToString(), Missing.Value, FieldAttributes.Public); // must be a local 
     this.field = f; f.originalContext = identifier.context;
     if (identifier.context.document.debugOn && this.field is JSLocalField){
       this.handler_scope.AddFieldForLocalScopeDebugInfo((JSLocalField)this.field);
     }
   }
   this.finallyHasControlFlowOutOfIt = finallyHasControlFlowOutOfIt;
   this.tryEndContext = tryEndContext;
 }
Beispiel #2
0
        internal bool inStaticInitializerCode; //Set this to true when partially evaluating the initializer of a static variable, false otherwise

        internal ClassScope(AST name, GlobalScope scope)
            : base(scope) //The parent must be set to a proper value before the class can be used.
        {
            this.name                 = name.ToString();
            this.engine               = scope.engine;
            this.fast                 = scope.fast;
            this.noExpando            = true;
            this.isKnownAtCompileTime = true;
            this.owner                = null; //set by Class constructor
            this.constructors         = new JSConstructor[0];
            ScriptObject enclosingScope = this.engine.ScriptObjectStackTop();

            while (enclosingScope is WithObject)
            {
                enclosingScope = enclosingScope.GetParent();
            }
            if (enclosingScope is ClassScope)
            {
                this.package = ((ClassScope)enclosingScope).GetPackage();
            }
            else if (enclosingScope is PackageScope)
            {
                this.package = (PackageScope)enclosingScope;
            }
            else
            {
                this.package = null;
            }
            this.itemProp                = null;
            this.outerClassField         = null;
            this.inStaticInitializerCode = false;
        }
        internal ClassScope(AST name, GlobalScope scope) : base(scope)
        {
            this.name                 = name.ToString();
            base.engine               = scope.engine;
            base.fast                 = scope.fast;
            this.noExpando            = true;
            base.isKnownAtCompileTime = true;
            this.owner                = null;
            this.constructors         = new JSConstructor[0];
            ScriptObject parent = base.engine.ScriptObjectStackTop();

            while (parent is WithObject)
            {
                parent = parent.GetParent();
            }
            if (parent is ClassScope)
            {
                this.package = ((ClassScope)parent).GetPackage();
            }
            else if (parent is PackageScope)
            {
                this.package = (PackageScope)parent;
            }
            else
            {
                this.package = null;
            }
            this.itemProp                    = null;
            this.outerClassField             = null;
            this.inStaticInitializerCode     = false;
            this.staticInitializerUsesEval   = false;
            this.instanceInitializerUsesEval = false;
        }
 internal ClassScope(AST name, GlobalScope scope) : base(scope)
 {
     this.name = name.ToString();
     base.engine = scope.engine;
     base.fast = scope.fast;
     this.noExpando = true;
     base.isKnownAtCompileTime = true;
     this.owner = null;
     this.constructors = new JSConstructor[0];
     ScriptObject parent = base.engine.ScriptObjectStackTop();
     while (parent is WithObject)
     {
         parent = parent.GetParent();
     }
     if (parent is ClassScope)
     {
         this.package = ((ClassScope) parent).GetPackage();
     }
     else if (parent is PackageScope)
     {
         this.package = (PackageScope) parent;
     }
     else
     {
         this.package = null;
     }
     this.itemProp = null;
     this.outerClassField = null;
     this.inStaticInitializerCode = false;
     this.staticInitializerUsesEval = false;
     this.instanceInitializerUsesEval = false;
 }
Beispiel #5
0
 // the parser may invoke this function in error condition to change this call to a function declaration
 internal void GetParameters(ArrayList parameters)
 {
     Debug.Assert(this.func is Lookup && this.outParameterCount == 0);
     for (int i = 0, n = this.args.count; i < n; i++)
     {
         AST item = this.args[i];
         parameters.Add(new ParameterDeclaration(item.context, item.ToString(), null, null));
     }
 }
        internal Try(Context context, AST body, AST identifier, TypeExpression type, AST handler, AST finally_block, bool finallyHasControlFlowOutOfIt, Context tryEndContext) : base(context)
        {
            this.body          = body;
            this.type          = type;
            this.handler       = handler;
            this.finally_block = finally_block;
            ScriptObject parent = base.Globals.ScopeStack.Peek();

            while (parent is WithObject)
            {
                parent = parent.GetParent();
            }
            this.handler_scope = null;
            this.field         = null;
            if (identifier != null)
            {
                this.fieldName = identifier.ToString();
                this.field     = parent.GetField(this.fieldName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (this.field != null)
                {
                    if ((((type == null) && (this.field is JSVariableField)) && (this.field.IsStatic && (((JSVariableField)this.field).type == null))) && (!this.field.IsLiteral && !this.field.IsInitOnly))
                    {
                        return;
                    }
                    if (((IActivationObject)parent).GetLocalField(this.fieldName) != null)
                    {
                        identifier.context.HandleError(JSError.DuplicateName, false);
                    }
                }
                this.handler_scope = new BlockScope(parent);
                this.handler_scope.catchHanderScope = true;
                JSVariableField field = this.handler_scope.AddNewField(identifier.ToString(), Microsoft.JScript.Missing.Value, FieldAttributes.Public);
                this.field            = field;
                field.originalContext = identifier.context;
                if (identifier.context.document.debugOn && (this.field is JSLocalField))
                {
                    this.handler_scope.AddFieldForLocalScopeDebugInfo((JSLocalField)this.field);
                }
            }
            this.finallyHasControlFlowOutOfIt = finallyHasControlFlowOutOfIt;
            this.tryEndContext = tryEndContext;
        }
        internal Try(Context context, AST body, AST identifier, TypeExpression type, AST handler, AST finally_block, bool finallyHasControlFlowOutOfIt, Context tryEndContext)
            : base(context)
        {
            this.body          = body;
            this.type          = type;
            this.handler       = handler;
            this.finally_block = finally_block;
            ScriptObject current_scope = (ScriptObject)Globals.ScopeStack.Peek();

            while (current_scope is WithObject) //Can only happen at run time and only if there is an eval
            {
                current_scope = current_scope.GetParent();
            }
            this.handler_scope = null;
            this.field         = null;
            if (identifier != null)
            {
                this.fieldName = identifier.ToString();
                this.field     = current_scope.GetField(this.fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
                if (this.field != null)
                {
                    if (type == null && (field is JSVariableField && field.IsStatic && ((JSVariableField)field).type == null) && !field.IsLiteral && !field.IsInitOnly)
                    {
                        return; //preserve legacy semantics by using the existing variable
                    }
                    if (((IActivationObject)current_scope).GetLocalField(this.fieldName) != null)
                    {
                        identifier.context.HandleError(JSError.DuplicateName, false);
                    }
                }
                this.handler_scope = new BlockScope(current_scope);
                this.handler_scope.catchHanderScope = true;
                JSVariableField f = this.handler_scope.AddNewField(identifier.ToString(), Missing.Value, FieldAttributes.Public); // must be a local
                this.field = f; f.originalContext = identifier.context;
                if (identifier.context.document.debugOn && this.field is JSLocalField)
                {
                    this.handler_scope.AddFieldForLocalScopeDebugInfo((JSLocalField)this.field);
                }
            }
            this.finallyHasControlFlowOutOfIt = finallyHasControlFlowOutOfIt;
            this.tryEndContext = tryEndContext;
        }
Beispiel #8
0
 public override string ToString()
 {
     if (expression != null)
     {
         return(expression.ToString());
     }
     else
     {
         return(String.Empty);
     }
 }
Beispiel #9
0
        internal void GetParameters(ArrayList parameters)
        {
            int num   = 0;
            int count = this.args.count;

            while (num < count)
            {
                AST ast = this.args[num];
                parameters.Add(new ParameterDeclaration(ast.context, ast.ToString(), null, null));
                num++;
            }
        }
 internal TypeExpression(AST expression)
   : base(expression.context) {
   this.expression = expression;
   this.isArray = false;
   this.rank = 0;
   this.recursive = false;
   this.cachedIR = null;
   if (expression is Lookup){
     String name = expression.ToString();
     Object ptype = Globals.TypeRefs.GetPredefinedType(name);
     if (ptype != null)
       this.expression = new ConstantWrapper(ptype, expression.context);
   }
 }
 internal FunctionExpression(Context context, AST id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, Block body, FunctionScope own_scope, FieldAttributes attributes)
   : base(context){
   if (attributes != (FieldAttributes)0){
     this.context.HandleError(JSError.SyntaxError);
     attributes = (FieldAttributes)0;
   }
   ScriptObject enclosingScope = Globals.ScopeStack.Peek();
   this.name = id.ToString();
   if (this.name.Length == 0)
     this.name = "anonymous "+(uniqueNumber++).ToString(CultureInfo.InvariantCulture);
   else
     this.AddNameTo(enclosingScope);
   this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, MethodAttributes.Static|MethodAttributes.Public);
 }
Beispiel #12
0
 internal Class(Context context, AST id, TypeExpression superTypeExpression, TypeExpression[] interfaces, Block body, 
   FieldAttributes attributes, bool isAbstract, bool isFinal, bool isStatic, bool isInterface, CustomAttributeList customAttributes)
   : base(context) {
   this.name = id.ToString();
   this.superTypeExpression = superTypeExpression;
   this.interfaces = interfaces;
   this.body = body;
   this.enclosingScope = (ScriptObject)Globals.ScopeStack.Peek(1);
   this.attributes = TypeAttributes.Class|TypeAttributes.Serializable;
   this.SetAccessibility(attributes);
   if (isAbstract)
     this.attributes |= TypeAttributes.Abstract;
   this.isAbstract = isAbstract || isInterface;
   this.isAlreadyPartiallyEvaluated = false;
   if (isFinal)
     this.attributes |= TypeAttributes.Sealed;
   if (isInterface)
     this.attributes |= TypeAttributes.Interface | TypeAttributes.Abstract;
   this.isCooked = false;
   this.cookedType = null;
   this.isExpando = false;
   this.isInterface = isInterface;
   this.isStatic = isStatic;
   this.needsEngine = !isInterface;
   this.validOn = (AttributeTargets)0;
   this.allowMultiple = true;
   this.classob = (ClassScope)Globals.ScopeStack.Peek();
   this.classob.name = this.name;
   this.classob.owner = this;
   this.implicitDefaultConstructor = null;
   if (!isInterface && !(this is EnumDeclaration))
     this.SetupConstructors();
   this.EnterNameIntoEnclosingScopeAndGetOwnField(id, isStatic);
   this.fields = this.classob.GetMemberFields();
   this.superClass = null;
   this.superIR = null;
   this.superMembers = null;
   this.firstIndex = null;
   this.fieldInitializer = null;
   this.customAttributes = customAttributes;
   this.clsCompliance = CLSComplianceSpec.NotAttributed;
   this.generateCodeForExpando = false;
   this.expandoItemProp = null;
   this.getHashTableMethod = null;
   this.getItem = null;
   this.setItem = null;
 }
Beispiel #13
0
 internal TypeExpression(AST expression) : base(expression.context)
 {
     this.expression = expression;
     this.isArray    = false;
     this.rank       = 0;
     this.recursive  = false;
     this.cachedIR   = null;
     if (expression is Lookup)
     {
         string typeName       = expression.ToString();
         object predefinedType = Globals.TypeRefs.GetPredefinedType(typeName);
         if (predefinedType != null)
         {
             this.expression = new ConstantWrapper(predefinedType, expression.context);
         }
     }
 }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(id);
            if (type_annot != String.Empty)
            {
                sb.Append(":" + type_annot);
                sb.Append(" = ");
            }

            if (val != null)
            {
                sb.Append(val.ToString());
            }

            return("var " + sb.ToString());
        }
Beispiel #15
0
 internal TypeExpression(AST expression)
     : base(expression.context)
 {
     this.expression = expression;
     this.isArray    = false;
     this.rank       = 0;
     this.recursive  = false;
     this.cachedIR   = null;
     if (expression is Lookup)
     {
         String name  = expression.ToString();
         Object ptype = PredefinedType[name];
         if (ptype != null)
         {
             this.expression = new ConstantWrapper(ptype, expression.context);
         }
     }
 }
Beispiel #16
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (cond != null)
            {
                sb.Append(cond.ToString());
            }
            if (true_stm != null)
            {
                sb.Append(true_stm.ToString());
            }
            if (false_stm != null)
            {
                sb.Append(false_stm.ToString());
            }

            return(sb.ToString());
        }
        internal FunctionExpression(Context context, AST id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, Block body, FunctionScope own_scope, FieldAttributes attributes) : base(context)
        {
            if (attributes != FieldAttributes.PrivateScope)
            {
                base.context.HandleError(JSError.SyntaxError);
                attributes = FieldAttributes.PrivateScope;
            }
            ScriptObject enclosingScope = base.Globals.ScopeStack.Peek();

            this.name = id.ToString();
            if (this.name.Length == 0)
            {
                this.name = "anonymous " + uniqueNumber++.ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                this.AddNameTo(enclosingScope);
            }
            this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, base.context, MethodAttributes.Static | MethodAttributes.Public);
        }
Beispiel #18
0
 internal bool inStaticInitializerCode; //Set this to true when partially evaluating the initializer of a static variable, false otherwise
 
 internal ClassScope(AST name, GlobalScope scope)
   : base(scope) { //The parent must be set to a proper value before the class can be used.
   this.name = name.ToString();
   this.engine = scope.engine;
   this.fast = scope.fast;
   this.noExpando = true;
   this.isKnownAtCompileTime = true;
   this.owner = null; //set by Class constructor
   this.constructors = new JSConstructor[0];
   ScriptObject enclosingScope = this.engine.ScriptObjectStackTop();
   while (enclosingScope is WithObject)
     enclosingScope = enclosingScope.GetParent();
   if (enclosingScope is ClassScope)
     this.package = ((ClassScope)enclosingScope).GetPackage();
   else if (enclosingScope is PackageScope)
     this.package = (PackageScope)enclosingScope;
   else
     this.package = null;
   this.itemProp = null;
   this.outerClassField = null;
   this.inStaticInitializerCode = false;
 }
Beispiel #19
0
      private AST MemberExpression(AST expression, ArrayList newContexts, out bool canBeQualid, ref bool canBeAttribute){
        bool noMoreForAttr = false;
        canBeQualid = true;
        for(;;){
          this.noSkipTokenSet.Add(NoSkipTokenSet.s_MemberExprNoSkipTokenSet);
          try{
            switch (this.currentToken.token){
              case JSToken.LeftParen:
                if (noMoreForAttr)
                  canBeAttribute = false;
                else
                  noMoreForAttr = true;
                canBeQualid = false;

                ASTList args = null;
                RecoveryTokenException callError = null;
                this.noSkipTokenSet.Add(NoSkipTokenSet.s_ParenToken);
                try{
                  args = ParseExpressionList(JSToken.RightParen);
                }catch(RecoveryTokenException exc){
                  args = (ASTList)exc._partiallyComputedNode;
                  if (IndexOfToken(NoSkipTokenSet.s_ParenToken, exc) == -1)
                    callError = exc; // thrown later on
                }finally{
                  this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ParenToken);
                }

                //treat eval and print specially
                if (expression is Lookup){
                  String name = expression.ToString();
                  if (name.Equals("eval")){
                    expression.context.UpdateWith(args.context);
                    if (args.count > 0)
                      expression = new Eval(expression.context, args[0]);
                    else
                      expression = new Eval(expression.context, new ConstantWrapper("", CurrentPositionContext()));
                  }else if (this.Globals.engine.doPrint && name.Equals("print")){
                    expression.context.UpdateWith(args.context);
                    expression = new Print(expression.context, args);
                  }else{
                    if (name == "GetObject")
                      this.ForceReportInfo(JSError.GetObjectNotSupportedOnRotor);
                    expression = new Call(expression.context.CombineWith(args.context), expression, args, false);
                  }
                }else
                  expression = new Call(expression.context.CombineWith(args.context), expression, args, false);

                if (null != newContexts && newContexts.Count > 0){
                  ((Context)newContexts[newContexts.Count - 1]).UpdateWith(expression.context);
                  if (!(expression is Call))
                    expression = new Call((Context)newContexts[newContexts.Count - 1], expression, new ASTList(CurrentPositionContext()), false);
                  else
                    expression.context = (Context)newContexts[newContexts.Count - 1];
                  ((Call)expression).isConstructor = true;
                  newContexts.RemoveAt(newContexts.Count - 1);
                }

                if (callError != null){
                  callError._partiallyComputedNode = expression;
                  throw callError;
                }

                GetNextToken();
              break;

              case JSToken.LeftBracket:
                canBeQualid = false;
                canBeAttribute = false;
                this.noSkipTokenSet.Add(NoSkipTokenSet.s_BracketToken);
                try{
                  args = ParseExpressionList(JSToken.RightBracket);
                }catch(RecoveryTokenException exc){
                  if(IndexOfToken(NoSkipTokenSet.s_BracketToken, exc) == -1){
                    if (exc._partiallyComputedNode != null){
                      exc._partiallyComputedNode =
                         new Call(expression.context.CombineWith(this.currentToken.Clone()), expression, (ASTList)exc._partiallyComputedNode, true);
                    }else{
                      exc._partiallyComputedNode = expression;
                    }
                    throw exc;
                  }else
                    args = (ASTList)exc._partiallyComputedNode;
                }finally{
                  this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BracketToken);
                }
                expression = new Call(expression.context.CombineWith(this.currentToken.Clone()), expression, args, true);

                if (null != newContexts && newContexts.Count > 0){
                  ((Context)newContexts[newContexts.Count - 1]).UpdateWith(expression.context);
                  expression.context = (Context)newContexts[newContexts.Count - 1];
                  ((Call)expression).isConstructor = true;
                  newContexts.RemoveAt(newContexts.Count - 1);
                }
                GetNextToken();
              break;

              case JSToken.AccessField:
                if (noMoreForAttr)
                  canBeAttribute = false;
                ConstantWrapper id = null;
                GetNextToken();
                if (JSToken.Identifier != this.currentToken.token){
                  string identifier = JSKeyword.CanBeIdentifier(this.currentToken.token);
                  if (null != identifier){
                    ForceReportInfo(JSError.KeywordUsedAsIdentifier);
                    id = new ConstantWrapper(identifier, this.currentToken.Clone());
                  }else{
                    ReportError(JSError.NoIdentifier);
                    SkipTokensAndThrow(expression);
                  }
                }else
                  id = new ConstantWrapper(this.scanner.GetIdentifier(), this.currentToken.Clone());
                GetNextToken();
                expression = new Member(expression.context.CombineWith(id.context), expression, id);
              break;
              default:
                if (null != newContexts){
                  while (newContexts.Count > 0){
                    ((Context)newContexts[newContexts.Count - 1]).UpdateWith(expression.context);
                    expression = new Call((Context)newContexts[newContexts.Count - 1],
                                          expression,
                                          new ASTList(CurrentPositionContext()),
                                          false);
                    ((Call)expression).isConstructor = true;
                    newContexts.RemoveAt(newContexts.Count - 1);
                  }
                }
                return expression;
            }
          }catch(RecoveryTokenException exc){
            if (IndexOfToken(NoSkipTokenSet.s_MemberExprNoSkipTokenSet, exc) != -1)
              expression = exc._partiallyComputedNode;
            else{
              Debug.Assert(exc._partiallyComputedNode == expression);
              throw exc;
            }
          }finally{
            this.noSkipTokenSet.Remove(NoSkipTokenSet.s_MemberExprNoSkipTokenSet);
          }
        }
      }
Beispiel #20
0
 public override string ToString()
 {
     return(exp.ToString());
 }