示例#1
0
文件: try.cs 项目: ArildF/masters
 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;
 }
 internal EnumDeclaration(Context context, IdentifierLiteral id, TypeExpression baseType, Block body, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context, id, new TypeExpression(new ConstantWrapper(Typeob.Enum, null)), new TypeExpression[0], body, attributes, false, false, true, false, customAttributes)
 {
     this.baseType = (baseType != null) ? baseType : new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
     base.needsEngine = false;
     base.attributes &= TypeAttributes.NestedFamORAssem;
     TypeExpression expression = new TypeExpression(new ConstantWrapper(base.classob, base.context));
     AST ast = new ConstantWrapper(-1, null);
     AST ast2 = new ConstantWrapper(1, null);
     JSMemberField[] fields = base.fields;
     for (int i = 0; i < fields.Length; i++)
     {
         FieldInfo info = fields[i];
         JSVariableField field = (JSVariableField) info;
         field.attributeFlags = FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Public;
         field.type = expression;
         if (field.value == null)
         {
             field.value = ast = new Plus(ast.context, ast, ast2);
         }
         else
         {
             ast = (AST) field.value;
         }
         field.value = new DeclaredEnumValue(field.value, field.Name, base.classob);
     }
 }
 internal FunctionObject(string name, ParameterDeclaration[] parameter_declarations, TypeExpression return_type_expr, Block body, FunctionScope own_scope, ScriptObject enclosing_scope, Context funcContext, MethodAttributes attributes, CustomAttributeList customAttributes, bool isMethod) : base(body.Globals.globalObject.originalFunction.originalPrototype, name, parameter_declarations.Length)
 {
     this.parameter_declarations = parameter_declarations;
     int length = parameter_declarations.Length;
     this.formal_parameters = new string[length];
     for (int i = 0; i < length; i++)
     {
         this.formal_parameters[i] = parameter_declarations[i].identifier;
     }
     this.argumentsSlotNumber = 0;
     this.return_type_expr = return_type_expr;
     if (this.return_type_expr != null)
     {
         own_scope.AddReturnValueField();
     }
     this.body = body;
     this.method = null;
     this.parameterInfos = null;
     this.funcContext = funcContext;
     this.own_scope = own_scope;
     this.own_scope.owner = this;
     if ((!(enclosing_scope is ActivationObject) || !((ActivationObject) enclosing_scope).fast) && !isMethod)
     {
         this.argumentsSlotNumber = this.own_scope.GetNextSlotNumber();
         JSLocalField field = (JSLocalField) this.own_scope.AddNewField("arguments", null, FieldAttributes.PrivateScope);
         field.type = new TypeExpression(new ConstantWrapper(Typeob.Object, funcContext));
         field.isDefined = true;
         this.hasArgumentsObject = true;
     }
     else
     {
         this.hasArgumentsObject = false;
     }
     this.implementedIface = null;
     this.implementedIfaceMethod = null;
     this.isMethod = isMethod;
     this.isExpandoMethod = (customAttributes != null) && customAttributes.ContainsExpandoAttribute();
     this.isStatic = this.own_scope.isStatic = (attributes & MethodAttributes.Static) != MethodAttributes.PrivateScope;
     this.suppressIL = false;
     this.noVersionSafeAttributeSpecified = true;
     this.fields = this.own_scope.GetLocalFields();
     this.enclosing_scope = enclosing_scope;
     this.must_save_stack_locals = false;
     this.text = null;
     this.mb = null;
     this.cb = null;
     this.attributes = attributes;
     if (!this.isStatic)
     {
         this.attributes |= MethodAttributes.HideBySig;
     }
     this.globals = body.Globals;
     this.superConstructor = null;
     this.superConstructorCall = null;
     this.customAttributes = customAttributes;
     base.noExpando = false;
     this.clsCompliance = CLSComplianceSpec.NotAttributed;
     this.engineLocal = null;
     this.partiallyEvaluated = false;
 }
 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);
 }
 internal override AST PartiallyEvaluate()
 {
     if (base.classob.GetParent() is GlobalScope)
     {
         this.baseType.PartiallyEvaluate();
         IReflect reflect = this.baseType.ToIReflect();
         Type     bt      = null;
         if (!(reflect is Type) || !Microsoft.JScript.Convert.IsPrimitiveIntegerType(bt = (Type)reflect))
         {
             this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum);
             this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
             bt            = Typeob.Int32;
         }
         if (base.customAttributes != null)
         {
             base.customAttributes.PartiallyEvaluate();
         }
         if (base.NeedsToBeCheckedForCLSCompliance())
         {
             if (!TypeExpression.TypeIsCLSCompliant(reflect))
             {
                 this.baseType.context.HandleError(JSError.NonCLSCompliantType);
             }
             base.CheckMemberNamesForCLSCompliance();
         }
         ScriptObject enclosingScope = base.enclosingScope;
         while (!(enclosingScope is GlobalScope) && !(enclosingScope is PackageScope))
         {
             enclosingScope = enclosingScope.GetParent();
         }
         base.classob.SetParent(new WithObject(enclosingScope, Typeob.Enum, true));
         base.Globals.ScopeStack.Push(base.classob);
         try
         {
             JSMemberField[] fields = base.fields;
             for (int i = 0; i < fields.Length; i++)
             {
                 FieldInfo     info  = fields[i];
                 JSMemberField field = (JSMemberField)info;
                 ((DeclaredEnumValue)field.value).CoerceToBaseType(bt, field.originalContext);
             }
         }
         finally
         {
             base.Globals.ScopeStack.Pop();
         }
     }
     return(this);
 }
示例#6
0
 internal ParameterDeclaration(Context context, String identifier, TypeExpression type, CustomAttributeList customAttributes)
   : base() {
   this.identifier = identifier;
   this.type = type == null ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type;
   this.context = context;
   ActivationObject current_scope = (ActivationObject)context.document.engine.Globals.ScopeStack.Peek();
   if (current_scope.name_table[this.identifier] != null)
     //Only happens if there is another parameter declarations with the same name
     context.HandleError(JSError.DuplicateName, this.identifier, current_scope is ClassScope || current_scope.fast || type != null);
   else{
     JSVariableField field = current_scope.AddNewField(this.identifier, null, 0);
     field.originalContext = context;
   }
   this.customAttributes = customAttributes;
 }
 internal JSVariableField(String name, ScriptObject obj, FieldAttributes attributeFlags){
   this.obj = obj;
   this.name = name;
   this.debuggerName = name;
   this.metaData = null;
   if ((attributeFlags & FieldAttributes.FieldAccessMask) == (FieldAttributes)0)
     attributeFlags |= FieldAttributes.Public; //Fields not marked otherwise, are public
   this.attributeFlags = attributeFlags;
   this.type = null;
   this.method = null;
   this.cons = null;
   this.value = null;
   this.originalContext = null;
   this.clsCompliance = CLSComplianceSpec.NotAttributed;
 }
 internal ParameterDeclaration(Context context, string identifier, TypeExpression type, CustomAttributeList customAttributes)
 {
     this.identifier = identifier;
     this.type = (type == null) ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type;
     this.context = context;
     ActivationObject obj2 = (ActivationObject) context.document.engine.Globals.ScopeStack.Peek();
     if (obj2.name_table[this.identifier] != null)
     {
         context.HandleError(JSError.DuplicateName, this.identifier, ((obj2 is ClassScope) || obj2.fast) || (type != null));
     }
     else
     {
         obj2.AddNewField(this.identifier, null, FieldAttributes.PrivateScope).originalContext = context;
     }
     this.customAttributes = customAttributes;
 }
        internal override AST PartiallyEvaluate()
        {
            AST id = this.identifier = (Lookup)this.identifier.PartiallyEvaluateAsReference();

            if (this.type != null)
            {
                this.field.type = this.type = (TypeExpression)this.type.PartiallyEvaluate();
            }
            else if (this.initializer == null && !(this.field is JSLocalField) &&
                     this.field.value is Missing)
            {
                id.context.HandleError(JSError.VariableLeftUninitialized);
                this.field.type = this.type = new TypeExpression(new ConstantWrapper(Typeob.Object, id.context));
            }
            if (this.initializer != null)
            {
                if (this.field.IsStatic)
                {
                    ScriptObject scope  = this.Engine.ScriptObjectStackTop();
                    ClassScope   cscope = null;
                    while (scope != null && (cscope = scope as ClassScope) == null)
                    {
                        scope = scope.GetParent();
                    }
                    if (cscope != null)
                    {
                        cscope.inStaticInitializerCode = true;
                    }
                    this.initializer = this.initializer.PartiallyEvaluate();
                    if (cscope != null)
                    {
                        cscope.inStaticInitializerCode = false;
                    }
                }
                else
                {
                    this.initializer = this.initializer.PartiallyEvaluate();
                }
                id.SetPartialValue(this.initializer);
            }
            // deal with custom attributes
            if (this.field != null && this.field.customAttributes != null)
            {
                this.field.customAttributes.PartiallyEvaluate();
            }
            return(this);
        }
示例#10
0
文件: class.cs 项目: ArildF/masters
 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;
 }
 internal VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes)
   : base(context) {
   if (initializer != null)
     this.context.UpdateWith(initializer.context);
   else if (type != null)
     this.context.UpdateWith(type.context);
   this.identifier = identifier;
   this.type = type;
   this.initializer = initializer;
   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();
   String name = this.identifier.ToString();
   if (current_scope is ClassScope){
     if (name == ((ClassScope)current_scope).name){
       identifier.context.HandleError(JSError.CannotUseNameOfClass);
       name = name + " var";
     }
   }else{
     if (attributes != (FieldAttributes)0){
       this.context.HandleError(JSError.NotInsideClass);
       attributes = FieldAttributes.Public;
     }else
       attributes |= FieldAttributes.Public;
   }
   FieldInfo field = ((IActivationObject)current_scope).GetLocalField(name);
   if (field != null){
     if (field.IsLiteral || current_scope is ClassScope || type != null)
       identifier.context.HandleError(JSError.DuplicateName, true);
     this.type = type = null;
   }
   if (current_scope is ActivationObject)
     if (field == null || field is JSVariableField)
       this.field = ((ActivationObject)current_scope).AddFieldOrUseExistingField(this.identifier.ToString(), Missing.Value, attributes);
     else
       this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), null, attributes);
   else
     this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), null, attributes|FieldAttributes.Static);
   this.field.type = type;
   this.field.customAttributes = customAttributes;
   this.field.originalContext = context;
   if (this.field is JSLocalField)
     // emit debug info for the local only if this block of code is in a section that has debug set
     ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn;
   this.completion = new Completion();
 }
