internal override AST PartiallyEvaluate(){ this.ctor = this.ctor.PartiallyEvaluateAsCallable(); //first weed out assignment expressions and use them as property initializers ASTList positionalArgs = new ASTList(this.args.context); ASTList namedArgs = new ASTList(this.args.context); for (int i = 0, m = this.args.count; i < m; i++){ AST arg = this.args[i]; Assign assign = arg as Assign; if (assign != null){ assign.rhside = assign.rhside.PartiallyEvaluate(); namedArgs.Append(assign); }else positionalArgs.Append(arg.PartiallyEvaluate()); } int n = positionalArgs.count; IReflect[] argIRs = new IReflect[n]; for (int i = 0; i < n; i++){ AST arg = positionalArgs[i]; // only accept ConstantWrappers if (arg is ConstantWrapper){ Object argument = arg.Evaluate(); if ((argIRs[i] = CustomAttribute.TypeOfArgument(argument)) != null){ this.positionalArgValues.Add(argument); continue; } }else if (arg is ArrayLiteral && ((ArrayLiteral)arg).IsOkToUseInCustomAttribute()){ argIRs[i] = Typeob.ArrayObject; this.positionalArgValues.Add(arg.Evaluate()); continue; } arg.context.HandleError(JSError.InvalidCustomAttributeArgument); return null; // the custom attribute is not good and it will be ignored } //Get the custom attribute and the appropriate constructor (under the covers) this.type = this.ctor.ResolveCustomAttribute(positionalArgs, argIRs, this.target); if (this.type == null) return null; if (Convert.IsPromotableTo((IReflect)this.type, Typeob.CodeAccessSecurityAttribute)){ this.context.HandleError(JSError.CannotUseStaticSecurityAttribute); return null; } //Coerce the positional arguments to the right type and supply default values for optional parameters ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member; ParameterInfo[] parameters = c.GetParameters(); int j = 0; int len = this.positionalArgValues.Count; foreach (ParameterInfo p in parameters){ IReflect ir = p is ParameterDeclaration ? ((ParameterDeclaration)p).ParameterIReflect : p.ParameterType; if (j < len ){ Object value = this.positionalArgValues[j]; this.positionalArgValues[j] = Convert.Coerce(value, ir, value is ArrayObject); j++; }else{ Object value; if (TypeReferences.GetDefaultParameterValue(p) == System.Convert.DBNull){ value = Convert.Coerce(null, ir); }else value = TypeReferences.GetDefaultParameterValue(p); this.positionalArgValues.Add(value); } } //Check validity of property/field initializers for (int i = 0, m = namedArgs.count; i < m; i++){ Assign assign = (Assign)namedArgs[i]; if (assign.lhside is Lookup && (assign.rhside is ConstantWrapper || (assign.rhside is ArrayLiteral && ((ArrayLiteral)assign.rhside).IsOkToUseInCustomAttribute()))){ Object value = assign.rhside.Evaluate(); IReflect argType = null; if (value is ArrayObject || ((argType = CustomAttribute.TypeOfArgument(value)) != null && argType != Typeob.Object)){ String name = ((Lookup)assign.lhside).Name; MemberInfo [] members = ((IReflect)this.type).GetMember(name, BindingFlags.Public|BindingFlags.Instance); if (members == null || members.Length == 0){ assign.context.HandleError(JSError.NoSuchMember); return null; } if (members.Length == 1){ MemberInfo member = members[0]; if (member is FieldInfo){ FieldInfo fieldInfo = (FieldInfo)member; if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly){ try{ IReflect ir = fieldInfo is JSVariableField ? ((JSVariableField)fieldInfo).GetInferredType(null) : fieldInfo.FieldType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgFields.Add(member); this.namedArgFieldValues.Add(value); continue; }catch(JScriptException){ assign.rhside.context.HandleError(JSError.TypeMismatch); return null; // the custom attribute is not good and it will be ignored } } }else if (member is PropertyInfo){ PropertyInfo propertyInfo = (PropertyInfo)member; MethodInfo setMethodInfo = JSProperty.GetSetMethod(propertyInfo, false); if (setMethodInfo != null){ ParameterInfo [] paramInfo = setMethodInfo.GetParameters(); if (paramInfo != null && paramInfo.Length == 1){ try{ IReflect ir = paramInfo[0] is ParameterDeclaration ? ((ParameterDeclaration)paramInfo[0]).ParameterIReflect : paramInfo[0].ParameterType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgProperties.Add(member); this.namedArgPropertyValues.Add(value); }catch(JScriptException){ assign.rhside.context.HandleError(JSError.TypeMismatch); return null; // the custom attribute is not good and it will be ignored } continue; } } } } } } assign.context.HandleError(JSError.InvalidCustomAttributeArgument); return null; } if (!this.CheckIfTargetOK(this.type)) return null; //Ignore attribute //Consume and discard assembly name attributes try{ Type ty = this.type as Type; if (ty != null && this.target is AssemblyCustomAttributeList){ if (ty.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute"){ if (this.positionalArgValues.Count > 0) this.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm)); return null; } if (ty.FullName == "System.Reflection.AssemblyCultureAttribute"){ if (this.positionalArgValues.Count > 0){ String cultureId = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.PEFileKind != PEFileKinds.Dll && cultureId.Length > 0){ this.context.HandleError(JSError.ExecutablesCannotBeLocalized); return null; } this.Engine.Globals.assemblyCulture = new CultureInfo(cultureId); } return null; } if (ty.FullName == "System.Reflection.AssemblyDelaySignAttribute"){ if (this.positionalArgValues.Count > 0) this.Engine.Globals.assemblyDelaySign = Convert.ToBoolean(this.positionalArgValues[0], false); return null; } if (ty.FullName == "System.Reflection.AssemblyFlagsAttribute"){ if (this.positionalArgValues.Count > 0) this.Engine.Globals.assemblyFlags = (AssemblyFlags)(uint)Convert.CoerceT(this.positionalArgValues[0], typeof(uint)); return null; } if (ty.FullName == "System.Reflection.AssemblyKeyFileAttribute"){ if (this.positionalArgValues.Count > 0){ this.Engine.Globals.assemblyKeyFileName = Convert.ToString(this.positionalArgValues[0]); this.Engine.Globals.assemblyKeyFileNameContext = this.context; if (this.Engine.Globals.assemblyKeyFileName != null && this.Engine.Globals.assemblyKeyFileName.Length == 0) { this.Engine.Globals.assemblyKeyFileName = null; this.Engine.Globals.assemblyKeyFileNameContext = null; } } return null; } if (ty.FullName == "System.Reflection.AssemblyKeyNameAttribute"){ if (this.positionalArgValues.Count > 0){ this.Engine.Globals.assemblyKeyName = Convert.ToString(this.positionalArgValues[0]); this.Engine.Globals.assemblyKeyNameContext = this.context; if (this.Engine.Globals.assemblyKeyName != null && this.Engine.Globals.assemblyKeyName.Length == 0) { this.Engine.Globals.assemblyKeyName = null; this.Engine.Globals.assemblyKeyNameContext = null; } } return null; } if (ty.FullName == "System.Reflection.AssemblyVersionAttribute"){ if (this.positionalArgValues.Count > 0) this.Engine.Globals.assemblyVersion = this.ParseVersion(Convert.ToString(this.positionalArgValues[0])); return null; } if (ty.FullName == "System.CLSCompliantAttribute"){ this.Engine.isCLSCompliant = this.args == null || this.args.count == 0 || Convert.ToBoolean(this.positionalArgValues[0], false); return this; } } }catch(ArgumentException){ this.context.HandleError(JSError.InvalidCall); } return this; }
//--------------------------------------------------------------------------------------- // ParseExpressionList // // Given a starting this.currentToken '(' or '[', parse a list of expression separated by // ',' until matching ')' or ']' //--------------------------------------------------------------------------------------- private ASTList ParseExpressionList(JSToken terminator){ Context listCtx = this.currentToken.Clone(); int line = this.scanner.GetCurrentLine(); GetNextToken(); ASTList list = new ASTList(listCtx); if (terminator != this.currentToken.token){ for (;;){ this.noSkipTokenSet.Add(NoSkipTokenSet.s_ExpressionListNoSkipTokenSet); try{ if (JSToken.BitwiseAnd == this.currentToken.token){ // address of operator Context addressOfCtx = this.currentToken.Clone(); GetNextToken(); AST lhexpr = ParseLeftHandSideExpression(); if (lhexpr is Member || lhexpr is Lookup){ addressOfCtx.UpdateWith(lhexpr.context); list.Append(new AddressOf(addressOfCtx, lhexpr)); }else{ ReportError(JSError.DoesNotHaveAnAddress, addressOfCtx.Clone()); list.Append(lhexpr); } }else if (JSToken.Comma == this.currentToken.token){ list.Append(new ConstantWrapper(System.Reflection.Missing.Value, this.currentToken.Clone())); }else if (terminator == this.currentToken.token){ break; }else list.Append(ParseExpression(true)); if (terminator == this.currentToken.token) break; else{ if (JSToken.Comma != this.currentToken.token){ if (terminator == JSToken.RightParen){ // in ASP+ it's easy to write a semicolon at the end of an expression // not realizing it is going to go inside a function call // (ie. Response.Write()), so make a special check here if (JSToken.Semicolon == this.currentToken.token){ if (JSToken.RightParen == this.scanner.PeekToken()){ ReportError(JSError.UnexpectedSemicolon, true); GetNextToken(); break; } } ReportError(JSError.NoRightParenOrComma); }else ReportError(JSError.NoRightBracketOrComma); SkipTokensAndThrow(); } } }catch(RecoveryTokenException exc){ if (exc._partiallyComputedNode != null) list.Append(exc._partiallyComputedNode); if (IndexOfToken(NoSkipTokenSet.s_ExpressionListNoSkipTokenSet, exc) == -1){ exc._partiallyComputedNode = list; throw exc; } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ExpressionListNoSkipTokenSet); } GetNextToken(); } } listCtx.UpdateWith(this.currentToken); return list; }
internal override AST PartiallyEvaluate() { this.ctor = this.ctor.PartiallyEvaluateAsCallable(); ASTList args = new ASTList(this.args.context); ASTList list2 = new ASTList(this.args.context); int num = 0; int count = this.args.count; while (num < count) { AST ast = this.args[num]; Assign elem = ast as Assign; if (elem != null) { elem.rhside = elem.rhside.PartiallyEvaluate(); list2.Append(elem); } else { args.Append(ast.PartiallyEvaluate()); } num++; } int num3 = args.count; IReflect[] argIRs = new IReflect[num3]; for (int i = 0; i < num3; i++) { AST ast2 = args[i]; if (ast2 is ConstantWrapper) { object argument = ast2.Evaluate(); if ((argIRs[i] = TypeOfArgument(argument)) == null) { goto Label_0120; } this.positionalArgValues.Add(argument); continue; } if ((ast2 is ArrayLiteral) && ((ArrayLiteral)ast2).IsOkToUseInCustomAttribute()) { argIRs[i] = Typeob.ArrayObject; this.positionalArgValues.Add(ast2.Evaluate()); continue; } Label_0120: ast2.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); } this.type = this.ctor.ResolveCustomAttribute(args, argIRs, this.target); if (this.type == null) { return(null); } if (Microsoft.JScript.Convert.IsPromotableTo((IReflect)this.type, Typeob.CodeAccessSecurityAttribute)) { base.context.HandleError(JSError.CannotUseStaticSecurityAttribute); return(null); } ParameterInfo[] parameters = ((ConstructorInfo)((Binding)this.ctor).member).GetParameters(); int num5 = 0; int num6 = this.positionalArgValues.Count; foreach (ParameterInfo info2 in parameters) { IReflect reflect = (info2 is ParameterDeclaration) ? ((ParameterDeclaration)info2).ParameterIReflect : info2.ParameterType; if (num5 < num6) { object obj3 = this.positionalArgValues[num5]; this.positionalArgValues[num5] = Microsoft.JScript.Convert.Coerce(obj3, reflect, obj3 is ArrayObject); num5++; } else { object defaultParameterValue; if (TypeReferences.GetDefaultParameterValue(info2) == System.Convert.DBNull) { defaultParameterValue = Microsoft.JScript.Convert.Coerce(null, reflect); } else { defaultParameterValue = TypeReferences.GetDefaultParameterValue(info2); } this.positionalArgValues.Add(defaultParameterValue); } } int num7 = 0; int num8 = list2.count; while (num7 < num8) { Assign assign2 = (Assign)list2[num7]; if ((assign2.lhside is Lookup) && ((assign2.rhside is ConstantWrapper) || ((assign2.rhside is ArrayLiteral) && ((ArrayLiteral)assign2.rhside).IsOkToUseInCustomAttribute()))) { object obj5 = assign2.rhside.Evaluate(); IReflect reflect2 = null; if ((obj5 is ArrayObject) || (((reflect2 = TypeOfArgument(obj5)) != null) && (reflect2 != Typeob.Object))) { string name = ((Lookup)assign2.lhside).Name; MemberInfo[] member = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance); if ((member == null) || (member.Length == 0)) { assign2.context.HandleError(JSError.NoSuchMember); return(null); } if (member.Length == 1) { MemberInfo info3 = member[0]; if (info3 is FieldInfo) { FieldInfo info4 = (FieldInfo)info3; if (info4.IsLiteral || info4.IsInitOnly) { goto Label_04B6; } try { IReflect reflect3 = (info4 is JSVariableField) ? ((JSVariableField)info4).GetInferredType(null) : info4.FieldType; obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect3, obj5 is ArrayObject); this.namedArgFields.Add(info3); this.namedArgFieldValues.Add(obj5); goto Label_04C9; } catch (JScriptException) { assign2.rhside.context.HandleError(JSError.TypeMismatch); return(null); } } if (info3 is PropertyInfo) { PropertyInfo prop = (PropertyInfo)info3; MethodInfo setMethod = JSProperty.GetSetMethod(prop, false); if (setMethod != null) { ParameterInfo[] infoArray3 = setMethod.GetParameters(); if ((infoArray3 != null) && (infoArray3.Length == 1)) { try { IReflect reflect4 = (infoArray3[0] is ParameterDeclaration) ? ((ParameterDeclaration)infoArray3[0]).ParameterIReflect : infoArray3[0].ParameterType; obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect4, obj5 is ArrayObject); this.namedArgProperties.Add(info3); this.namedArgPropertyValues.Add(obj5); goto Label_04C9; } catch (JScriptException) { assign2.rhside.context.HandleError(JSError.TypeMismatch); return(null); } } } } } } } Label_04B6: assign2.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); Label_04C9: num7++; } if (!this.CheckIfTargetOK(this.type)) { return(null); } try { Type type = this.type as Type; if ((type != null) && (this.target is AssemblyCustomAttributeList)) { if (type.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm)); } return(null); } if (type.FullName == "System.Reflection.AssemblyCultureAttribute") { if (this.positionalArgValues.Count > 0) { string str2 = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]); if ((base.Engine.PEFileKind != PEFileKinds.Dll) && (str2.Length > 0)) { base.context.HandleError(JSError.ExecutablesCannotBeLocalized); return(null); } base.Engine.Globals.assemblyCulture = new CultureInfo(str2); } return(null); } if (type.FullName == "System.Reflection.AssemblyDelaySignAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyDelaySign = Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false); } return(null); } if (type.FullName == "System.Reflection.AssemblyFlagsAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyFlags = (AssemblyFlags)((uint)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(uint))); } return(null); } if (type.FullName == "System.Reflection.AssemblyKeyFileAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyKeyFileName = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]); base.Engine.Globals.assemblyKeyFileNameContext = base.context; if ((base.Engine.Globals.assemblyKeyFileName != null) && (base.Engine.Globals.assemblyKeyFileName.Length == 0)) { base.Engine.Globals.assemblyKeyFileName = null; base.Engine.Globals.assemblyKeyFileNameContext = null; } } return(null); } if (type.FullName == "System.Reflection.AssemblyKeyNameAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyKeyName = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]); base.Engine.Globals.assemblyKeyNameContext = base.context; if ((base.Engine.Globals.assemblyKeyName != null) && (base.Engine.Globals.assemblyKeyName.Length == 0)) { base.Engine.Globals.assemblyKeyName = null; base.Engine.Globals.assemblyKeyNameContext = null; } } return(null); } if (type.FullName == "System.Reflection.AssemblyVersionAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyVersion = this.ParseVersion(Microsoft.JScript.Convert.ToString(this.positionalArgValues[0])); } return(null); } if (type.FullName == "System.CLSCompliantAttribute") { base.Engine.isCLSCompliant = ((this.args == null) || (this.args.count == 0)) || Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false); return(this); } } } catch (ArgumentException) { base.context.HandleError(JSError.InvalidCall); } return(this); }
//--------------------------------------------------------------------------------------- // ParsePackage // // Package : // 'package' QualifiedIdentifier '{' ClassList '}' // // ClassList : // <empty> | // Class ClassList | // Attributes Class ClassList | // Attributes Enum ClassList //--------------------------------------------------------------------------------------- // Because 'package' is not a reserved word in JS5 we have to deal with an ambiguity // in the grammar. A source sequence like the following // package // x // { } // can be legally parsed in two ways: // Identifier Identifier Block or // Package // we give Package priority in this situation. // Here is how we deal with some possible cases: // 1- ** package <no line break> QualifiedIdentifier ** is parsed unambiguously as a package production regardless of what comes after Identifier // 2- ** package <no line break> NotOneOf(Operator | '[' | '.' | '(' | Identifier) '{' ** is parsed as a package production with an error // 3- ** package <line break> '{' ** is parsed as a package (anonymous) with an error // 4- ** package <line break> Not(Identifier) ** is never parsed as a package private AST ParsePackage(Context packageContext){ GetNextToken(); AST qualid = null; bool gotLineBreak = this.scanner.GotEndOfLine(); // erroneous package production if (JSToken.Identifier != this.currentToken.token){ if (JSScanner.CanParseAsExpression(this.currentToken.token)){ // it's an expression. Report a warning. package and this.currentToken can be an expression (i.e. 'package +') ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); qualid = new Lookup("package", packageContext); // get the member expression qualid = MemberExpression(qualid, null); bool isLeftHandSide; qualid = ParsePostfixExpression(qualid, out isLeftHandSide); qualid = ParseExpression(qualid, false, isLeftHandSide, JSToken.None); return new Expression(qualid.context.Clone(), qualid); }else if (!gotLineBreak){ if (JSToken.Increment == this.currentToken.token || JSToken.Decrement == this.currentToken.token){ // it's a postfix expression. Report a warning ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); bool dummy; qualid = new Lookup("package", packageContext); qualid = ParsePostfixExpression(qualid, out dummy); qualid = ParseExpression(qualid, false, false, JSToken.None); return new Expression(qualid.context.Clone(), qualid); } }else{ // it's an expression. Report a warning which, as a side effect, will make the current token be the next token fetched ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); return new Lookup("package", packageContext); } }else{ // it is an identifier, parse it as a qualified identifier this.errorToken = this.currentToken; // this will make GetNextToken() in ParseQualifiedIdentifier() return this.currentToken qualid = ParseQualifiedIdentifier(JSError.NoIdentifier); } // if we are here we have: // ** package QualifiedIdentifier ** or // ** package SomeNonSenseToken **, that is a token that does not make an expression Context nonSenseToken = null; if (JSToken.LeftCurly != this.currentToken.token && qualid == null){ // we want to peek and see whether the next token is a LeftCurly nonSenseToken = this.currentToken.Clone(); GetNextToken(); } if (JSToken.LeftCurly == this.currentToken.token){ // sounds like a package, possibly with an error. If qualid is not null is actually a good package, otherwise we treat it // as an anonymous package and keep going. if (qualid == null){ if (nonSenseToken == null) nonSenseToken = this.currentToken.Clone(); ReportError(JSError.NoIdentifier, nonSenseToken, true); } }else{ if (qualid == null){ // this is pretty screwy, let's ignore the package keyword for a start ReportError(JSError.SyntaxError, packageContext); if (JSScanner.CanStartStatement(nonSenseToken.token)){ // this is tricky we assign nonSenseToken to this.currentToken and call ParseStatement, because we know it is a statement start token. // The parser should then call GetNextToken() which will return the this.currentToken that is assigned to this.errorToken this.currentToken = nonSenseToken; return ParseStatement(); }else{ //ReportError(JSError.SyntaxError, nonSenseToken); if (JSScanner.CanStartStatement(this.currentToken.token)){ this.errorToken = null; return ParseStatement(); }else{ ReportError(JSError.SyntaxError); SkipTokensAndThrow(); } } }else{ if (gotLineBreak){ // we are here with the following: 'package' <line break> QalifiedIdentifier' however we do not have a left curly. // if the token in our hand can start an expression we go with two expressions, otherwise we accept it as a package //if (JSScanner.CanParseAsExpression(this.currentToken.token)){ ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); Block block = new Block(packageContext.Clone()); block.Append(new Lookup("package", packageContext)); qualid = MemberExpression(qualid, null); bool isLeftHandSide; qualid = ParsePostfixExpression(qualid, out isLeftHandSide); qualid = ParseExpression(qualid, false, true, JSToken.None); block.Append(new Expression(qualid.context.Clone(), qualid)); block.context.UpdateWith(qualid.context); return block; //} } // the package production rule is entered regardless of the presence of a left curly. ReportError(JSError.NoLeftCurly); } } PackageScope pscope = new PackageScope(Globals.ScopeStack.Peek()); Globals.ScopeStack.Push(pscope); //Give declarations a place to go while building AST try{ string name = (qualid != null) ? qualid.ToString() : "anonymous package"; pscope.name = name; packageContext.UpdateWith(this.currentToken); ASTList classList = new ASTList(packageContext); GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_BlockNoSkipTokenSet); this.noSkipTokenSet.Add(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet); try{ while (this.currentToken.token != JSToken.RightCurly){ AST ast = null; try{ switch (this.currentToken.token){ case JSToken.Interface: case JSToken.Class: classList.Append(ParseClass((FieldAttributes)0, false, this.currentToken.Clone(), false, false, null)); break; case JSToken.Enum: classList.Append(ParseEnum((FieldAttributes)0, this.currentToken.Clone(), null)); break; case JSToken.Internal: case JSToken.Public: case JSToken.Static: case JSToken.Private: case JSToken.Protected: case JSToken.Abstract: case JSToken.Final: bool parsedOK; ast = ParseAttributes(null, true, false, out parsedOK); if (parsedOK){ if (ast is Class){ classList.Append(ast); break; } } ReportError(JSError.OnlyClassesAllowed, ast.context.Clone(), true); SkipTokensAndThrow(); break; case JSToken.Identifier: bool bAssign, canBeAttribute = true; ast = ParseUnaryExpression(out bAssign, ref canBeAttribute, false); if (canBeAttribute){ bool parsed; ast = ParseAttributes(ast, true, false, out parsed); if (parsed){ if (ast is Class){ classList.Append(ast); break; } } } ReportError(JSError.OnlyClassesAllowed, ast.context.Clone(), true); SkipTokensAndThrow(); break; case JSToken.EndOfFile: EOFError(JSError.ErrEOF); throw new EndOfFile(); // abort parsing, get back to the main parse routine case JSToken.Semicolon: // ignore any spurious semicolon GetNextToken(); break; case JSToken.Import: // handle common error of using import in package ReportError(JSError.InvalidImport, true); try{ ParseImportStatement(); }catch(RecoveryTokenException){ } break; case JSToken.Package: // handle common error of using package in package Context nestedPackageContext = this.currentToken.Clone(); AST statement = ParsePackage(nestedPackageContext); if (statement is Package) ReportError(JSError.PackageInWrongContext, nestedPackageContext, true); break; default: ReportError(JSError.OnlyClassesAllowed, (ast != null) ? ast.context.Clone() : CurrentPositionContext(), true); SkipTokensAndThrow(); break; } }catch(RecoveryTokenException exc){ if (exc._partiallyComputedNode != null && exc._partiallyComputedNode is Class){ classList.Append((Class)exc._partiallyComputedNode); exc._partiallyComputedNode = null; } if (IndexOfToken(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet, exc) == -1) throw exc; } } }catch(RecoveryTokenException exc){ if (IndexOfToken(NoSkipTokenSet.s_BlockNoSkipTokenSet, exc) == -1){ ReportError(JSError.NoRightCurly, CurrentPositionContext()); exc._partiallyComputedNode = new Package(name, qualid, classList, packageContext); throw exc; } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet); this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockNoSkipTokenSet); } GetNextToken(); return new Package(name, qualid, classList, packageContext); }finally{ Globals.ScopeStack.Pop(); } }
private AST ParseLeftHandSideExpression(bool isMinus, ref bool canBeAttribute, bool warnForKeyword){ AST ast = null; bool isFunction = false; ArrayList newContexts = null; // new expression while (JSToken.New == this.currentToken.token){ if (null == newContexts) newContexts = new ArrayList(4); newContexts.Add(this.currentToken.Clone()); GetNextToken(); } JSToken token = this.currentToken.token; switch (token){ // primary expression case JSToken.Identifier: ast = new Lookup(this.scanner.GetIdentifier(), this.currentToken.Clone()); break; case JSToken.This: canBeAttribute = false; ast = new ThisLiteral(this.currentToken.Clone(), false); break; case JSToken.Super: canBeAttribute = false; ast = new ThisLiteral(this.currentToken.Clone(), true); break; case JSToken.StringLiteral: canBeAttribute = false; ast = new ConstantWrapper(this.scanner.GetStringLiteral(), this.currentToken.Clone()); break; case JSToken.IntegerLiteral: {canBeAttribute = false; String number = this.currentToken.GetCode(); Object n = Convert.LiteralToNumber(number, this.currentToken); if (n == null) n = 0; ast = new ConstantWrapper(n, this.currentToken.Clone()); ((ConstantWrapper)ast).isNumericLiteral = true; break;} case JSToken.NumericLiteral: {canBeAttribute = false; String number = (isMinus) ? "-" + this.currentToken.GetCode() : this.currentToken.GetCode(); double d = Convert.ToNumber(number, false, false, Missing.Value); ast = new ConstantWrapper(d, this.currentToken.Clone()); ((ConstantWrapper)ast).isNumericLiteral = true; break;} case JSToken.True: canBeAttribute = false; ast = new ConstantWrapper(true, this.currentToken.Clone()); break; case JSToken.False: canBeAttribute = false; ast = new ConstantWrapper(false, this.currentToken.Clone()); break; case JSToken.Null: canBeAttribute = false; ast = new NullLiteral(this.currentToken.Clone()); break; case JSToken.PreProcessorConstant: canBeAttribute = false; ast = new ConstantWrapper(this.scanner.GetPreProcessorValue(), this.currentToken.Clone()); break; case JSToken.Divide: canBeAttribute = false; // could it be a regexp? String source = this.scanner.ScanRegExp(); if (source != null){ bool badRegExp = false; try { new Regex(source, RegexOptions.ECMAScript); } catch (System.ArgumentException) { // Replace the invalid source with the trivial regular expression. source = ""; badRegExp = true; } String flags = this.scanner.ScanRegExpFlags(); if (flags == null) ast = new RegExpLiteral(source, null, this.currentToken.Clone()); else try{ ast = new RegExpLiteral(source, flags, this.currentToken.Clone()); }catch (JScriptException){ // The flags are invalid, so use null instead. ast = new RegExpLiteral(source, null, this.currentToken.Clone()); badRegExp = true; } if (badRegExp){ ReportError(JSError.RegExpSyntax, true); } break; } goto default; // expression case JSToken.LeftParen: canBeAttribute = false; GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_ParenExpressionNoSkipToken); try{ ast = ParseExpression(); if (JSToken.RightParen != this.currentToken.token) ReportError(JSError.NoRightParen); }catch(RecoveryTokenException exc){ if (IndexOfToken(NoSkipTokenSet.s_ParenExpressionNoSkipToken, exc) == -1) throw exc; else ast = exc._partiallyComputedNode; }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ParenExpressionNoSkipToken); } if (ast == null) //this can only happen when catching the exception and nothing was sent up by the caller SkipTokensAndThrow(); break; // array initializer case JSToken.LeftBracket: canBeAttribute = false; Context listCtx = this.currentToken.Clone(); ASTList list = new ASTList(this.currentToken.Clone()); GetNextToken(); if (this.currentToken.token == JSToken.Identifier && this.scanner.PeekToken() == JSToken.Colon){ this.noSkipTokenSet.Add(NoSkipTokenSet.s_BracketToken); try{ if (this.currentToken.GetCode() == "assembly"){ GetNextToken(); GetNextToken(); return new AssemblyCustomAttributeList(this.ParseCustomAttributeList()); }else{ ReportError(JSError.ExpectedAssembly); SkipTokensAndThrow(); } }catch(RecoveryTokenException exc){ exc._partiallyComputedNode = new Block(listCtx); return exc._partiallyComputedNode; }finally{ if (this.currentToken.token == JSToken.RightBracket){ this.errorToken = null; GetNextToken(); } this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BracketToken); } } while (JSToken.RightBracket != this.currentToken.token){ if (JSToken.Comma != this.currentToken.token){ this.noSkipTokenSet.Add(NoSkipTokenSet.s_ArrayInitNoSkipTokenSet); try{ list.Append(ParseExpression(true)); if (JSToken.Comma != this.currentToken.token){ if (JSToken.RightBracket != this.currentToken.token) ReportError(JSError.NoRightBracket); break; } }catch(RecoveryTokenException exc){ if (exc._partiallyComputedNode != null) list.Append(exc._partiallyComputedNode); if (IndexOfToken(NoSkipTokenSet.s_ArrayInitNoSkipTokenSet, exc) == -1){ listCtx.UpdateWith(CurrentPositionContext()); exc._partiallyComputedNode = new ArrayLiteral(listCtx, list); throw exc; }else{ if (JSToken.RightBracket == this.currentToken.token) break; } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ArrayInitNoSkipTokenSet); } }else{ list.Append(new ConstantWrapper(Missing.Value, this.currentToken.Clone())); } GetNextToken(); } listCtx.UpdateWith(this.currentToken); ast = new ArrayLiteral(listCtx, list); break; // object initializer case JSToken.LeftCurly: canBeAttribute = false; Context objCtx = this.currentToken.Clone(); GetNextToken(); ASTList fields = new ASTList(this.currentToken.Clone()); if (JSToken.RightCurly != this.currentToken.token){ for (;;){ AST field = null; AST value = null; if (JSToken.Identifier == this.currentToken.token) field = new ConstantWrapper(this.scanner.GetIdentifier(), this.currentToken.Clone()); else if (JSToken.StringLiteral == this.currentToken.token) field = new ConstantWrapper(this.scanner.GetStringLiteral(), this.currentToken.Clone()); else if (JSToken.IntegerLiteral == this.currentToken.token || JSToken.NumericLiteral == this.currentToken.token ){ String numberString = this.currentToken.GetCode(); double dValue = Convert.ToNumber(numberString, true, true, Missing.Value); field = new ConstantWrapper(dValue, this.currentToken.Clone()); ((ConstantWrapper)field).isNumericLiteral = true; }else{ ReportError(JSError.NoMemberIdentifier); field = new IdentifierLiteral("_#Missing_Field#_" + s_cDummyName++, CurrentPositionContext()); } ASTList pair = new ASTList(field.context.Clone()); GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_ObjectInitNoSkipTokenSet); try{ // get the value if (JSToken.Colon != this.currentToken.token){ ReportError(JSError.NoColon, true); value = ParseExpression(true); }else{ GetNextToken(); value = ParseExpression(true); } // put the pair into the list of fields pair.Append(field); pair.Append(value); fields.Append(pair); if (JSToken.RightCurly == this.currentToken.token) break; else{ if (JSToken.Comma == this.currentToken.token) GetNextToken(); else{ if (this.scanner.GotEndOfLine()){ ReportError(JSError.NoRightCurly); }else ReportError(JSError.NoComma, true); SkipTokensAndThrow(); } } }catch(RecoveryTokenException exc){ if (exc._partiallyComputedNode != null){ // the problem was in ParseExpression trying to determine value value = exc._partiallyComputedNode; pair.Append(field); pair.Append(value); fields.Append(pair); } if (IndexOfToken(NoSkipTokenSet.s_ObjectInitNoSkipTokenSet, exc) == -1){ exc._partiallyComputedNode = new ObjectLiteral(objCtx, fields); throw exc; }else{ if (JSToken.Comma == this.currentToken.token) GetNextToken(); if (JSToken.RightCurly == this.currentToken.token) break; } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ObjectInitNoSkipTokenSet); } } } fields.context.UpdateWith(this.currentToken); objCtx.UpdateWith(this.currentToken); ast = new ObjectLiteral(objCtx, fields); break; // function expression case JSToken.Function: canBeAttribute = false; ast = ParseFunction((FieldAttributes)0, true, this.currentToken.Clone(), false, false, false, false, null); isFunction = true; break; default: string identifier = JSKeyword.CanBeIdentifier(this.currentToken.token); if (null != identifier){ if (warnForKeyword){ switch (this.currentToken.token){ case JSToken.Boolean : case JSToken.Byte : case JSToken.Char : case JSToken.Double : case JSToken.Float : case JSToken.Int : case JSToken.Long : case JSToken.Short : case JSToken.Void : break; default: ForceReportInfo(JSError.KeywordUsedAsIdentifier); break; } } canBeAttribute = false; ast = new Lookup(identifier, this.currentToken.Clone()); }else if (this.currentToken.token == JSToken.BitwiseAnd){ //& expr used outside of a parameter list ReportError(JSError.WrongUseOfAddressOf); this.errorToken = null; GetNextToken(); return this.ParseLeftHandSideExpression(isMinus, ref canBeAttribute, warnForKeyword); }else{ ReportError(JSError.ExpressionExpected); SkipTokensAndThrow(); } break; } // can be a CallExpression, that is, followed by '.' or '(' or '[' if (!isFunction) GetNextToken(); return MemberExpression(ast, newContexts, ref canBeAttribute); }
internal override AST PartiallyEvaluate() { this.ctor = this.ctor.PartiallyEvaluateAsCallable(); ASTList args = new ASTList(this.args.context); ASTList list2 = new ASTList(this.args.context); int num = 0; int count = this.args.count; while (num < count) { AST ast = this.args[num]; Assign elem = ast as Assign; if (elem != null) { elem.rhside = elem.rhside.PartiallyEvaluate(); list2.Append(elem); } else { args.Append(ast.PartiallyEvaluate()); } num++; } int num3 = args.count; IReflect[] argIRs = new IReflect[num3]; for (int i = 0; i < num3; i++) { AST ast2 = args[i]; if (ast2 is ConstantWrapper) { object argument = ast2.Evaluate(); if ((argIRs[i] = TypeOfArgument(argument)) == null) { goto Label_0120; } this.positionalArgValues.Add(argument); continue; } if ((ast2 is ArrayLiteral) && ((ArrayLiteral) ast2).IsOkToUseInCustomAttribute()) { argIRs[i] = Typeob.ArrayObject; this.positionalArgValues.Add(ast2.Evaluate()); continue; } Label_0120: ast2.context.HandleError(JSError.InvalidCustomAttributeArgument); return null; } this.type = this.ctor.ResolveCustomAttribute(args, argIRs, this.target); if (this.type == null) { return null; } if (Microsoft.JScript.Convert.IsPromotableTo((IReflect) this.type, Typeob.CodeAccessSecurityAttribute)) { base.context.HandleError(JSError.CannotUseStaticSecurityAttribute); return null; } ParameterInfo[] parameters = ((ConstructorInfo) ((Binding) this.ctor).member).GetParameters(); int num5 = 0; int num6 = this.positionalArgValues.Count; foreach (ParameterInfo info2 in parameters) { IReflect reflect = (info2 is ParameterDeclaration) ? ((ParameterDeclaration) info2).ParameterIReflect : info2.ParameterType; if (num5 < num6) { object obj3 = this.positionalArgValues[num5]; this.positionalArgValues[num5] = Microsoft.JScript.Convert.Coerce(obj3, reflect, obj3 is ArrayObject); num5++; } else { object defaultParameterValue; if (TypeReferences.GetDefaultParameterValue(info2) == System.Convert.DBNull) { defaultParameterValue = Microsoft.JScript.Convert.Coerce(null, reflect); } else { defaultParameterValue = TypeReferences.GetDefaultParameterValue(info2); } this.positionalArgValues.Add(defaultParameterValue); } } int num7 = 0; int num8 = list2.count; while (num7 < num8) { Assign assign2 = (Assign) list2[num7]; if ((assign2.lhside is Lookup) && ((assign2.rhside is ConstantWrapper) || ((assign2.rhside is ArrayLiteral) && ((ArrayLiteral) assign2.rhside).IsOkToUseInCustomAttribute()))) { object obj5 = assign2.rhside.Evaluate(); IReflect reflect2 = null; if ((obj5 is ArrayObject) || (((reflect2 = TypeOfArgument(obj5)) != null) && (reflect2 != Typeob.Object))) { string name = ((Lookup) assign2.lhside).Name; MemberInfo[] member = ((IReflect) this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance); if ((member == null) || (member.Length == 0)) { assign2.context.HandleError(JSError.NoSuchMember); return null; } if (member.Length == 1) { MemberInfo info3 = member[0]; if (info3 is FieldInfo) { FieldInfo info4 = (FieldInfo) info3; if (info4.IsLiteral || info4.IsInitOnly) { goto Label_04B6; } try { IReflect reflect3 = (info4 is JSVariableField) ? ((JSVariableField) info4).GetInferredType(null) : info4.FieldType; obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect3, obj5 is ArrayObject); this.namedArgFields.Add(info3); this.namedArgFieldValues.Add(obj5); goto Label_04C9; } catch (JScriptException) { assign2.rhside.context.HandleError(JSError.TypeMismatch); return null; } } if (info3 is PropertyInfo) { PropertyInfo prop = (PropertyInfo) info3; MethodInfo setMethod = JSProperty.GetSetMethod(prop, false); if (setMethod != null) { ParameterInfo[] infoArray3 = setMethod.GetParameters(); if ((infoArray3 != null) && (infoArray3.Length == 1)) { try { IReflect reflect4 = (infoArray3[0] is ParameterDeclaration) ? ((ParameterDeclaration) infoArray3[0]).ParameterIReflect : infoArray3[0].ParameterType; obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect4, obj5 is ArrayObject); this.namedArgProperties.Add(info3); this.namedArgPropertyValues.Add(obj5); goto Label_04C9; } catch (JScriptException) { assign2.rhside.context.HandleError(JSError.TypeMismatch); return null; } } } } } } } Label_04B6: assign2.context.HandleError(JSError.InvalidCustomAttributeArgument); return null; Label_04C9: num7++; } if (!this.CheckIfTargetOK(this.type)) { return null; } try { Type type = this.type as Type; if ((type != null) && (this.target is AssemblyCustomAttributeList)) { if (type.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm) Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm)); } return null; } if (type.FullName == "System.Reflection.AssemblyCultureAttribute") { if (this.positionalArgValues.Count > 0) { string str2 = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]); if ((base.Engine.PEFileKind != PEFileKinds.Dll) && (str2.Length > 0)) { base.context.HandleError(JSError.ExecutablesCannotBeLocalized); return null; } base.Engine.Globals.assemblyCulture = new CultureInfo(str2); } return null; } if (type.FullName == "System.Reflection.AssemblyDelaySignAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyDelaySign = Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false); } return null; } if (type.FullName == "System.Reflection.AssemblyFlagsAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyFlags = (AssemblyFlags) ((uint) Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(uint))); } return null; } if (type.FullName == "System.Reflection.AssemblyKeyFileAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyKeyFileName = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]); base.Engine.Globals.assemblyKeyFileNameContext = base.context; if ((base.Engine.Globals.assemblyKeyFileName != null) && (base.Engine.Globals.assemblyKeyFileName.Length == 0)) { base.Engine.Globals.assemblyKeyFileName = null; base.Engine.Globals.assemblyKeyFileNameContext = null; } } return null; } if (type.FullName == "System.Reflection.AssemblyKeyNameAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyKeyName = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]); base.Engine.Globals.assemblyKeyNameContext = base.context; if ((base.Engine.Globals.assemblyKeyName != null) && (base.Engine.Globals.assemblyKeyName.Length == 0)) { base.Engine.Globals.assemblyKeyName = null; base.Engine.Globals.assemblyKeyNameContext = null; } } return null; } if (type.FullName == "System.Reflection.AssemblyVersionAttribute") { if (this.positionalArgValues.Count > 0) { base.Engine.Globals.assemblyVersion = this.ParseVersion(Microsoft.JScript.Convert.ToString(this.positionalArgValues[0])); } return null; } if (type.FullName == "System.CLSCompliantAttribute") { base.Engine.isCLSCompliant = ((this.args == null) || (this.args.count == 0)) || Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false); return this; } } } catch (ArgumentException) { base.context.HandleError(JSError.InvalidCall); } return this; }
//--------------------------------------------------------------------------------------- // ParseSwitchStatement // // SwitchStatement : // 'switch' '(' Expression ')' '{' CaseBlock '}' // // CaseBlock : // CaseList DefaultCaseClause CaseList // // CaseList : // <empty> | // CaseClause CaseList // // CaseClause : // 'case' Expression ':' OptionalStatements // // DefaultCaseClause : // <empty> | // 'default' ':' OptionalStatements //--------------------------------------------------------------------------------------- private AST ParseSwitchStatement(){ Context switchCtx = this.currentToken.Clone(); AST expr = null; ASTList cases = null; this.blockType.Add(BlockType.Switch); try{ // read switch(expr) GetNextToken(); if (JSToken.LeftParen != this.currentToken.token) ReportError(JSError.NoLeftParen); GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); this.noSkipTokenSet.Add(NoSkipTokenSet.s_SwitchNoSkipTokenSet); try{ expr = ParseExpression(); if (JSToken.RightParen != this.currentToken.token){ ReportError(JSError.NoRightParen); } GetNextToken(); if (JSToken.LeftCurly != this.currentToken.token){ ReportError(JSError.NoLeftCurly); } GetNextToken(); }catch(RecoveryTokenException exc){ if (IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exc) == -1 && IndexOfToken(NoSkipTokenSet.s_SwitchNoSkipTokenSet, exc) == -1 ){ // give up exc._partiallyComputedNode = null; throw exc; }else{ if (exc._partiallyComputedNode == null) expr = new ConstantWrapper(true, CurrentPositionContext()); else expr = exc._partiallyComputedNode; if (IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exc) != -1){ if (exc._token == JSToken.RightParen) GetNextToken(); if (JSToken.LeftCurly != this.currentToken.token){ ReportError(JSError.NoLeftCurly); } GetNextToken(); } } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_SwitchNoSkipTokenSet); this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); } // parse the switch body cases = new ASTList(this.currentToken.Clone()); bool defaultStatement = false; this.noSkipTokenSet.Add(NoSkipTokenSet.s_BlockNoSkipTokenSet); try{ while (JSToken.RightCurly != this.currentToken.token){ SwitchCase caseClause = null; AST caseValue = null; Context caseCtx = this.currentToken.Clone(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_CaseNoSkipTokenSet); try{ if (JSToken.Case == this.currentToken.token){ // get the case GetNextToken(); caseValue = ParseExpression(); }else if (JSToken.Default == this.currentToken.token){ // get the default if (defaultStatement) // we report an error but we still accept the default ReportError(JSError.DupDefault, true); else defaultStatement = true; GetNextToken(); }else{ // This is an error, there is no case or default. Assume a default was missing and keep going defaultStatement = true; ReportError(JSError.BadSwitch); } if (JSToken.Colon != this.currentToken.token) ReportError(JSError.NoColon); // read the statements inside the case or default GetNextToken(); }catch(RecoveryTokenException exc){ // right now we can only get here for the 'case' statement if (IndexOfToken(NoSkipTokenSet.s_CaseNoSkipTokenSet, exc) == -1){ // ignore the current case or default exc._partiallyComputedNode = null; throw exc; }else{ caseValue = exc._partiallyComputedNode; if (exc._token == JSToken.Colon) GetNextToken(); } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_CaseNoSkipTokenSet); } this.blockType.Add(BlockType.Block); try{ Block statements = new Block(this.currentToken.Clone()); this.noSkipTokenSet.Add(NoSkipTokenSet.s_SwitchNoSkipTokenSet); this.noSkipTokenSet.Add(NoSkipTokenSet.s_StartStatementNoSkipTokenSet); try{ while (JSToken.RightCurly != this.currentToken.token && JSToken.Case != this.currentToken.token && JSToken.Default != this.currentToken.token){ try{ statements.Append(ParseStatement()); }catch(RecoveryTokenException exc){ if (exc._partiallyComputedNode != null){ statements.Append(exc._partiallyComputedNode); exc._partiallyComputedNode = null; } if (IndexOfToken(NoSkipTokenSet.s_StartStatementNoSkipTokenSet, exc) == -1) throw exc; } } }catch(RecoveryTokenException exc){ if (IndexOfToken(NoSkipTokenSet.s_SwitchNoSkipTokenSet, exc) == -1){ if (null == caseValue) caseClause = new SwitchCase(caseCtx, statements); else caseClause = new SwitchCase(caseCtx, caseValue, statements); cases.Append(caseClause); throw exc; } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_StartStatementNoSkipTokenSet); this.noSkipTokenSet.Remove(NoSkipTokenSet.s_SwitchNoSkipTokenSet); } if (JSToken.RightCurly == this.currentToken.token) statements.context.UpdateWith(this.currentToken); if (null == caseValue){ caseCtx.UpdateWith(statements.context); caseClause = new SwitchCase(caseCtx, statements); }else{ caseCtx.UpdateWith(statements.context); caseClause = new SwitchCase(caseCtx, caseValue, statements); } cases.Append(caseClause); }finally{ this.blockType.RemoveAt(this.blockType.Count - 1); } } }catch(RecoveryTokenException exc){ if (IndexOfToken(NoSkipTokenSet.s_BlockNoSkipTokenSet, exc) == -1){ //save what you can a rethrow switchCtx.UpdateWith(CurrentPositionContext()); exc._partiallyComputedNode = new Switch(switchCtx, expr, cases); throw exc; } }finally{ this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockNoSkipTokenSet); } switchCtx.UpdateWith(this.currentToken); GetNextToken(); }finally{ this.blockType.RemoveAt(this.blockType.Count - 1); } return new Switch(switchCtx, expr, cases); }
internal override AST PartiallyEvaluate() { this.ctor = this.ctor.PartiallyEvaluateAsCallable(); //first weed out assignment expressions and use them as property initializers ASTList positionalArgs = new ASTList(this.args.context); ASTList namedArgs = new ASTList(this.args.context); for (int i = 0, m = this.args.count; i < m; i++) { AST arg = this.args[i]; Assign assign = arg as Assign; if (assign != null) { assign.rhside = assign.rhside.PartiallyEvaluate(); namedArgs.Append(assign); } else { positionalArgs.Append(arg.PartiallyEvaluate()); } } int n = positionalArgs.count; IReflect[] argIRs = new IReflect[n]; for (int i = 0; i < n; i++) { AST arg = positionalArgs[i]; // only accept ConstantWrappers if (arg is ConstantWrapper) { Object argument = arg.Evaluate(); if ((argIRs[i] = CustomAttribute.TypeOfArgument(argument)) != null) { this.positionalArgValues.Add(argument); continue; } } else if (arg is ArrayLiteral && ((ArrayLiteral)arg).IsOkToUseInCustomAttribute()) { argIRs[i] = Typeob.ArrayObject; this.positionalArgValues.Add(arg.Evaluate()); continue; } arg.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); // the custom attribute is not good and it will be ignored } //Get the custom attribute and the appropriate constructor (under the covers) this.type = this.ctor.ResolveCustomAttribute(positionalArgs, argIRs, this.target); if (this.type == null) { return(null); } if (Convert.IsPromotableTo((IReflect)this.type, typeof(CodeAccessSecurityAttribute))) { this.context.HandleError(JSError.CannotUseStaticSecurityAttribute); return(null); } //Coerce the positional arguments to the right type and supply default values for optional parameters ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member; ParameterInfo[] parameters = c.GetParameters(); int j = 0; int len = this.positionalArgValues.Count; foreach (ParameterInfo p in parameters) { IReflect ir = p is ParameterDeclaration ? ((ParameterDeclaration)p).ParameterIReflect : p.ParameterType; if (j < len) { Object value = this.positionalArgValues[j]; this.positionalArgValues[j] = Convert.Coerce(value, ir, value is ArrayObject); j++; } else { Object value; if (p.DefaultValue == System.Convert.DBNull) { value = Convert.Coerce(null, ir); } else { value = p.DefaultValue; } this.positionalArgValues.Add(value); } } //Check validity of property/field initializers for (int i = 0, m = namedArgs.count; i < m; i++) { Assign assign = (Assign)namedArgs[i]; if (assign.lhside is Lookup && (assign.rhside is ConstantWrapper || (assign.rhside is ArrayLiteral && ((ArrayLiteral)assign.rhside).IsOkToUseInCustomAttribute()))) { Object value = assign.rhside.Evaluate(); IReflect argType = null; if (value is ArrayObject || ((argType = CustomAttribute.TypeOfArgument(value)) != null && argType != Typeob.Object)) { String name = ((Lookup)assign.lhside).Name; MemberInfo [] members = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance); if (members == null || members.Length == 0) { assign.context.HandleError(JSError.NoSuchMember); return(null); } if (members.Length == 1) { MemberInfo member = members[0]; if (member is FieldInfo) { FieldInfo fieldInfo = (FieldInfo)member; if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly) { try{ IReflect ir = fieldInfo is JSVariableField ? ((JSVariableField)fieldInfo).GetInferredType(null) : fieldInfo.FieldType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgFields.Add(member); this.namedArgFieldValues.Add(value); continue; }catch (JScriptException) { assign.rhside.context.HandleError(JSError.TypeMismatch); return(null); // the custom attribute is not good and it will be ignored } } } else if (member is PropertyInfo) { PropertyInfo propertyInfo = (PropertyInfo)member; MethodInfo setMethodInfo = JSProperty.GetSetMethod(propertyInfo, false); if (setMethodInfo != null) { ParameterInfo [] paramInfo = setMethodInfo.GetParameters(); if (paramInfo != null && paramInfo.Length == 1) { try{ IReflect ir = paramInfo[0] is ParameterDeclaration ? ((ParameterDeclaration)paramInfo[0]).ParameterIReflect : paramInfo[0].ParameterType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgProperties.Add(member); this.namedArgPropertyValues.Add(value); }catch (JScriptException) { assign.rhside.context.HandleError(JSError.TypeMismatch); return(null); // the custom attribute is not good and it will be ignored } continue; } } } } } } assign.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); } if (!this.CheckIfTargetOK(this.type)) { return(null); //Ignore attribute } //Consume and discard assembly name attributes try{ Type ty = this.type as Type; if (ty != null && this.target is AssemblyCustomAttributeList) { if (ty.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm)); } return(null); } if (ty.FullName == "System.Reflection.AssemblyCultureAttribute") { if (this.positionalArgValues.Count > 0) { String cultureId = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.PEFileKind != PEFileKinds.Dll && cultureId.Length > 0) { this.context.HandleError(JSError.ExecutablesCannotBeLocalized); return(null); } this.Engine.Globals.assemblyCulture = new CultureInfo(cultureId); } return(null); } if (ty.FullName == "System.Reflection.AssemblyDelaySignAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyDelaySign = Convert.ToBoolean(this.positionalArgValues[0], false); } return(null); } if (ty.FullName == "System.Reflection.AssemblyFlagsAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyFlags = (AssemblyFlags)(uint)Convert.CoerceT(this.positionalArgValues[0], typeof(uint)); } return(null); } if (ty.FullName == "System.Reflection.AssemblyKeyFileAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyKeyFileName = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.Globals.assemblyKeyFileName != null && this.Engine.Globals.assemblyKeyFileName.Length == 0) { this.Engine.Globals.assemblyKeyFileName = null; } } return(null); } if (ty.FullName == "System.Reflection.AssemblyKeyNameAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyKeyName = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.Globals.assemblyKeyName != null && this.Engine.Globals.assemblyKeyName.Length == 0) { this.Engine.Globals.assemblyKeyName = null; } } return(null); } if (ty.FullName == "System.Reflection.AssemblyVersionAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyVersion = this.ParseVersion(Convert.ToString(this.positionalArgValues[0])); } return(null); } if (ty.FullName == "System.CLSCompliantAttribute") { this.Engine.isCLSCompliant = this.args == null || this.args.count == 0 || Convert.ToBoolean(this.positionalArgValues[0], false); return(this); } } }catch (ArgumentException) { this.context.HandleError(JSError.InvalidCall); } return(this); }
private AST ParseSwitchStatement() { Context context = this.currentToken.Clone(); AST expression = null; ASTList cases = null; this.blockType.Add(BlockType.Switch); try { this.GetNextToken(); if (JSToken.LeftParen != this.currentToken.token) { this.ReportError(JSError.NoLeftParen); } this.GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); this.noSkipTokenSet.Add(NoSkipTokenSet.s_SwitchNoSkipTokenSet); try { expression = this.ParseExpression(); if (JSToken.RightParen != this.currentToken.token) { this.ReportError(JSError.NoRightParen); } this.GetNextToken(); if (JSToken.LeftCurly != this.currentToken.token) { this.ReportError(JSError.NoLeftCurly); } this.GetNextToken(); } catch (RecoveryTokenException exception) { if ((this.IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exception) == -1) && (this.IndexOfToken(NoSkipTokenSet.s_SwitchNoSkipTokenSet, exception) == -1)) { exception._partiallyComputedNode = null; throw exception; } if (exception._partiallyComputedNode == null) { expression = new ConstantWrapper(true, this.CurrentPositionContext()); } else { expression = exception._partiallyComputedNode; } if (this.IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exception) != -1) { if (exception._token == JSToken.RightParen) { this.GetNextToken(); } if (JSToken.LeftCurly != this.currentToken.token) { this.ReportError(JSError.NoLeftCurly); } this.GetNextToken(); } } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_SwitchNoSkipTokenSet); this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet); } cases = new ASTList(this.currentToken.Clone()); bool flag = false; this.noSkipTokenSet.Add(NoSkipTokenSet.s_BlockNoSkipTokenSet); try { while (JSToken.RightCurly != this.currentToken.token) { SwitchCase elem = null; AST ast2 = null; Context context2 = this.currentToken.Clone(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_CaseNoSkipTokenSet); try { if (JSToken.Case == this.currentToken.token) { this.GetNextToken(); ast2 = this.ParseExpression(); } else if (JSToken.Default == this.currentToken.token) { if (flag) { this.ReportError(JSError.DupDefault, true); } else { flag = true; } this.GetNextToken(); } else { flag = true; this.ReportError(JSError.BadSwitch); } if (JSToken.Colon != this.currentToken.token) { this.ReportError(JSError.NoColon); } this.GetNextToken(); } catch (RecoveryTokenException exception2) { if (this.IndexOfToken(NoSkipTokenSet.s_CaseNoSkipTokenSet, exception2) == -1) { exception2._partiallyComputedNode = null; throw exception2; } ast2 = exception2._partiallyComputedNode; if (exception2._token == JSToken.Colon) { this.GetNextToken(); } } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_CaseNoSkipTokenSet); } this.blockType.Add(BlockType.Block); try { Block statements = new Block(this.currentToken.Clone()); this.noSkipTokenSet.Add(NoSkipTokenSet.s_SwitchNoSkipTokenSet); this.noSkipTokenSet.Add(NoSkipTokenSet.s_StartStatementNoSkipTokenSet); try { while (((JSToken.RightCurly != this.currentToken.token) && (JSToken.Case != this.currentToken.token)) && (JSToken.Default != this.currentToken.token)) { try { statements.Append(this.ParseStatement()); continue; } catch (RecoveryTokenException exception3) { if (exception3._partiallyComputedNode != null) { statements.Append(exception3._partiallyComputedNode); exception3._partiallyComputedNode = null; } if (this.IndexOfToken(NoSkipTokenSet.s_StartStatementNoSkipTokenSet, exception3) == -1) { throw exception3; } continue; } } } catch (RecoveryTokenException exception4) { if (this.IndexOfToken(NoSkipTokenSet.s_SwitchNoSkipTokenSet, exception4) == -1) { if (ast2 == null) { elem = new SwitchCase(context2, statements); } else { elem = new SwitchCase(context2, ast2, statements); } cases.Append(elem); throw exception4; } } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_StartStatementNoSkipTokenSet); this.noSkipTokenSet.Remove(NoSkipTokenSet.s_SwitchNoSkipTokenSet); } if (JSToken.RightCurly == this.currentToken.token) { statements.context.UpdateWith(this.currentToken); } if (ast2 == null) { context2.UpdateWith(statements.context); elem = new SwitchCase(context2, statements); } else { context2.UpdateWith(statements.context); elem = new SwitchCase(context2, ast2, statements); } cases.Append(elem); continue; } finally { this.blockType.RemoveAt(this.blockType.Count - 1); } } } catch (RecoveryTokenException exception5) { if (this.IndexOfToken(NoSkipTokenSet.s_BlockNoSkipTokenSet, exception5) == -1) { context.UpdateWith(this.CurrentPositionContext()); exception5._partiallyComputedNode = new Switch(context, expression, cases); throw exception5; } } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockNoSkipTokenSet); } context.UpdateWith(this.currentToken); this.GetNextToken(); } finally { this.blockType.RemoveAt(this.blockType.Count - 1); } return new Switch(context, expression, cases); }
private AST ParsePackage(Context packageContext) { AST ast4; this.GetNextToken(); AST expression = null; bool flag = this.scanner.GotEndOfLine(); if (JSToken.Identifier != this.currentToken.token) { if (JSScanner.CanParseAsExpression(this.currentToken.token)) { bool flag2; this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); expression = new Lookup("package", packageContext); expression = this.MemberExpression(expression, null); expression = this.ParsePostfixExpression(expression, out flag2); expression = this.ParseExpression(expression, false, flag2, JSToken.None); return new Expression(expression.context.Clone(), expression); } if (flag) { this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); return new Lookup("package", packageContext); } if ((JSToken.Increment == this.currentToken.token) || (JSToken.Decrement == this.currentToken.token)) { bool flag3; this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); expression = new Lookup("package", packageContext); expression = this.ParsePostfixExpression(expression, out flag3); expression = this.ParseExpression(expression, false, false, JSToken.None); return new Expression(expression.context.Clone(), expression); } } else { this.errorToken = this.currentToken; expression = this.ParseQualifiedIdentifier(JSError.NoIdentifier); } Context context = null; if ((JSToken.LeftCurly != this.currentToken.token) && (expression == null)) { context = this.currentToken.Clone(); this.GetNextToken(); } if (JSToken.LeftCurly == this.currentToken.token) { if (expression == null) { if (context == null) { context = this.currentToken.Clone(); } this.ReportError(JSError.NoIdentifier, context, true); } } else if (expression == null) { this.ReportError(JSError.SyntaxError, packageContext); if (JSScanner.CanStartStatement(context.token)) { this.currentToken = context; return this.ParseStatement(); } if (JSScanner.CanStartStatement(this.currentToken.token)) { this.errorToken = null; return this.ParseStatement(); } this.ReportError(JSError.SyntaxError); this.SkipTokensAndThrow(); } else { if (flag) { bool flag4; this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true); Block block = new Block(packageContext.Clone()); block.Append(new Lookup("package", packageContext)); expression = this.MemberExpression(expression, null); expression = this.ParsePostfixExpression(expression, out flag4); expression = this.ParseExpression(expression, false, true, JSToken.None); block.Append(new Expression(expression.context.Clone(), expression)); block.context.UpdateWith(expression.context); return block; } this.ReportError(JSError.NoLeftCurly); } PackageScope item = new PackageScope(this.Globals.ScopeStack.Peek()); this.Globals.ScopeStack.Push(item); try { string name = (expression != null) ? expression.ToString() : "anonymous package"; item.name = name; packageContext.UpdateWith(this.currentToken); ASTList classList = new ASTList(packageContext); this.GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_BlockNoSkipTokenSet); this.noSkipTokenSet.Add(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet); try { while (this.currentToken.token != JSToken.RightCurly) { AST statement = null; try { switch (this.currentToken.token) { case JSToken.Identifier: { bool flag6; bool canBeAttribute = true; statement = this.ParseUnaryExpression(out flag6, ref canBeAttribute, false); if (canBeAttribute) { bool flag8; statement = this.ParseAttributes(statement, true, false, out flag8); if (flag8 && (statement is Class)) { classList.Append(statement); continue; } } this.ReportError(JSError.OnlyClassesAllowed, statement.context.Clone(), true); this.SkipTokensAndThrow(); continue; } case JSToken.Interface: case JSToken.Class: { classList.Append(this.ParseClass(FieldAttributes.PrivateScope, false, this.currentToken.Clone(), false, false, null)); continue; } case JSToken.Enum: { classList.Append(this.ParseEnum(FieldAttributes.PrivateScope, this.currentToken.Clone(), null)); continue; } case JSToken.Import: { this.ReportError(JSError.InvalidImport, true); try { this.ParseImportStatement(); } catch (RecoveryTokenException) { } continue; } case JSToken.Package: { Context context2 = this.currentToken.Clone(); if (this.ParsePackage(context2) is Package) { this.ReportError(JSError.PackageInWrongContext, context2, true); } continue; } case JSToken.Internal: case JSToken.Abstract: case JSToken.Public: case JSToken.Static: case JSToken.Private: case JSToken.Protected: case JSToken.Final: { bool flag5; statement = this.ParseAttributes(null, true, false, out flag5); if (!flag5 || !(statement is Class)) { break; } classList.Append(statement); continue; } case JSToken.Semicolon: { this.GetNextToken(); continue; } case JSToken.EndOfFile: this.EOFError(JSError.ErrEOF); throw new EndOfFile(); default: goto Label_04D9; } this.ReportError(JSError.OnlyClassesAllowed, statement.context.Clone(), true); this.SkipTokensAndThrow(); continue; Label_04D9: this.ReportError(JSError.OnlyClassesAllowed, (statement != null) ? statement.context.Clone() : this.CurrentPositionContext(), true); this.SkipTokensAndThrow(); continue; } catch (RecoveryTokenException exception) { if ((exception._partiallyComputedNode != null) && (exception._partiallyComputedNode is Class)) { classList.Append((Class) exception._partiallyComputedNode); exception._partiallyComputedNode = null; } if (this.IndexOfToken(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet, exception) == -1) { throw exception; } continue; } } } catch (RecoveryTokenException exception2) { if (this.IndexOfToken(NoSkipTokenSet.s_BlockNoSkipTokenSet, exception2) == -1) { this.ReportError(JSError.NoRightCurly, this.CurrentPositionContext()); exception2._partiallyComputedNode = new Package(name, expression, classList, packageContext); throw exception2; } } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet); this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockNoSkipTokenSet); } this.GetNextToken(); ast4 = new Package(name, expression, classList, packageContext); } finally { this.Globals.ScopeStack.Pop(); } return ast4; }
private AST ParseLeftHandSideExpression(bool isMinus, ref bool canBeAttribute, bool warnForKeyword) { AST expression = null; Context context; ASTList list2; Context context2; ASTList list3; string str6; bool flag = false; ArrayList newContexts = null; while (JSToken.New == this.currentToken.token) { if (newContexts == null) { newContexts = new ArrayList(4); } newContexts.Add(this.currentToken.Clone()); this.GetNextToken(); } JSToken token = this.currentToken.token; if (token <= JSToken.Divide) { switch (token) { case JSToken.Function: canBeAttribute = false; expression = this.ParseFunction(FieldAttributes.PrivateScope, true, this.currentToken.Clone(), false, false, false, false, null); flag = true; goto Label_0956; case JSToken.LeftCurly: { AST ast2; canBeAttribute = false; context2 = this.currentToken.Clone(); this.GetNextToken(); list3 = new ASTList(this.currentToken.Clone()); if (JSToken.RightCurly == this.currentToken.token) { goto Label_0830; } Label_05C9: ast2 = null; AST elem = null; if (JSToken.Identifier == this.currentToken.token) { ast2 = new ConstantWrapper(this.scanner.GetIdentifier(), this.currentToken.Clone()); } else if (JSToken.StringLiteral == this.currentToken.token) { ast2 = new ConstantWrapper(this.scanner.GetStringLiteral(), this.currentToken.Clone()); } else if ((JSToken.IntegerLiteral == this.currentToken.token) || (JSToken.NumericLiteral == this.currentToken.token)) { ast2 = new ConstantWrapper(Microsoft.JScript.Convert.ToNumber(this.currentToken.GetCode(), true, true, Microsoft.JScript.Missing.Value), this.currentToken.Clone()); ((ConstantWrapper) ast2).isNumericLiteral = true; } else { this.ReportError(JSError.NoMemberIdentifier); ast2 = new IdentifierLiteral("_#Missing_Field#_" + s_cDummyName++, this.CurrentPositionContext()); } ASTList list4 = new ASTList(ast2.context.Clone()); this.GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_ObjectInitNoSkipTokenSet); try { try { if (JSToken.Colon != this.currentToken.token) { this.ReportError(JSError.NoColon, true); elem = this.ParseExpression(true); } else { this.GetNextToken(); elem = this.ParseExpression(true); } list4.Append(ast2); list4.Append(elem); list3.Append(list4); if (JSToken.RightCurly == this.currentToken.token) { goto Label_0830; } if (JSToken.Comma == this.currentToken.token) { this.GetNextToken(); } else { if (this.scanner.GotEndOfLine()) { this.ReportError(JSError.NoRightCurly); } else { this.ReportError(JSError.NoComma, true); } this.SkipTokensAndThrow(); } } catch (RecoveryTokenException exception4) { if (exception4._partiallyComputedNode != null) { elem = exception4._partiallyComputedNode; list4.Append(ast2); list4.Append(elem); list3.Append(list4); } if (this.IndexOfToken(NoSkipTokenSet.s_ObjectInitNoSkipTokenSet, exception4) == -1) { exception4._partiallyComputedNode = new ObjectLiteral(context2, list3); throw exception4; } if (JSToken.Comma == this.currentToken.token) { this.GetNextToken(); } if (JSToken.RightCurly == this.currentToken.token) { goto Label_0830; } } goto Label_05C9; } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ObjectInitNoSkipTokenSet); } goto Label_0830; } case JSToken.Null: canBeAttribute = false; expression = new NullLiteral(this.currentToken.Clone()); goto Label_0956; case JSToken.True: canBeAttribute = false; expression = new ConstantWrapper(true, this.currentToken.Clone()); goto Label_0956; case JSToken.False: canBeAttribute = false; expression = new ConstantWrapper(false, this.currentToken.Clone()); goto Label_0956; case JSToken.This: canBeAttribute = false; expression = new ThisLiteral(this.currentToken.Clone(), false); goto Label_0956; case JSToken.Identifier: expression = new Lookup(this.scanner.GetIdentifier(), this.currentToken.Clone()); goto Label_0956; case JSToken.StringLiteral: canBeAttribute = false; expression = new ConstantWrapper(this.scanner.GetStringLiteral(), this.currentToken.Clone()); goto Label_0956; case JSToken.IntegerLiteral: { canBeAttribute = false; object obj2 = Microsoft.JScript.Convert.LiteralToNumber(this.currentToken.GetCode(), this.currentToken); if (obj2 == null) { obj2 = 0; } expression = new ConstantWrapper(obj2, this.currentToken.Clone()); ((ConstantWrapper) expression).isNumericLiteral = true; goto Label_0956; } case JSToken.NumericLiteral: { canBeAttribute = false; string str = isMinus ? ("-" + this.currentToken.GetCode()) : this.currentToken.GetCode(); expression = new ConstantWrapper(Microsoft.JScript.Convert.ToNumber(str, false, false, Microsoft.JScript.Missing.Value), this.currentToken.Clone()); ((ConstantWrapper) expression).isNumericLiteral = true; goto Label_0956; } case JSToken.LeftParen: canBeAttribute = false; this.GetNextToken(); this.noSkipTokenSet.Add(NoSkipTokenSet.s_ParenExpressionNoSkipToken); try { expression = this.ParseExpression(); if (JSToken.RightParen != this.currentToken.token) { this.ReportError(JSError.NoRightParen); } } catch (RecoveryTokenException exception) { if (this.IndexOfToken(NoSkipTokenSet.s_ParenExpressionNoSkipToken, exception) == -1) { throw exception; } expression = exception._partiallyComputedNode; } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ParenExpressionNoSkipToken); } if (expression == null) { this.SkipTokensAndThrow(); } goto Label_0956; case JSToken.LeftBracket: canBeAttribute = false; context = this.currentToken.Clone(); list2 = new ASTList(this.currentToken.Clone()); this.GetNextToken(); if ((this.currentToken.token != JSToken.Identifier) || (this.scanner.PeekToken() != JSToken.Colon)) { goto Label_0561; } this.noSkipTokenSet.Add(NoSkipTokenSet.s_BracketToken); try { try { if (this.currentToken.GetCode() == "assembly") { this.GetNextToken(); this.GetNextToken(); return new AssemblyCustomAttributeList(this.ParseCustomAttributeList()); } this.ReportError(JSError.ExpectedAssembly); this.SkipTokensAndThrow(); } catch (RecoveryTokenException exception2) { exception2._partiallyComputedNode = new Block(context); return exception2._partiallyComputedNode; } goto Label_0561; } finally { if (this.currentToken.token == JSToken.RightBracket) { this.errorToken = null; this.GetNextToken(); } this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BracketToken); } goto Label_046D; case JSToken.Divide: { canBeAttribute = false; string pattern = this.scanner.ScanRegExp(); if (pattern == null) { break; } bool flag2 = false; try { new Regex(pattern, RegexOptions.ECMAScript); } catch (ArgumentException) { pattern = ""; flag2 = true; } string flags = this.scanner.ScanRegExpFlags(); if (flags == null) { expression = new RegExpLiteral(pattern, null, this.currentToken.Clone()); } else { try { expression = new RegExpLiteral(pattern, flags, this.currentToken.Clone()); } catch (JScriptException) { expression = new RegExpLiteral(pattern, null, this.currentToken.Clone()); flag2 = true; } } if (flag2) { this.ReportError(JSError.RegExpSyntax, true); } goto Label_0956; } } goto Label_0881; } if (token != JSToken.Super) { if (token == JSToken.PreProcessorConstant) { canBeAttribute = false; expression = new ConstantWrapper(this.scanner.GetPreProcessorValue(), this.currentToken.Clone()); goto Label_0956; } goto Label_0881; } canBeAttribute = false; expression = new ThisLiteral(this.currentToken.Clone(), true); goto Label_0956; Label_046D: if (JSToken.Comma != this.currentToken.token) { this.noSkipTokenSet.Add(NoSkipTokenSet.s_ArrayInitNoSkipTokenSet); try { list2.Append(this.ParseExpression(true)); if (JSToken.Comma != this.currentToken.token) { if (JSToken.RightBracket != this.currentToken.token) { this.ReportError(JSError.NoRightBracket); } goto Label_0573; } } catch (RecoveryTokenException exception3) { if (exception3._partiallyComputedNode != null) { list2.Append(exception3._partiallyComputedNode); } if (this.IndexOfToken(NoSkipTokenSet.s_ArrayInitNoSkipTokenSet, exception3) == -1) { context.UpdateWith(this.CurrentPositionContext()); exception3._partiallyComputedNode = new ArrayLiteral(context, list2); throw exception3; } if (JSToken.RightBracket == this.currentToken.token) { goto Label_0573; } } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ArrayInitNoSkipTokenSet); } } else { list2.Append(new ConstantWrapper(Microsoft.JScript.Missing.Value, this.currentToken.Clone())); } this.GetNextToken(); Label_0561: if (JSToken.RightBracket != this.currentToken.token) { goto Label_046D; } Label_0573: context.UpdateWith(this.currentToken); expression = new ArrayLiteral(context, list2); goto Label_0956; Label_0830: list3.context.UpdateWith(this.currentToken); context2.UpdateWith(this.currentToken); expression = new ObjectLiteral(context2, list3); goto Label_0956; Label_0881: str6 = JSKeyword.CanBeIdentifier(this.currentToken.token); if (str6 == null) { if (this.currentToken.token == JSToken.BitwiseAnd) { this.ReportError(JSError.WrongUseOfAddressOf); this.errorToken = null; this.GetNextToken(); return this.ParseLeftHandSideExpression(isMinus, ref canBeAttribute, warnForKeyword); } this.ReportError(JSError.ExpressionExpected); this.SkipTokensAndThrow(); goto Label_0956; } if (warnForKeyword) { switch (this.currentToken.token) { case JSToken.Boolean: case JSToken.Byte: case JSToken.Char: case JSToken.Double: case JSToken.Float: case JSToken.Int: case JSToken.Long: case JSToken.Short: case JSToken.Void: goto Label_08FC; } this.ForceReportInfo(JSError.KeywordUsedAsIdentifier); } Label_08FC: canBeAttribute = false; expression = new Lookup(str6, this.currentToken.Clone()); Label_0956: if (!flag) { this.GetNextToken(); } return this.MemberExpression(expression, newContexts, ref canBeAttribute); }
private ASTList ParseExpressionList(JSToken terminator) { Context context = this.currentToken.Clone(); this.scanner.GetCurrentLine(); this.GetNextToken(); ASTList list = new ASTList(context); if (terminator != this.currentToken.token) { while (true) { this.noSkipTokenSet.Add(NoSkipTokenSet.s_ExpressionListNoSkipTokenSet); try { if (JSToken.BitwiseAnd == this.currentToken.token) { Context context2 = this.currentToken.Clone(); this.GetNextToken(); AST operand = this.ParseLeftHandSideExpression(); if ((operand is Member) || (operand is Lookup)) { context2.UpdateWith(operand.context); list.Append(new AddressOf(context2, operand)); } else { this.ReportError(JSError.DoesNotHaveAnAddress, context2.Clone()); list.Append(operand); } } else if (JSToken.Comma == this.currentToken.token) { list.Append(new ConstantWrapper(System.Reflection.Missing.Value, this.currentToken.Clone())); } else { if (terminator == this.currentToken.token) { break; } list.Append(this.ParseExpression(true)); } if (terminator == this.currentToken.token) { break; } if (JSToken.Comma != this.currentToken.token) { if (terminator == JSToken.RightParen) { if ((JSToken.Semicolon == this.currentToken.token) && (JSToken.RightParen == this.scanner.PeekToken())) { this.ReportError(JSError.UnexpectedSemicolon, true); this.GetNextToken(); break; } this.ReportError(JSError.NoRightParenOrComma); } else { this.ReportError(JSError.NoRightBracketOrComma); } this.SkipTokensAndThrow(); } } catch (RecoveryTokenException exception) { if (exception._partiallyComputedNode != null) { list.Append(exception._partiallyComputedNode); } if (this.IndexOfToken(NoSkipTokenSet.s_ExpressionListNoSkipTokenSet, exception) == -1) { exception._partiallyComputedNode = list; throw exception; } } finally { this.noSkipTokenSet.Remove(NoSkipTokenSet.s_ExpressionListNoSkipTokenSet); } this.GetNextToken(); } } context.UpdateWith(this.currentToken); return list; }