示例#12
0
        internal ParameterDeclaration(Context context, string identifier, TypeExpression type, CustomAttributeList customAttributes)
        {
            this.identifier = identifier;
            this.type       = (type == null) ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type;
            this.context    = context;
            ActivationObject obj2 = (ActivationObject)context.document.engine.Globals.ScopeStack.Peek();

            if (obj2.name_table[this.identifier] != null)
            {
                context.HandleError(JSError.DuplicateName, this.identifier, ((obj2 is ClassScope) || obj2.fast) || (type != null));
            }
            else
            {
                obj2.AddNewField(this.identifier, null, FieldAttributes.PrivateScope).originalContext = context;
            }
            this.customAttributes = customAttributes;
        }
示例#13
0
 internal JSVariableField(string name, ScriptObject obj, FieldAttributes attributeFlags)
 {
     this.obj          = obj;
     this.name         = name;
     this.debuggerName = name;
     this.metaData     = null;
     if ((attributeFlags & FieldAttributes.FieldAccessMask) == FieldAttributes.PrivateScope)
     {
         attributeFlags |= FieldAttributes.Public;
     }
     this.attributeFlags  = attributeFlags;
     this.type            = null;
     this.method          = null;
     this.value           = null;
     this.originalContext = null;
     this.clsCompliance   = CLSComplianceSpec.NotAttributed;
 }
 internal JSVariableField(string name, ScriptObject obj, FieldAttributes attributeFlags)
 {
     this.obj = obj;
     this.name = name;
     this.debuggerName = name;
     this.metaData = null;
     if ((attributeFlags & FieldAttributes.FieldAccessMask) == FieldAttributes.PrivateScope)
     {
         attributeFlags |= FieldAttributes.Public;
     }
     this.attributeFlags = attributeFlags;
     this.type = null;
     this.method = null;
     this.value = null;
     this.originalContext = null;
     this.clsCompliance = CLSComplianceSpec.NotAttributed;
 }
        internal override AST PartiallyEvaluate()
        {
            AST ast = this.identifier = (Lookup)this.identifier.PartiallyEvaluateAsReference();

            if (this.type != null)
            {
                this.field.type = this.type = (TypeExpression)this.type.PartiallyEvaluate();
            }
            else if (((this.initializer == null) && !(this.field is JSLocalField)) && (this.field.value is Microsoft.JScript.Missing))
            {
                ast.context.HandleError(JSError.VariableLeftUninitialized);
                this.field.type = this.type = new TypeExpression(new ConstantWrapper(Typeob.Object, ast.context));
            }
            if (this.initializer != null)
            {
                if (this.field.IsStatic)
                {
                    ScriptObject parent = base.Engine.ScriptObjectStackTop();
                    ClassScope   scope  = null;
                    while ((parent != null) && ((scope = parent as ClassScope) == null))
                    {
                        parent = parent.GetParent();
                    }
                    if (scope != null)
                    {
                        scope.inStaticInitializerCode = true;
                    }
                    this.initializer = this.initializer.PartiallyEvaluate();
                    if (scope != null)
                    {
                        scope.inStaticInitializerCode = false;
                    }
                }
                else
                {
                    this.initializer = this.initializer.PartiallyEvaluate();
                }
                ast.SetPartialValue(this.initializer);
            }
            if ((this.field != null) && (this.field.customAttributes != null))
            {
                this.field.customAttributes.PartiallyEvaluate();
            }
            return(this);
        }
示例#16
0
 internal JSVariableField(String name, ScriptObject obj, FieldAttributes attributeFlags)
 {
     this.obj          = obj;
     this.name         = name;
     this.debuggerName = name;
     this.metaData     = null;
     if ((attributeFlags & FieldAttributes.FieldAccessMask) == (FieldAttributes)0)
     {
         attributeFlags |= FieldAttributes.Public; //Fields not marked otherwise, are public
     }
     this.attributeFlags  = attributeFlags;
     this.type            = null;
     this.method          = null;
     this.cons            = null;
     this.value           = null;
     this.originalContext = null;
     this.clsCompliance   = CLSComplianceSpec.NotAttributed;
 }
示例#17
0
 internal EnumDeclaration(Context context, IdentifierLiteral id, TypeExpression baseType, Block body, FieldAttributes attributes, CustomAttributeList customAttributes)
   : base(context, id, new TypeExpression(new ConstantWrapper(typeof(Enum), null)), new TypeExpression[0], body, attributes, false, false, true, false, customAttributes){
   this.baseType = baseType != null ? baseType : new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
   this.needsEngine = false;
   this.attributes &= TypeAttributes.VisibilityMask;
   TypeExpression thisType = new TypeExpression(new ConstantWrapper(this.classob, this.context));
   AST currentValue = new ConstantWrapper(-1, null);
   AST one = new ConstantWrapper(1, null);
   foreach (FieldInfo f in this.fields){
     JSVariableField field = (JSVariableField)f;
     field.attributeFlags = FieldAttributes.Public|FieldAttributes.Static|FieldAttributes.Literal;
     field.type = thisType;
     if (field.value == null)
       field.value = currentValue = new Plus(currentValue.context, currentValue, one);
     else
       currentValue = (AST)field.value;
     field.value = new EnumWrapper(field.value, field.Name, this.classob);
   }
 }
示例#18
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 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;
        }
示例#19
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;
        }
示例#20
0
 internal override AST PartiallyEvaluate()
 {
     this.operand1 = this.operand1.PartiallyEvaluateAsReference();
     this.operand2 = this.operand2.PartiallyEvaluate();
     this.binOp    = new Plus(this.context, this.operand1, this.operand2);
     this.operand1.SetPartialValue(this.binOp);
     if (this.Engine.doFast)
     {
         Binding b = this.operand1 as Binding;
         if (b != null && b.member is JSVariableField)
         {
             TypeExpression te = ((JSVariableField)b.member).type;
             if (te != null && te.InferType(null) == Typeob.String)
             {
                 this.operand1.context.HandleError(JSError.StringConcatIsSlow);
             }
         }
     }
     return(this);
 }
 internal override AST PartiallyEvaluate()
 {
     base.operand1 = base.operand1.PartiallyEvaluateAsReference();
     base.operand2 = base.operand2.PartiallyEvaluate();
     this.binOp    = new Plus(base.context, base.operand1, base.operand2);
     base.operand1.SetPartialValue(this.binOp);
     if (base.Engine.doFast)
     {
         Binding binding = base.operand1 as Binding;
         if ((binding != null) && (binding.member is JSVariableField))
         {
             TypeExpression type = ((JSVariableField)binding.member).type;
             if ((type != null) && (type.InferType(null) == Typeob.String))
             {
                 base.operand1.context.HandleError(JSError.StringConcatIsSlow);
             }
         }
     }
     return(this);
 }
        internal ParameterDeclaration(Context context, String identifier, TypeExpression type, CustomAttributeList customAttributes)
            : base()
        {
            this.identifier = identifier;
            this.type       = type == null ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type;
            this.context    = context;
            ActivationObject current_scope = (ActivationObject)context.document.engine.Globals.ScopeStack.Peek();

            if (current_scope.name_table[this.identifier] != null)
            {
                //Only happens if there is another parameter declarations with the same name
                context.HandleError(JSError.DuplicateName, this.identifier, current_scope is ClassScope || current_scope.fast || type != null);
            }
            else
            {
                JSVariableField field = current_scope.AddNewField(this.identifier, null, 0);
                field.originalContext = context;
            }
            this.customAttributes = customAttributes;
        }
示例#23
0
    internal override AST PartiallyEvaluate(){
      if (!(this.classob.GetParent() is GlobalScope))
        return this; //The class has already been partially evaluated
          
      this.baseType.PartiallyEvaluate();
      IReflect ir = this.baseType.ToIReflect();
      Type bt = null;
      if (!(ir is Type) || !Convert.IsPrimitiveIntegerType(bt = (Type)ir)){
        this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum);
        this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
        bt = Typeob.Int32;          
      }

      if (this.customAttributes != null)
        this.customAttributes.PartiallyEvaluate();

      if (this.NeedsToBeCheckedForCLSCompliance()){
        if (!TypeExpression.TypeIsCLSCompliant(ir))
          this.baseType.context.HandleError(JSError.NonCLSCompliantType);
        this.CheckMemberNamesForCLSCompliance();
      }
        
      ScriptObject scope = this.enclosingScope;
      while (!(scope is GlobalScope) && !(scope is PackageScope))
        scope = scope.GetParent();
      this.classob.SetParent(new WithObject(scope, typeof(Enum), true));
        
      Globals.ScopeStack.Push(this.classob);
      try{
        foreach (FieldInfo f in this.fields){
          JSMemberField field = (JSMemberField)f;
          ((EnumWrapper)field.value).CoerceToBaseType(bt, field.originalContext);
        }
      }finally{
        Globals.ScopeStack.Pop();
      }
      return this;
    }
示例#24
0
 internal Constant(Context context, Lookup identifier, TypeExpression type, AST value, FieldAttributes attributes, CustomAttributeList customAttributes)
   : base(context){
   this.attributes = attributes | FieldAttributes.InitOnly;
   this.customAttributes = customAttributes;
   this.completion = new Completion();
   this.identifier = identifier;
   this.name = identifier.ToString();
   this.value = value;
   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();
   if (current_scope is ClassScope){
     if (this.name == ((ClassScope)current_scope).name){
       identifier.context.HandleError(JSError.CannotUseNameOfClass);
       this.name = this.name + " const";
     }
     if (attributes == 0) attributes = FieldAttributes.Public;
   }else{
     if (attributes != 0)
       this.context.HandleError(JSError.NotInsideClass);
     attributes = FieldAttributes.Public;
   }
   FieldInfo field = ((IActivationObject)current_scope).GetLocalField(this.name);
   if (field != null){
     identifier.context.HandleError(JSError.DuplicateName, true);
     this.name = this.name + " const";
   }
   if (current_scope is ActivationObject)
     this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), value, attributes);
   else
     this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), value, attributes|FieldAttributes.Static);
   this.field.type = type;
   this.field.customAttributes = customAttributes;
   this.field.originalContext = context;
   if (this.field is JSLocalField)
     // emit debug info for the local only if this block of code is in a section that has debug set
     ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn;
 }
示例#25
0
      //---------------------------------------------------------------------------------------
      // ParseEnum
      //
      //  Enum :
      //    'enum' identifier [':' baseType] EnumBody (in the guise of ClassBody with a param)
      //
      //---------------------------------------------------------------------------------------
      private AST ParseEnum(FieldAttributes visibilitySpec, Context enumCtx, CustomAttributeList customAttributes){
        IdentifierLiteral name = null;
        AST baseId = null;
        TypeExpression baseType = null;
        Block body = null;

        GetNextToken();
        if (JSToken.Identifier == this.currentToken.token){
          name = new IdentifierLiteral(this.scanner.GetIdentifier(), this.currentToken.Clone());
        }else{
          ReportError(JSError.NoIdentifier);
          if (JSToken.Colon != this.currentToken.token && JSToken.LeftCurly != this.currentToken.token)
            SkipTokensAndThrow(); // what the is this?
          name = new IdentifierLiteral("##Missing Enum Name##" + s_cDummyName++, CurrentPositionContext());
        }

        GetNextToken();
        if (JSToken.Colon == this.currentToken.token){
          this.noSkipTokenSet.Add(NoSkipTokenSet.s_EnumBaseTypeNoSkipTokenSet);
          try{
            baseId = ParseQualifiedIdentifier(JSError.NeedType);
          }catch(RecoveryTokenException exc){
            if (IndexOfToken(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet, exc) == -1){
              exc._partiallyComputedNode = null;
              throw exc;
            }else{
              baseId = exc._partiallyComputedNode;
            }
          }finally{
            this.noSkipTokenSet.Remove(NoSkipTokenSet.s_EnumBaseTypeNoSkipTokenSet);
          }
        }
        if (baseId != null)
          baseType = new TypeExpression(baseId);
        if (JSToken.LeftCurly != this.currentToken.token)
          ReportError(JSError.NoLeftCurly);

        // make a new state and save the old one
        ArrayList blockType = this.blockType;
        this.blockType = new ArrayList(16);
        SimpleHashtable labelTable = this.labelTable;
        this.labelTable = new SimpleHashtable(16);

        Globals.ScopeStack.Push(new ClassScope(name, ((IActivationObject)Globals.ScopeStack.Peek()).GetGlobalScope())); //Give declarations a place to go while building AST

        try{
          body = ParseClassBody(true, false);
          enumCtx.UpdateWith(body.context);
          EnumDeclaration result = new EnumDeclaration(enumCtx, name, baseType, body, visibilitySpec, customAttributes);
          if (customAttributes != null) customAttributes.SetTarget(result);
          return result;
        }catch(RecoveryTokenException exc){
          enumCtx.UpdateWith(exc._partiallyComputedNode.context);
          exc._partiallyComputedNode =  new EnumDeclaration(enumCtx, name, baseType, (Block)exc._partiallyComputedNode, visibilitySpec, customAttributes);
          if (customAttributes != null) customAttributes.SetTarget(exc._partiallyComputedNode);
          throw exc;
        }finally{
          Globals.ScopeStack.Pop();
          this.blockType = blockType;
          this.labelTable = labelTable;
        }
      }
        internal VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes)
            : base(context)
        {
            if (initializer != null)
            {
                this.context.UpdateWith(initializer.context);
            }
            else if (type != null)
            {
                this.context.UpdateWith(type.context);
            }
            this.identifier  = identifier;
            this.type        = type;
            this.initializer = initializer;
            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();
            }
            String name = this.identifier.ToString();

            if (current_scope is ClassScope)
            {
                if (name == ((ClassScope)current_scope).name)
                {
                    identifier.context.HandleError(JSError.CannotUseNameOfClass);
                    name = name + " var";
                }
            }
            else
            {
                if (attributes != (FieldAttributes)0)
                {
                    this.context.HandleError(JSError.NotInsideClass);
                    attributes = FieldAttributes.Public;
                }
                else
                {
                    attributes |= FieldAttributes.Public;
                }
            }
            FieldInfo field = ((IActivationObject)current_scope).GetLocalField(name);

            if (field != null)
            {
                if (field.IsLiteral || current_scope is ClassScope || type != null)
                {
                    identifier.context.HandleError(JSError.DuplicateName, true);
                }
                this.type = type = null;
            }
            if (current_scope is ActivationObject)
            {
                if (field == null || field is JSVariableField)
                {
                    this.field = ((ActivationObject)current_scope).AddFieldOrUseExistingField(this.identifier.ToString(), Missing.Value, attributes);
                }
                else
                {
                    this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), null, attributes);
                }
            }
            else
            {
                this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), null, attributes | FieldAttributes.Static);
            }
            this.field.type             = type;
            this.field.customAttributes = customAttributes;
            this.field.originalContext  = context;
            if (this.field is JSLocalField)
            {
                // emit debug info for the local only if this block of code is in a section that has debug set
                ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn;
            }
            this.completion = new Completion();
        }
示例#27
0
文件: class.cs 项目: ArildF/masters
 private void GetIRForSuperType(){
   IReflect supIR = this.superIR = Typeob.Object;
   if (this.superTypeExpression != null){
     this.superTypeExpression.PartiallyEvaluate();
     supIR = this.superIR = this.superTypeExpression.ToIReflect();
   }
   Type supType = supIR as Type;
   if (supType != null){
     if (supType.IsSealed || supType.IsInterface || supType == typeof(ValueType) || supType == Typeob.ArrayObject){
       if (this.superTypeExpression.Evaluate() is Namespace)
         this.superTypeExpression.context.HandleError(JSError.NeedType);
       else
         this.superTypeExpression.context.HandleError(JSError.TypeCannotBeExtended, supType.FullName);
       this.superTypeExpression = null;
       this.superIR = Typeob.Object;
     }else if (typeof(INeedEngine).IsAssignableFrom(supType))
       this.needsEngine = false;
   }else if (supIR is ClassScope){
     if (((ClassScope)supIR).owner.IsASubClassOf(this)){
       this.superTypeExpression.context.HandleError(JSError.CircularDefinition);
       this.superTypeExpression = null;
       this.superIR = Typeob.Object;
     }else{
       this.needsEngine = false;
       this.superClass = ((ClassScope)supIR).owner;
       if ((this.superClass.attributes & TypeAttributes.Sealed) != 0){
         this.superTypeExpression.context.HandleError(JSError.TypeCannotBeExtended, this.superClass.name);
         this.superClass.attributes &= ~TypeAttributes.Sealed;
         this.superTypeExpression = null;
       }else if (this.superClass.isInterface){
         this.superTypeExpression.context.HandleError(JSError.TypeCannotBeExtended, this.superClass.name);
         this.superIR = Typeob.Object;
         this.superTypeExpression = null;
       }
     }
   }else{
     this.superTypeExpression.context.HandleError(JSError.TypeCannotBeExtended);
     this.superIR = Typeob.Object;
     this.superTypeExpression = null;
   }
 }
示例#28
0
文件: class.cs 项目: ArildF/masters
      private void CheckIfValidExtensionOfSuperType(){   
        this.GetIRForSuperType();
        ClassScope csc = this.superIR as ClassScope;
        if (csc != null){
          csc.owner.PartiallyEvaluate();
          if (this.IsStatic){
            if (!csc.owner.IsStatic){
              this.superTypeExpression.context.HandleError(JSError.NestedInstanceTypeCannotBeExtendedByStatic);
              this.superIR = Typeob.Object;
              this.superTypeExpression = null;
            }
          }else{
            if (!csc.owner.IsStatic && this.enclosingScope != csc.owner.enclosingScope){
              this.superTypeExpression.context.HandleError(JSError.NestedInstanceTypeCannotBeExtendedByStatic);
              this.superIR = Typeob.Object;
              this.superTypeExpression = null;
            }
          }
        }
        this.GetSuperTypeMembers();
        this.GetStartIndexForEachName();
        
        bool checkCLSCompliance = this.NeedsToBeCheckedForCLSCompliance();
        if (checkCLSCompliance)
          this.CheckMemberNamesForCLSCompliance();

        //First check only the methods the implement interfaces
        for (int i = 0, n = this.fields.Length; i < n; i++){
          JSMemberField field = this.fields[i];
          if (field.IsLiteral){
            Object value = field.value;
            if (value is FunctionObject){
              JSMemberField startMethod = field;
              while(true){
                FunctionObject func = (FunctionObject)value;
                if (func.implementedIface == null) break;
                this.CheckMethodDeclarationConsistency(func);
                if (func.implementedIfaceMethod == null)
                  func.funcContext.HandleError(JSError.NoMethodInBaseToOverride);
                if (field.IsPublic || field.IsFamily || field.IsFamilyOrAssembly)
                  func.CheckCLSCompliance(checkCLSCompliance);
                field = field.nextOverload;
                if (field == null) break;
                value = field.value;
              }
              continue;
            }else if (value is JSProperty){
              continue;
            }
          }
        }
        for (int i = 0, n = this.fields.Length; i < n; i++){
          JSMemberField field = this.fields[i];
          if (field.IsLiteral){
            Object value = field.value;
            if (value is FunctionObject){
              JSMemberField startMethod = field;
              while(true){
                FunctionObject func = (FunctionObject)value;
                if (func.implementedIface != null) break;
                this.CheckMethodDeclarationConsistency(func);
                if (field.IsPublic || field.IsFamily || field.IsFamilyOrAssembly)
                  func.CheckCLSCompliance(checkCLSCompliance);
                field = field.nextOverload;
                if (field == null) break;
                value = field.value;
              }
              continue;
            }else if (value is JSProperty){
              continue;
            }
          }
          this.CheckFieldDeclarationConsistency(field);
          if (field.IsPublic || field.IsFamily || field.IsFamilyOrAssembly)
            field.CheckCLSCompliance(checkCLSCompliance);
        }
      }
 internal override AST PartiallyEvaluate(){
   AST id = this.identifier = (Lookup)this.identifier.PartiallyEvaluateAsReference();
   if (this.type != null)
     this.field.type = this.type = (TypeExpression)this.type.PartiallyEvaluate();
   else if (this.initializer == null && !(this.field is JSLocalField) &&
   this.field.value is Missing){
     id.context.HandleError(JSError.VariableLeftUninitialized);
     this.field.type = this.type = new TypeExpression(new ConstantWrapper(Typeob.Object, id.context));
   }
   if (this.initializer != null){
     if (this.field.IsStatic){
       ScriptObject scope = this.Engine.ScriptObjectStackTop();
       ClassScope cscope = null;
       while (scope != null && (cscope = scope as ClassScope) == null) scope = scope.GetParent();
       if (cscope != null) cscope.inStaticInitializerCode = true;
       this.initializer = this.initializer.PartiallyEvaluate();
       if (cscope != null) cscope.inStaticInitializerCode = false;
     }else
       this.initializer = this.initializer.PartiallyEvaluate();
     id.SetPartialValue(this.initializer);
   }
   // deal with custom attributes
   if (this.field != null && this.field.customAttributes != null)
     this.field.customAttributes.PartiallyEvaluate();
   return this;
 }
 internal FunctionObject(string name, ParameterDeclaration[] parameter_declarations, TypeExpression return_type_expr, Block body, FunctionScope own_scope, ScriptObject enclosing_scope, Context funcContext, MethodAttributes attributes) : this(name, parameter_declarations, return_type_expr, body, own_scope, enclosing_scope, funcContext, attributes, null, false)
 {
 }
示例#31
0
 internal ParameterDeclaration(Type type, String identifier)
   : base(){
   this.identifier = identifier;
   this.type = new TypeExpression(new ConstantWrapper(type, null));
   this.customAttributes = null;
 }
示例#32
0
 //---------------------------------------------------------------------------------------
 // ParseTypeExpression
 //
 //  TypeExpression :
 //    QualifiedIdentifier |
 //    TypeExpression <no line break> '[' ']'
 //
 //--------------------------------------------------------------------------------------
 private TypeExpression ParseTypeExpression(){
   AST typeId = null;
   try{
     typeId = ParseQualifiedIdentifier(JSError.NeedType);
   }catch(RecoveryTokenException exc){
     if (exc._partiallyComputedNode != null){
       exc._partiallyComputedNode = new TypeExpression(exc._partiallyComputedNode);
     }
     throw exc;
   }
   TypeExpression type = new TypeExpression(typeId);
   if (type != null){
     while (!this.scanner.GotEndOfLine() && JSToken.LeftBracket == this.currentToken.token){
       GetNextToken();
       int rank = 1;
       while (JSToken.Comma == this.currentToken.token){
         GetNextToken(); rank++;
       }
       if (JSToken.RightBracket != this.currentToken.token)
         ReportError(JSError.NoRightBracket);
       GetNextToken();
       if (type.isArray)
         type = new TypeExpression(type);
       type.isArray = true;
       type.rank = rank;
     }
   }
   return type;
 }
 private AST ParseEnum(FieldAttributes visibilitySpec, Context enumCtx, CustomAttributeList customAttributes)
 {
     IdentifierLiteral name = null;
     AST ast = null;
     TypeExpression baseType = null;
     Block body = null;
     AST ast2;
     this.GetNextToken();
     if (JSToken.Identifier == this.currentToken.token)
     {
         name = new IdentifierLiteral(this.scanner.GetIdentifier(), this.currentToken.Clone());
     }
     else
     {
         this.ReportError(JSError.NoIdentifier);
         if ((JSToken.Colon != this.currentToken.token) && (JSToken.LeftCurly != this.currentToken.token))
         {
             this.SkipTokensAndThrow();
         }
         name = new IdentifierLiteral("##Missing Enum Name##" + s_cDummyName++, this.CurrentPositionContext());
     }
     this.GetNextToken();
     if (JSToken.Colon == this.currentToken.token)
     {
         this.noSkipTokenSet.Add(NoSkipTokenSet.s_EnumBaseTypeNoSkipTokenSet);
         try
         {
             ast = this.ParseQualifiedIdentifier(JSError.NeedType);
         }
         catch (RecoveryTokenException exception)
         {
             if (this.IndexOfToken(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet, exception) == -1)
             {
                 exception._partiallyComputedNode = null;
                 throw exception;
             }
             ast = exception._partiallyComputedNode;
         }
         finally
         {
             this.noSkipTokenSet.Remove(NoSkipTokenSet.s_EnumBaseTypeNoSkipTokenSet);
         }
     }
     if (ast != null)
     {
         baseType = new TypeExpression(ast);
     }
     if (JSToken.LeftCurly != this.currentToken.token)
     {
         this.ReportError(JSError.NoLeftCurly);
     }
     ArrayList blockType = this.blockType;
     this.blockType = new ArrayList(0x10);
     SimpleHashtable labelTable = this.labelTable;
     this.labelTable = new SimpleHashtable(0x10);
     this.Globals.ScopeStack.Push(new ClassScope(name, ((IActivationObject) this.Globals.ScopeStack.Peek()).GetGlobalScope()));
     try
     {
         body = this.ParseClassBody(true, false);
         enumCtx.UpdateWith(body.context);
         EnumDeclaration target = new EnumDeclaration(enumCtx, name, baseType, body, visibilitySpec, customAttributes);
         if (customAttributes != null)
         {
             customAttributes.SetTarget(target);
         }
         ast2 = target;
     }
     catch (RecoveryTokenException exception2)
     {
         enumCtx.UpdateWith(exception2._partiallyComputedNode.context);
         exception2._partiallyComputedNode = new EnumDeclaration(enumCtx, name, baseType, (Block) exception2._partiallyComputedNode, visibilitySpec, customAttributes);
         if (customAttributes != null)
         {
             customAttributes.SetTarget(exception2._partiallyComputedNode);
         }
         throw exception2;
     }
     finally
     {
         this.Globals.ScopeStack.Pop();
         this.blockType = blockType;
         this.labelTable = labelTable;
     }
     return ast2;
 }
示例#34
0
      internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, 
                                   Block body, FunctionScope own_scope, FieldAttributes attributes, 
                                   bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes)
        : base(context) {
        MethodAttributes methodAttributes = (MethodAttributes)0;
        if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
          methodAttributes = MethodAttributes.Public;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private)
          methodAttributes = MethodAttributes.Private;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
          methodAttributes = MethodAttributes.Assembly;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family)
          methodAttributes = MethodAttributes.Family;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem)
          methodAttributes = MethodAttributes.FamORAssem;
        else
          methodAttributes = MethodAttributes.Public;

        if ((attributes & FieldAttributes.Static) != 0 || !isMethod)
          methodAttributes |= MethodAttributes.Static;
        else
          methodAttributes |= MethodAttributes.Virtual | MethodAttributes.NewSlot;
        
        if (isAbstract)
          methodAttributes |= MethodAttributes.Abstract;
        if (isFinal)
          methodAttributes |= MethodAttributes.Final;
        
        this.name = id.ToString();
        this.isMethod = isMethod;
        if (ifaceId != null){
          if (isMethod){
            this.ifaceId = new TypeExpression(ifaceId);
            methodAttributes &= ~MethodAttributes.MemberAccessMask;
            methodAttributes |= MethodAttributes.Private|MethodAttributes.Final;
          }else{
            this.declaringObject = new Member(ifaceId.context, ifaceId, id);
            this.name = this.declaringObject.ToString();
          }
        }
        ScriptObject enclosingScope = Globals.ScopeStack.Peek();
        if (attributes == 0 && !isAbstract && !isFinal){
          if (enclosingScope is ClassScope)
            attributes |= FieldAttributes.Public;
        }else{
          if (!(enclosingScope is ClassScope)){
            this.context.HandleError(JSError.NotInsideClass);
            attributes = (FieldAttributes)0;
            methodAttributes = MethodAttributes.Public;
          }
        }
        if (enclosingScope is ActivationObject){
          this.inFastScope = ((ActivationObject)enclosingScope).fast;
          // if later on originalName != this.name this is a property getter/setter
          String originalName = this.name; 
          // mangle the name 
          if (isGetter){
            methodAttributes |= MethodAttributes.SpecialName;
            this.name = "get_" + this.name;
            if (return_type == null)
              return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context));
          }else if (isSetter){
            methodAttributes |= MethodAttributes.SpecialName;
            this.name = "set_" + this.name;
            return_type = new TypeExpression(new ConstantWrapper(Typeob.Void, context));
          }
          attributes &= FieldAttributes.FieldAccessMask;
          // create the function object
          this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, 
                                         methodAttributes, customAttributes, this.isMethod);
          if (this.declaringObject != null) return;
          // check whether the function name (possibly mangled) is in use already
          String fieldName = this.name;
          if (this.ifaceId != null) fieldName = ifaceId.ToString()+"."+fieldName;
          JSVariableField localField = (JSVariableField)((ActivationObject)enclosingScope).name_table[fieldName];
          if (localField != null && (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || this.func.isExpandoMethod)){
            if (originalName != this.name)
              localField.originalContext.HandleError(JSError.ClashWithProperty);
            else{
              id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod);
              if (localField.value is FunctionObject)
                ((FunctionObject)localField.value).suppressIL = true;
            }
          }
          // create or update the proper field
          if (this.isMethod){
            if (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || originalName != this.name){
              this.field = ((ActivationObject)enclosingScope).AddNewField(fieldName, this.func, attributes|FieldAttributes.Literal);
              if (originalName == this.name) // if it is a property do not assign the type
                ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, this.context));
            }else
              this.field = ((JSMemberField)localField).AddOverload(this.func, attributes|FieldAttributes.Literal);
          }else if (enclosingScope is FunctionScope){
            if (this.inFastScope) attributes |= FieldAttributes.Literal;
            this.field = ((FunctionScope)enclosingScope).AddNewField(this.name, attributes, this.func);
            if (this.field is JSLocalField){
              JSLocalField locField = (JSLocalField)this.field;
              if (this.inFastScope){
                locField.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
                locField.attributeFlags |= FieldAttributes.Literal;
              }
              locField.debugOn = this.context.document.debugOn;
              locField.isDefined = true;
            }
          }else if (this.inFastScope){
            this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes|FieldAttributes.Literal);
            ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
            //Do not use typeof(Closure) for the field, since that has the arguments and callee properties, which are not
            //accessible in fast mode
          }else //enclosingScope is GlobalObject
            this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes|FieldAttributes.Static);
          ((JSVariableField)this.field).originalContext = context;
          
          // if it is a property create/update the PropertyInfo and assign the getter/setter
          if (originalName != this.name){
            String propertyFieldName = originalName;
            if (this.ifaceId != null) propertyFieldName = ifaceId.ToString()+"."+originalName;
            FieldInfo prop = (FieldInfo)((ClassScope)enclosingScope).name_table[propertyFieldName];
            if (prop != null){
              // check whether a property was defined already
              if (prop.IsLiteral){
                Object val = ((JSVariableField)prop).value;
                if (val is JSProperty)
                  this.enclosingProperty = (JSProperty)val;
              }
              if (this.enclosingProperty == null)
                id.context.HandleError(JSError.DuplicateName, true); // the matching name was not a property
            }
            if (this.enclosingProperty == null){
              this.enclosingProperty = new JSProperty(originalName);
              prop = ((ActivationObject)enclosingScope).AddNewField(propertyFieldName, this.enclosingProperty, attributes|FieldAttributes.Literal);
              ((JSMemberField)prop).originalContext = this.context;
            }else{
              if ((isGetter && this.enclosingProperty.getter != null) || (isSetter && this.enclosingProperty.setter != null))
                id.context.HandleError(JSError.DuplicateName, true); // duplicated setter or getter
            }
            if (isGetter)
              this.enclosingProperty.getter = new JSFieldMethod(this.field, enclosingScope);
            else
              this.enclosingProperty.setter = new JSFieldMethod(this.field, enclosingScope);
          }
        }else{ //Might get here if function declaration is inside of an eval.
          this.inFastScope = false;
          this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, MethodAttributes.Public, null, false);
          this.field = ((StackFrame)enclosingScope).AddNewField(this.name, new Closure(this.func), attributes|FieldAttributes.Static);
        }
      }
 internal VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context)
 {
     if (initializer != null)
     {
         base.context.UpdateWith(initializer.context);
     }
     else if (type != null)
     {
         base.context.UpdateWith(type.context);
     }
     this.identifier = identifier;
     this.type = type;
     this.initializer = initializer;
     ScriptObject parent = base.Globals.ScopeStack.Peek();
     while (parent is WithObject)
     {
         parent = parent.GetParent();
     }
     string name = this.identifier.ToString();
     if (parent is ClassScope)
     {
         if (name == ((ClassScope) parent).name)
         {
             identifier.context.HandleError(JSError.CannotUseNameOfClass);
             name = name + " var";
         }
     }
     else if (attributes != FieldAttributes.PrivateScope)
     {
         base.context.HandleError(JSError.NotInsideClass);
         attributes = FieldAttributes.Public;
     }
     else
     {
         attributes |= FieldAttributes.Public;
     }
     FieldInfo localField = ((IActivationObject) parent).GetLocalField(name);
     if (localField != null)
     {
         if ((localField.IsLiteral || (parent is ClassScope)) || (type != null))
         {
             identifier.context.HandleError(JSError.DuplicateName, true);
         }
         this.type = (TypeExpression) (type = null);
     }
     if (parent is ActivationObject)
     {
         if ((localField == null) || (localField is JSVariableField))
         {
             this.field = ((ActivationObject) parent).AddFieldOrUseExistingField(this.identifier.ToString(), Microsoft.JScript.Missing.Value, attributes);
         }
         else
         {
             this.field = ((ActivationObject) parent).AddNewField(this.identifier.ToString(), null, attributes);
         }
     }
     else
     {
         this.field = ((StackFrame) parent).AddNewField(this.identifier.ToString(), null, attributes | FieldAttributes.Static);
     }
     this.field.type = type;
     this.field.customAttributes = customAttributes;
     this.field.originalContext = context;
     if (this.field is JSLocalField)
     {
         ((JSLocalField) this.field).debugOn = this.identifier.context.document.debugOn;
     }
     this.completion = new Completion();
 }
示例#36
0
 internal static bool TypeIsCLSCompliant(Object type)
 {
     if (type is ClassScope)
     {
         return(((ClassScope)type).IsCLSCompliant());
     }
     else if (type is TypedArray)
     {
         Object et = ((TypedArray)type).elementType;
         if (et is TypedArray || (et is Type && ((Type)et).IsArray))
         {
             return(false);
         }
         return(TypeExpression.TypeIsCLSCompliant(et));
     }
     else
     {
         Type t = (Type)type;
         if (t.IsPrimitive)
         {
             if (t == Typeob.Boolean ||
                 t == Typeob.Byte ||
                 t == Typeob.Char ||
                 t == Typeob.Double ||
                 t == Typeob.Int16 ||
                 t == Typeob.Int32 ||
                 t == Typeob.Int64 ||
                 t == Typeob.Single)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             if (t.IsArray)
             {
                 Type et = t.GetElementType();
                 if (et.IsArray)
                 {
                     return(false);
                 }
                 return(TypeExpression.TypeIsCLSCompliant(t));
             }
             Object[] attr = t.GetCustomAttributes(Typeob.CLSCompliantAttribute, false);
             if (attr.Length > 0)
             {
                 return(((CLSCompliantAttribute)attr[0]).IsCompliant);
             }
             else
             {
                 Module m = t.Module;
                 attr = m.GetCustomAttributes(Typeob.CLSCompliantAttribute, false);
                 if (attr.Length > 0)
                 {
                     return(((CLSCompliantAttribute)attr[0]).IsCompliant);
                 }
                 else
                 {
                     Assembly a = m.Assembly;
                     attr = a.GetCustomAttributes(Typeob.CLSCompliantAttribute, false);
                     if (attr.Length > 0)
                     {
                         return(((CLSCompliantAttribute)attr[0]).IsCompliant);
                     }
                     else
                     {
                         return(false);
                     }
                 }
             }
         }
     }
 }
示例#37
0
        internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type,
                                     Block body, FunctionScope own_scope, FieldAttributes attributes,
                                     bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes)
            : base(context)
        {
            MethodAttributes methodAttributes = (MethodAttributes)0;

            if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
            {
                methodAttributes = MethodAttributes.Public;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private)
            {
                methodAttributes = MethodAttributes.Private;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
            {
                methodAttributes = MethodAttributes.Assembly;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family)
            {
                methodAttributes = MethodAttributes.Family;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem)
            {
                methodAttributes = MethodAttributes.FamORAssem;
            }
            else
            {
                methodAttributes = MethodAttributes.Public;
            }

            if ((attributes & FieldAttributes.Static) != 0 || !isMethod)
            {
                methodAttributes |= MethodAttributes.Static;
            }
            else
            {
                methodAttributes |= MethodAttributes.Virtual | MethodAttributes.NewSlot;
            }

            if (isAbstract)
            {
                methodAttributes |= MethodAttributes.Abstract;
            }
            if (isFinal)
            {
                methodAttributes |= MethodAttributes.Final;
            }

            this.name     = id.ToString();
            this.isMethod = isMethod;
            if (ifaceId != null)
            {
                if (isMethod)
                {
                    this.ifaceId      = new TypeExpression(ifaceId);
                    methodAttributes &= ~MethodAttributes.MemberAccessMask;
                    methodAttributes |= MethodAttributes.Private | MethodAttributes.Final;
                }
                else
                {
                    this.declaringObject = new Member(ifaceId.context, ifaceId, id);
                    this.name            = this.declaringObject.ToString();
                }
            }
            ScriptObject enclosingScope = Globals.ScopeStack.Peek();

            if (attributes == 0 && !isAbstract && !isFinal)
            {
                if (enclosingScope is ClassScope)
                {
                    attributes |= FieldAttributes.Public;
                }
            }
            else
            {
                if (!(enclosingScope is ClassScope))
                {
                    this.context.HandleError(JSError.NotInsideClass);
                    attributes       = (FieldAttributes)0;
                    methodAttributes = MethodAttributes.Public;
                }
            }
            if (enclosingScope is ActivationObject)
            {
                this.inFastScope = ((ActivationObject)enclosingScope).fast;
                // if later on originalName != this.name this is a property getter/setter
                String originalName = this.name;
                // mangle the name
                if (isGetter)
                {
                    methodAttributes |= MethodAttributes.SpecialName;
                    this.name         = "get_" + this.name;
                    if (return_type == null)
                    {
                        return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context));
                    }
                }
                else if (isSetter)
                {
                    methodAttributes |= MethodAttributes.SpecialName;
                    this.name         = "set_" + this.name;
                    return_type       = new TypeExpression(new ConstantWrapper(Typeob.Void, context));
                }
                attributes &= FieldAttributes.FieldAccessMask;
                // create the function object
                this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context,
                                               methodAttributes, customAttributes, this.isMethod);
                if (this.declaringObject != null)
                {
                    return;
                }
                // check whether the function name (possibly mangled) is in use already
                String fieldName = this.name;
                if (this.ifaceId != null)
                {
                    fieldName = ifaceId.ToString() + "." + fieldName;
                }
                JSVariableField localField = (JSVariableField)((ActivationObject)enclosingScope).name_table[fieldName];
                if (localField != null && (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || this.func.isExpandoMethod))
                {
                    if (originalName != this.name)
                    {
                        localField.originalContext.HandleError(JSError.ClashWithProperty);
                    }
                    else
                    {
                        id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod);
                        if (localField.value is FunctionObject)
                        {
                            ((FunctionObject)localField.value).suppressIL = true;
                        }
                    }
                }
                // create or update the proper field
                if (this.isMethod)
                {
                    if (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || originalName != this.name)
                    {
                        this.field = ((ActivationObject)enclosingScope).AddNewField(fieldName, this.func, attributes | FieldAttributes.Literal);
                        if (originalName == this.name) // if it is a property do not assign the type
                        {
                            ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, this.context));
                        }
                    }
                    else
                    {
                        this.field = ((JSMemberField)localField).AddOverload(this.func, attributes | FieldAttributes.Literal);
                    }
                }
                else if (enclosingScope is FunctionScope)
                {
                    if (this.inFastScope)
                    {
                        attributes |= FieldAttributes.Literal;
                    }
                    this.field = ((FunctionScope)enclosingScope).AddNewField(this.name, attributes, this.func);
                    if (this.field is JSLocalField)
                    {
                        JSLocalField locField = (JSLocalField)this.field;
                        if (this.inFastScope)
                        {
                            locField.type            = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
                            locField.attributeFlags |= FieldAttributes.Literal;
                        }
                        locField.debugOn   = this.context.document.debugOn;
                        locField.isDefined = true;
                    }
                }
                else if (this.inFastScope)
                {
                    this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes | FieldAttributes.Literal);
                    ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
                    //Do not use typeof(Closure) for the field, since that has the arguments and callee properties, which are not
                    //accessible in fast mode
                }
                else //enclosingScope is GlobalObject
                {
                    this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes | FieldAttributes.Static);
                }
                ((JSVariableField)this.field).originalContext = context;

                // if it is a property create/update the PropertyInfo and assign the getter/setter
                if (originalName != this.name)
                {
                    String propertyFieldName = originalName;
                    if (this.ifaceId != null)
                    {
                        propertyFieldName = ifaceId.ToString() + "." + originalName;
                    }
                    FieldInfo prop = (FieldInfo)((ClassScope)enclosingScope).name_table[propertyFieldName];
                    if (prop != null)
                    {
                        // check whether a property was defined already
                        if (prop.IsLiteral)
                        {
                            Object val = ((JSVariableField)prop).value;
                            if (val is JSProperty)
                            {
                                this.enclosingProperty = (JSProperty)val;
                            }
                        }
                        if (this.enclosingProperty == null)
                        {
                            id.context.HandleError(JSError.DuplicateName, true); // the matching name was not a property
                        }
                    }
                    if (this.enclosingProperty == null)
                    {
                        this.enclosingProperty = new JSProperty(originalName);
                        prop = ((ActivationObject)enclosingScope).AddNewField(propertyFieldName, this.enclosingProperty, attributes | FieldAttributes.Literal);
                        ((JSMemberField)prop).originalContext = this.context;
                    }
                    else
                    {
                        if ((isGetter && this.enclosingProperty.getter != null) || (isSetter && this.enclosingProperty.setter != null))
                        {
                            id.context.HandleError(JSError.DuplicateName, true); // duplicated setter or getter
                        }
                    }
                    if (isGetter)
                    {
                        this.enclosingProperty.getter = new JSFieldMethod(this.field, enclosingScope);
                    }
                    else
                    {
                        this.enclosingProperty.setter = new JSFieldMethod(this.field, enclosingScope);
                    }
                }
            }
            else //Might get here if function declaration is inside of an eval.
            {
                this.inFastScope = false;
                this.func        = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, MethodAttributes.Public, null, false);
                this.field       = ((StackFrame)enclosingScope).AddNewField(this.name, new Closure(this.func), attributes | FieldAttributes.Static);
            }
        }
示例#38
0
 internal ParameterDeclaration(Type type, string identifier)
 {
     this.identifier       = identifier;
     this.type             = new TypeExpression(new ConstantWrapper(type, null));
     this.customAttributes = null;
 }
 internal override AST PartiallyEvaluate()
 {
     AST ast = this.identifier = (Lookup) this.identifier.PartiallyEvaluateAsReference();
     if (this.type != null)
     {
         this.field.type = this.type = (TypeExpression) this.type.PartiallyEvaluate();
     }
     else if (((this.initializer == null) && !(this.field is JSLocalField)) && (this.field.value is Microsoft.JScript.Missing))
     {
         ast.context.HandleError(JSError.VariableLeftUninitialized);
         this.field.type = this.type = new TypeExpression(new ConstantWrapper(Typeob.Object, ast.context));
     }
     if (this.initializer != null)
     {
         if (this.field.IsStatic)
         {
             ScriptObject parent = base.Engine.ScriptObjectStackTop();
             ClassScope scope = null;
             while ((parent != null) && ((scope = parent as ClassScope) == null))
             {
                 parent = parent.GetParent();
             }
             if (scope != null)
             {
                 scope.inStaticInitializerCode = true;
             }
             this.initializer = this.initializer.PartiallyEvaluate();
             if (scope != null)
             {
                 scope.inStaticInitializerCode = false;
             }
         }
         else
         {
             this.initializer = this.initializer.PartiallyEvaluate();
         }
         ast.SetPartialValue(this.initializer);
     }
     if ((this.field != null) && (this.field.customAttributes != null))
     {
         this.field.customAttributes.PartiallyEvaluate();
     }
     return this;
 }
示例#40
0
        internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, Block body, FunctionScope own_scope, FieldAttributes attributes, bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes) : base(context)
        {
            this.completion = new Completion();
            MethodAttributes privateScope = MethodAttributes.PrivateScope;

            if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
            {
                privateScope = MethodAttributes.Public;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private)
            {
                privateScope = MethodAttributes.Private;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
            {
                privateScope = MethodAttributes.Assembly;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family)
            {
                privateScope = MethodAttributes.Family;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem)
            {
                privateScope = MethodAttributes.FamORAssem;
            }
            else
            {
                privateScope = MethodAttributes.Public;
            }
            if (((attributes & FieldAttributes.Static) != FieldAttributes.PrivateScope) || !isMethod)
            {
                privateScope |= MethodAttributes.Static;
            }
            else
            {
                privateScope |= MethodAttributes.NewSlot | MethodAttributes.Virtual;
            }
            if (isAbstract)
            {
                privateScope |= MethodAttributes.Abstract;
            }
            if (isFinal)
            {
                privateScope |= MethodAttributes.Final;
            }
            this.name     = id.ToString();
            this.isMethod = isMethod;
            if (ifaceId != null)
            {
                if (isMethod)
                {
                    this.ifaceId  = new TypeExpression(ifaceId);
                    privateScope &= ~MethodAttributes.MemberAccessMask;
                    privateScope |= MethodAttributes.Final | MethodAttributes.Private;
                }
                else
                {
                    this.declaringObject = new Member(ifaceId.context, ifaceId, id);
                    this.name            = this.declaringObject.ToString();
                }
            }
            ScriptObject obj2 = base.Globals.ScopeStack.Peek();

            if (((attributes == FieldAttributes.PrivateScope) && !isAbstract) && !isFinal)
            {
                if (obj2 is ClassScope)
                {
                    attributes |= FieldAttributes.Public;
                }
            }
            else if (!(obj2 is ClassScope))
            {
                base.context.HandleError(JSError.NotInsideClass);
                attributes   = FieldAttributes.PrivateScope;
                privateScope = MethodAttributes.Public;
            }
            if (obj2 is ActivationObject)
            {
                this.inFastScope = ((ActivationObject)obj2).fast;
                string name = this.name;
                if (isGetter)
                {
                    privateScope |= MethodAttributes.SpecialName;
                    this.name     = "get_" + this.name;
                    if (return_type == null)
                    {
                        return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context));
                    }
                }
                else if (isSetter)
                {
                    privateScope |= MethodAttributes.SpecialName;
                    this.name     = "set_" + this.name;
                    return_type   = new TypeExpression(new ConstantWrapper(Typeob.Void, context));
                }
                attributes &= FieldAttributes.FieldAccessMask;
                MethodAttributes attributes3 = privateScope & MethodAttributes.MemberAccessMask;
                if ((((privateScope & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) && ((privateScope & MethodAttributes.Final) == MethodAttributes.PrivateScope)) && (((attributes3 == MethodAttributes.Private) || (attributes3 == MethodAttributes.Assembly)) || (attributes3 == MethodAttributes.FamANDAssem)))
                {
                    privateScope |= MethodAttributes.CheckAccessOnOverride;
                }
                this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, privateScope, customAttributes, this.isMethod);
                if (this.declaringObject == null)
                {
                    string str2 = this.name;
                    if (this.ifaceId != null)
                    {
                        str2 = ifaceId.ToString() + "." + str2;
                    }
                    JSVariableField field = (JSVariableField)((ActivationObject)obj2).name_table[str2];
                    if ((field != null) && ((!(field is JSMemberField) || !(((JSMemberField)field).value is FunctionObject)) || this.func.isExpandoMethod))
                    {
                        if (name != this.name)
                        {
                            field.originalContext.HandleError(JSError.ClashWithProperty);
                        }
                        else
                        {
                            id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod);
                            if (field.value is FunctionObject)
                            {
                                ((FunctionObject)field.value).suppressIL = true;
                            }
                        }
                    }
                    if (this.isMethod)
                    {
                        if ((!(field is JSMemberField) || !(((JSMemberField)field).value is FunctionObject)) || (name != this.name))
                        {
                            this.field = ((ActivationObject)obj2).AddNewField(str2, this.func, attributes | FieldAttributes.Literal);
                            if (name == this.name)
                            {
                                this.field.type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, base.context));
                            }
                        }
                        else
                        {
                            this.field = ((JSMemberField)field).AddOverload(this.func, attributes | FieldAttributes.Literal);
                        }
                    }
                    else if (obj2 is FunctionScope)
                    {
                        if (this.inFastScope)
                        {
                            attributes |= FieldAttributes.Literal;
                        }
                        this.field = ((FunctionScope)obj2).AddNewField(this.name, attributes, this.func);
                        if (this.field is JSLocalField)
                        {
                            JSLocalField field2 = (JSLocalField)this.field;
                            if (this.inFastScope)
                            {
                                field2.type            = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context));
                                field2.attributeFlags |= FieldAttributes.Literal;
                            }
                            field2.debugOn   = base.context.document.debugOn;
                            field2.isDefined = true;
                        }
                    }
                    else if (this.inFastScope)
                    {
                        this.field      = ((ActivationObject)obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Literal);
                        this.field.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context));
                    }
                    else
                    {
                        this.field = ((ActivationObject)obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Static);
                    }
                    this.field.originalContext = context;
                    if (name != this.name)
                    {
                        string str3 = name;
                        if (this.ifaceId != null)
                        {
                            str3 = ifaceId.ToString() + "." + name;
                        }
                        FieldInfo info = (FieldInfo)((ClassScope)obj2).name_table[str3];
                        if (info != null)
                        {
                            if (info.IsLiteral)
                            {
                                object obj3 = ((JSVariableField)info).value;
                                if (obj3 is JSProperty)
                                {
                                    this.enclosingProperty = (JSProperty)obj3;
                                }
                            }
                            if (this.enclosingProperty == null)
                            {
                                id.context.HandleError(JSError.DuplicateName, true);
                            }
                        }
                        if (this.enclosingProperty == null)
                        {
                            this.enclosingProperty = new JSProperty(name);
                            ((JSMemberField)((ActivationObject)obj2).AddNewField(str3, this.enclosingProperty, attributes | FieldAttributes.Literal)).originalContext = base.context;
                        }
                        else if ((isGetter && (this.enclosingProperty.getter != null)) || (isSetter && (this.enclosingProperty.setter != null)))
                        {
                            id.context.HandleError(JSError.DuplicateName, true);
                        }
                        if (isGetter)
                        {
                            this.enclosingProperty.getter = new JSFieldMethod(this.field, obj2);
                        }
                        else
                        {
                            this.enclosingProperty.setter = new JSFieldMethod(this.field, obj2);
                        }
                    }
                }
            }
            else
            {
                this.inFastScope = false;
                this.func        = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, MethodAttributes.Public, null, false);
                this.field       = ((StackFrame)obj2).AddNewField(this.name, new Closure(this.func), attributes | FieldAttributes.Static);
            }
        }
 internal override AST PartiallyEvaluate()
 {
     if (base.classob.GetParent() is GlobalScope)
     {
         this.baseType.PartiallyEvaluate();
         IReflect reflect = this.baseType.ToIReflect();
         Type bt = null;
         if (!(reflect is Type) || !Microsoft.JScript.Convert.IsPrimitiveIntegerType(bt = (Type) reflect))
         {
             this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum);
             this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
             bt = Typeob.Int32;
         }
         if (base.customAttributes != null)
         {
             base.customAttributes.PartiallyEvaluate();
         }
         if (base.NeedsToBeCheckedForCLSCompliance())
         {
             if (!TypeExpression.TypeIsCLSCompliant(reflect))
             {
                 this.baseType.context.HandleError(JSError.NonCLSCompliantType);
             }
             base.CheckMemberNamesForCLSCompliance();
         }
         ScriptObject enclosingScope = base.enclosingScope;
         while (!(enclosingScope is GlobalScope) && !(enclosingScope is PackageScope))
         {
             enclosingScope = enclosingScope.GetParent();
         }
         base.classob.SetParent(new WithObject(enclosingScope, Typeob.Enum, true));
         base.Globals.ScopeStack.Push(base.classob);
         try
         {
             JSMemberField[] fields = base.fields;
             for (int i = 0; i < fields.Length; i++)
             {
                 FieldInfo info = fields[i];
                 JSMemberField field = (JSMemberField) info;
                 ((DeclaredEnumValue) field.value).CoerceToBaseType(bt, field.originalContext);
             }
         }
         finally
         {
             base.Globals.ScopeStack.Pop();
         }
     }
     return this;
 }
示例#42
0
文件: class.cs 项目: ArildF/masters
 private void GetSuperTypeMembers(){
   SuperTypeMembersSorter sorter = new SuperTypeMembersSorter();
   IReflect ir = this.superIR;
   //Add members on superclasses
   while (ir != null){
     sorter.Add(ir.GetMembers(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.Static|BindingFlags.DeclaredOnly));
     if (ir is Type){
       ir = ((Type)ir).BaseType;
     }else{
       ir = ((ClassScope)ir).GetSuperType();
     }
   }
   //Add any implicit interfaces to the end of the explicit list of interfaces
   ArrayList implicitInterfaces = new ArrayList();
   int n = this.interfaces.Length;
   IReflect[] explicitInterfaces = new IReflect[n];
   for (int i = 0; i < n; i++){
     IReflect iface = explicitInterfaces[i] = this.interfaces[i].ToIReflect();
     Type t = iface as Type;
     bool isInterface;
     if (t != null) 
       isInterface = t.IsInterface;
     else{
       ClassScope csc = (ClassScope)iface;
       isInterface = csc.owner.isInterface;
     }
     if (!isInterface) this.interfaces[i].context.HandleError(JSError.NeedInterface);
   }
   foreach (IReflect iface in explicitInterfaces)
     this.AddImplicitInterfaces(iface, explicitInterfaces, implicitInterfaces);
   for (int i = 0; i < implicitInterfaces.Count; i++){
     IReflect iface = (IReflect)implicitInterfaces[i];
     this.AddImplicitInterfaces(iface, explicitInterfaces, implicitInterfaces);
   }
   int m = implicitInterfaces.Count;
   if (m > 0){
     TypeExpression[] newInterfaces = new TypeExpression[n + m];
     for (int i = 0; i < n; i++) newInterfaces[i] = this.interfaces[i];
     for (int i = 0; i < m; i++) newInterfaces[i+n] = new TypeExpression(new ConstantWrapper(implicitInterfaces[i], null));
     this.interfaces = newInterfaces;
   }
   //Add members on interfaces implemented by the class. Also check for circular definition;
   foreach (TypeExpression ifaceExpr in this.interfaces){
     ClassScope ifcsc = ifaceExpr.ToIReflect() as ClassScope;
     if (ifcsc != null && ifcsc.owner.ImplementsInterface(this.classob)){
       this.context.HandleError(JSError.CircularDefinition);
       this.interfaces = new TypeExpression[0];
       break;
     }
     sorter.Add(ifaceExpr.ToIReflect().GetMembers(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance));
   }
   //Add unimplemented members on interfaces implemented by abstract superclasses
   ir = this.superIR;
   while (ir != null){
     Type type = ir as Type;
     if (type != null){
       if (!type.IsAbstract) break;
       Class.GetUnimplementedInferfaceMembersFor(type, sorter);
       ir = type.BaseType;
     }else{
       ClassScope csc = (ClassScope)ir;
       if (!csc.owner.isAbstract) break;
       csc.owner.GetUnimplementedInferfaceMembers(sorter);
       ir = null;
     }
   }
   this.superMembers = sorter.GetMembers();
 }
示例#43
0
        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);
        }
 internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, Block body, FunctionScope own_scope, FieldAttributes attributes, bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes) : base(context)
 {
     this.completion = new Completion();
     MethodAttributes privateScope = MethodAttributes.PrivateScope;
     if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
     {
         privateScope = MethodAttributes.Public;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private)
     {
         privateScope = MethodAttributes.Private;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
     {
         privateScope = MethodAttributes.Assembly;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family)
     {
         privateScope = MethodAttributes.Family;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem)
     {
         privateScope = MethodAttributes.FamORAssem;
     }
     else
     {
         privateScope = MethodAttributes.Public;
     }
     if (((attributes & FieldAttributes.Static) != FieldAttributes.PrivateScope) || !isMethod)
     {
         privateScope |= MethodAttributes.Static;
     }
     else
     {
         privateScope |= MethodAttributes.NewSlot | MethodAttributes.Virtual;
     }
     if (isAbstract)
     {
         privateScope |= MethodAttributes.Abstract;
     }
     if (isFinal)
     {
         privateScope |= MethodAttributes.Final;
     }
     this.name = id.ToString();
     this.isMethod = isMethod;
     if (ifaceId != null)
     {
         if (isMethod)
         {
             this.ifaceId = new TypeExpression(ifaceId);
             privateScope &= ~MethodAttributes.MemberAccessMask;
             privateScope |= MethodAttributes.Final | MethodAttributes.Private;
         }
         else
         {
             this.declaringObject = new Member(ifaceId.context, ifaceId, id);
             this.name = this.declaringObject.ToString();
         }
     }
     ScriptObject obj2 = base.Globals.ScopeStack.Peek();
     if (((attributes == FieldAttributes.PrivateScope) && !isAbstract) && !isFinal)
     {
         if (obj2 is ClassScope)
         {
             attributes |= FieldAttributes.Public;
         }
     }
     else if (!(obj2 is ClassScope))
     {
         base.context.HandleError(JSError.NotInsideClass);
         attributes = FieldAttributes.PrivateScope;
         privateScope = MethodAttributes.Public;
     }
     if (obj2 is ActivationObject)
     {
         this.inFastScope = ((ActivationObject) obj2).fast;
         string name = this.name;
         if (isGetter)
         {
             privateScope |= MethodAttributes.SpecialName;
             this.name = "get_" + this.name;
             if (return_type == null)
             {
                 return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context));
             }
         }
         else if (isSetter)
         {
             privateScope |= MethodAttributes.SpecialName;
             this.name = "set_" + this.name;
             return_type = new TypeExpression(new ConstantWrapper(Typeob.Void, context));
         }
         attributes &= FieldAttributes.FieldAccessMask;
         MethodAttributes attributes3 = privateScope & MethodAttributes.MemberAccessMask;
         if ((((privateScope & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) && ((privateScope & MethodAttributes.Final) == MethodAttributes.PrivateScope)) && (((attributes3 == MethodAttributes.Private) || (attributes3 == MethodAttributes.Assembly)) || (attributes3 == MethodAttributes.FamANDAssem)))
         {
             privateScope |= MethodAttributes.CheckAccessOnOverride;
         }
         this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, privateScope, customAttributes, this.isMethod);
         if (this.declaringObject == null)
         {
             string str2 = this.name;
             if (this.ifaceId != null)
             {
                 str2 = ifaceId.ToString() + "." + str2;
             }
             JSVariableField field = (JSVariableField) ((ActivationObject) obj2).name_table[str2];
             if ((field != null) && ((!(field is JSMemberField) || !(((JSMemberField) field).value is FunctionObject)) || this.func.isExpandoMethod))
             {
                 if (name != this.name)
                 {
                     field.originalContext.HandleError(JSError.ClashWithProperty);
                 }
                 else
                 {
                     id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod);
                     if (field.value is FunctionObject)
                     {
                         ((FunctionObject) field.value).suppressIL = true;
                     }
                 }
             }
             if (this.isMethod)
             {
                 if ((!(field is JSMemberField) || !(((JSMemberField) field).value is FunctionObject)) || (name != this.name))
                 {
                     this.field = ((ActivationObject) obj2).AddNewField(str2, this.func, attributes | FieldAttributes.Literal);
                     if (name == this.name)
                     {
                         this.field.type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, base.context));
                     }
                 }
                 else
                 {
                     this.field = ((JSMemberField) field).AddOverload(this.func, attributes | FieldAttributes.Literal);
                 }
             }
             else if (obj2 is FunctionScope)
             {
                 if (this.inFastScope)
                 {
                     attributes |= FieldAttributes.Literal;
                 }
                 this.field = ((FunctionScope) obj2).AddNewField(this.name, attributes, this.func);
                 if (this.field is JSLocalField)
                 {
                     JSLocalField field2 = (JSLocalField) this.field;
                     if (this.inFastScope)
                     {
                         field2.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context));
                         field2.attributeFlags |= FieldAttributes.Literal;
                     }
                     field2.debugOn = base.context.document.debugOn;
                     field2.isDefined = true;
                 }
             }
             else if (this.inFastScope)
             {
                 this.field = ((ActivationObject) obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Literal);
                 this.field.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context));
             }
             else
             {
                 this.field = ((ActivationObject) obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Static);
             }
             this.field.originalContext = context;
             if (name != this.name)
             {
                 string str3 = name;
                 if (this.ifaceId != null)
                 {
                     str3 = ifaceId.ToString() + "." + name;
                 }
                 FieldInfo info = (FieldInfo) ((ClassScope) obj2).name_table[str3];
                 if (info != null)
                 {
                     if (info.IsLiteral)
                     {
                         object obj3 = ((JSVariableField) info).value;
                         if (obj3 is JSProperty)
                         {
                             this.enclosingProperty = (JSProperty) obj3;
                         }
                     }
                     if (this.enclosingProperty == null)
                     {
                         id.context.HandleError(JSError.DuplicateName, true);
                     }
                 }
                 if (this.enclosingProperty == null)
                 {
                     this.enclosingProperty = new JSProperty(name);
                     ((JSMemberField) ((ActivationObject) obj2).AddNewField(str3, this.enclosingProperty, attributes | FieldAttributes.Literal)).originalContext = base.context;
                 }
                 else if ((isGetter && (this.enclosingProperty.getter != null)) || (isSetter && (this.enclosingProperty.setter != null)))
                 {
                     id.context.HandleError(JSError.DuplicateName, true);
                 }
                 if (isGetter)
                 {
                     this.enclosingProperty.getter = new JSFieldMethod(this.field, obj2);
                 }
                 else
                 {
                     this.enclosingProperty.setter = new JSFieldMethod(this.field, obj2);
                 }
             }
         }
     }
     else
     {
         this.inFastScope = false;
         this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, MethodAttributes.Public, null, false);
         this.field = ((StackFrame) obj2).AddNewField(this.name, new Closure(this.func), attributes | FieldAttributes.Static);
     }
 }
        internal VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context)
        {
            if (initializer != null)
            {
                base.context.UpdateWith(initializer.context);
            }
            else if (type != null)
            {
                base.context.UpdateWith(type.context);
            }
            this.identifier  = identifier;
            this.type        = type;
            this.initializer = initializer;
            ScriptObject parent = base.Globals.ScopeStack.Peek();

            while (parent is WithObject)
            {
                parent = parent.GetParent();
            }
            string name = this.identifier.ToString();

            if (parent is ClassScope)
            {
                if (name == ((ClassScope)parent).name)
                {
                    identifier.context.HandleError(JSError.CannotUseNameOfClass);
                    name = name + " var";
                }
            }
            else if (attributes != FieldAttributes.PrivateScope)
            {
                base.context.HandleError(JSError.NotInsideClass);
                attributes = FieldAttributes.Public;
            }
            else
            {
                attributes |= FieldAttributes.Public;
            }
            FieldInfo localField = ((IActivationObject)parent).GetLocalField(name);

            if (localField != null)
            {
                if ((localField.IsLiteral || (parent is ClassScope)) || (type != null))
                {
                    identifier.context.HandleError(JSError.DuplicateName, true);
                }
                this.type = (TypeExpression)(type = null);
            }
            if (parent is ActivationObject)
            {
                if ((localField == null) || (localField is JSVariableField))
                {
                    this.field = ((ActivationObject)parent).AddFieldOrUseExistingField(this.identifier.ToString(), Microsoft.JScript.Missing.Value, attributes);
                }
                else
                {
                    this.field = ((ActivationObject)parent).AddNewField(this.identifier.ToString(), null, attributes);
                }
            }
            else
            {
                this.field = ((StackFrame)parent).AddNewField(this.identifier.ToString(), null, attributes | FieldAttributes.Static);
            }
            this.field.type             = type;
            this.field.customAttributes = customAttributes;
            this.field.originalContext  = context;
            if (this.field is JSLocalField)
            {
                ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn;
            }
            this.completion = new Completion();
        }
 private TypeExpression ParseTypeExpression()
 {
     AST ast = null;
     try
     {
         ast = this.ParseQualifiedIdentifier(JSError.NeedType);
     }
     catch (RecoveryTokenException exception)
     {
         if (exception._partiallyComputedNode != null)
         {
             exception._partiallyComputedNode = new TypeExpression(exception._partiallyComputedNode);
         }
         throw exception;
     }
     TypeExpression expression = new TypeExpression(ast);
     if (expression != null)
     {
         while (!this.scanner.GotEndOfLine() && (JSToken.LeftBracket == this.currentToken.token))
         {
             this.GetNextToken();
             int num = 1;
             while (JSToken.Comma == this.currentToken.token)
             {
                 this.GetNextToken();
                 num++;
             }
             if (JSToken.RightBracket != this.currentToken.token)
             {
                 this.ReportError(JSError.NoRightBracket);
             }
             this.GetNextToken();
             if (expression.isArray)
             {
                 expression = new TypeExpression(expression);
             }
             expression.isArray = true;
             expression.rank = num;
         }
     }
     return expression;
 }
示例#47
0
        // has to be called after partially evaluate
        internal bool IsCLSCompliant()
        {
            Object value = this.expression.Evaluate();

            return(TypeExpression.TypeIsCLSCompliant(value));
        }
 private AST ParseClass(FieldAttributes visibilitySpec, bool isStatic, Context classCtx, bool isAbstract, bool isFinal, CustomAttributeList customAttributes)
 {
     AST name = null;
     AST ast2 = null;
     TypeExpression superTypeExpression = null;
     Block body = null;
     TypeExpression[] expressionArray;
     AST ast4;
     ArrayList list = new ArrayList();
     bool isInterface = JSToken.Interface == this.currentToken.token;
     this.GetNextToken();
     if (JSToken.Identifier == this.currentToken.token)
     {
         name = new IdentifierLiteral(this.scanner.GetIdentifier(), this.currentToken.Clone());
     }
     else
     {
         this.ReportError(JSError.NoIdentifier);
         if (((JSToken.Extends != this.currentToken.token) && (JSToken.Implements != this.currentToken.token)) && (JSToken.LeftCurly != this.currentToken.token))
         {
             this.SkipTokensAndThrow();
         }
         name = new IdentifierLiteral("##Missing Class Name##" + s_cDummyName++, this.CurrentPositionContext());
     }
     this.GetNextToken();
     if ((JSToken.Extends == this.currentToken.token) || (JSToken.Implements == this.currentToken.token))
     {
         if (isInterface && (JSToken.Extends == this.currentToken.token))
         {
             this.currentToken.token = JSToken.Implements;
         }
         if (JSToken.Extends == this.currentToken.token)
         {
             this.noSkipTokenSet.Add(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet);
             try
             {
                 ast2 = this.ParseQualifiedIdentifier(JSError.NeedType);
             }
             catch (RecoveryTokenException exception)
             {
                 if (this.IndexOfToken(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet, exception) == -1)
                 {
                     exception._partiallyComputedNode = null;
                     throw exception;
                 }
                 ast2 = exception._partiallyComputedNode;
             }
             finally
             {
                 this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet);
             }
         }
         if (JSToken.Implements == this.currentToken.token)
         {
             do
             {
                 AST expression = null;
                 this.noSkipTokenSet.Add(NoSkipTokenSet.s_ClassImplementsNoSkipTokenSet);
                 try
                 {
                     expression = this.ParseQualifiedIdentifier(JSError.NeedType);
                     list.Add(new TypeExpression(expression));
                 }
                 catch (RecoveryTokenException exception2)
                 {
                     if (this.IndexOfToken(NoSkipTokenSet.s_ClassImplementsNoSkipTokenSet, exception2) == -1)
                     {
                         exception2._partiallyComputedNode = null;
                         throw exception2;
                     }
                     if (exception2._partiallyComputedNode != null)
                     {
                         list.Add(new TypeExpression(exception2._partiallyComputedNode));
                     }
                 }
                 finally
                 {
                     this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ClassImplementsNoSkipTokenSet);
                 }
             }
             while (JSToken.Comma == this.currentToken.token);
         }
     }
     if (ast2 != null)
     {
         superTypeExpression = new TypeExpression(ast2);
     }
     if (JSToken.LeftCurly != this.currentToken.token)
     {
         this.ReportError(JSError.NoLeftCurly);
     }
     ArrayList blockType = this.blockType;
     this.blockType = new ArrayList(0x10);
     SimpleHashtable labelTable = this.labelTable;
     this.labelTable = new SimpleHashtable(0x10);
     this.Globals.ScopeStack.Push(new ClassScope(name, ((IActivationObject) this.Globals.ScopeStack.Peek()).GetGlobalScope()));
     try
     {
         body = this.ParseClassBody(false, isInterface);
         classCtx.UpdateWith(body.context);
         expressionArray = new TypeExpression[list.Count];
         list.CopyTo(expressionArray);
         Class target = new Class(classCtx, name, superTypeExpression, expressionArray, body, visibilitySpec, isAbstract, isFinal, isStatic, isInterface, customAttributes);
         if (customAttributes != null)
         {
             customAttributes.SetTarget(target);
         }
         ast4 = target;
     }
     catch (RecoveryTokenException exception3)
     {
         classCtx.UpdateWith(exception3._partiallyComputedNode.context);
         expressionArray = new TypeExpression[list.Count];
         list.CopyTo(expressionArray);
         exception3._partiallyComputedNode = new Class(classCtx, name, superTypeExpression, expressionArray, (Block) exception3._partiallyComputedNode, visibilitySpec, isAbstract, isFinal, isStatic, isInterface, customAttributes);
         if (customAttributes != null)
         {
             customAttributes.SetTarget(exception3._partiallyComputedNode);
         }
         throw exception3;
     }
     finally
     {
         this.Globals.ScopeStack.Pop();
         this.blockType = blockType;
         this.labelTable = labelTable;
     }
     return ast4;
 }
示例#49
0
      //---------------------------------------------------------------------------------------
      // ParseClass
      //
      //  Class :
      //    'class' identifier OptionalExtends ClassBody
      //
      //  Extends :
      //    'extends' QualifiedIdentifier
      //
      //---------------------------------------------------------------------------------------
      private AST ParseClass(FieldAttributes visibilitySpec, bool isStatic, Context classCtx, bool isAbstract, bool isFinal, CustomAttributeList customAttributes){
        AST name = null;
        AST baseId = null;
        TypeExpression baseType = null;
        Block body = null;
        ArrayList interfaces = new ArrayList();

        bool isInterface = JSToken.Interface == this.currentToken.token;

        GetNextToken();
        if (JSToken.Identifier == this.currentToken.token){
          name = new IdentifierLiteral(this.scanner.GetIdentifier(), this.currentToken.Clone());
        }else{
          ReportError(JSError.NoIdentifier);
          if (JSToken.Extends != this.currentToken.token
              &&  JSToken.Implements != this.currentToken.token
              &&  JSToken.LeftCurly != this.currentToken.token)
            SkipTokensAndThrow(); // what the is this?
          name = new IdentifierLiteral("##Missing Class Name##" + s_cDummyName++, CurrentPositionContext());
        }

        GetNextToken();
        if (JSToken.Extends == this.currentToken.token || JSToken.Implements == this.currentToken.token){
          if (isInterface && JSToken.Extends == this.currentToken.token)
            this.currentToken.token = JSToken.Implements;
          if (JSToken.Extends == this.currentToken.token){
            this.noSkipTokenSet.Add(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet);
            try{
              baseId = ParseQualifiedIdentifier(JSError.NeedType);
            }catch(RecoveryTokenException exc){
              if (IndexOfToken(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet, exc) == -1){
                exc._partiallyComputedNode = null;
                throw exc;
              }else{
                baseId = exc._partiallyComputedNode;
              }
            }finally{
              this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ClassExtendsNoSkipTokenSet);
            }
          }
          if (JSToken.Implements == this.currentToken.token){
            do{
              AST typeId = null;
              this.noSkipTokenSet.Add(NoSkipTokenSet.s_ClassImplementsNoSkipTokenSet);
              try{
                typeId = ParseQualifiedIdentifier(JSError.NeedType);
                interfaces.Add(new TypeExpression(typeId));
              }catch(RecoveryTokenException exc){
                if (IndexOfToken(NoSkipTokenSet.s_ClassImplementsNoSkipTokenSet, exc) == -1){
                  exc._partiallyComputedNode = null;
                  throw exc;
                }else{
                  if (exc._partiallyComputedNode != null)
                    interfaces.Add(new TypeExpression(exc._partiallyComputedNode));
                }
              }finally{
                this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ClassImplementsNoSkipTokenSet);
              }
            }while (JSToken.Comma == this.currentToken.token);
          }
        }
        if (baseId != null)
          baseType = new TypeExpression(baseId);
        if (JSToken.LeftCurly != this.currentToken.token){
          ReportError(JSError.NoLeftCurly);
        }

        // make a new state and save the old one
        ArrayList blockType = this.blockType;
        this.blockType = new ArrayList(16);
        SimpleHashtable labelTable = this.labelTable;
        this.labelTable = new SimpleHashtable(16);

        Globals.ScopeStack.Push(new ClassScope(name, ((IActivationObject)Globals.ScopeStack.Peek()).GetGlobalScope())); //Give declarations a place to go while building AST

        TypeExpression[] ifaces;
        try{
          body = ParseClassBody(false, isInterface);
          classCtx.UpdateWith(body.context);
          ifaces = new TypeExpression[interfaces.Count]; interfaces.CopyTo(ifaces);
          Class result = new Class(classCtx, name, baseType, ifaces, body, visibilitySpec, isAbstract, isFinal, isStatic, isInterface, customAttributes);
          if (customAttributes != null) customAttributes.SetTarget(result);
          return result;
        }catch(RecoveryTokenException exc){
          classCtx.UpdateWith(exc._partiallyComputedNode.context);
          ifaces = new TypeExpression[interfaces.Count]; interfaces.CopyTo(ifaces);
          exc._partiallyComputedNode =
            new Class(classCtx, name, baseType, ifaces, (Block)exc._partiallyComputedNode, visibilitySpec, isAbstract, isFinal, isStatic, isInterface, customAttributes);
          if (customAttributes != null) customAttributes.SetTarget(exc._partiallyComputedNode);
          throw exc;
        }finally{
          Globals.ScopeStack.Pop();
          this.blockType = blockType;
          this.labelTable = labelTable;
        }

      }