public static CompileTimeConstant /*?*/ SetBooleanTrue(ICompileTimeConstant constExpression) { Contract.Requires(constExpression != null); IConvertible /*?*/ ic = constExpression.Value as IConvertible; if (ic == null) { return(null); } CompileTimeConstant result = new CompileTimeConstant(constExpression); switch (ic.GetTypeCode()) { case System.TypeCode.SByte: result.Value = (SByte)1; break; case System.TypeCode.Int16: result.Value = (Int16)1; break; case System.TypeCode.Int32: result.Value = (Int32)1; break; case System.TypeCode.Int64: result.Value = (Int64)1; break; case System.TypeCode.Byte: result.Value = (Byte)1; break; case System.TypeCode.UInt16: result.Value = (UInt16)1; break; case System.TypeCode.UInt32: result.Value = (UInt32)1; break; case System.TypeCode.UInt64: result.Value = (UInt64)1; break; default: return(null); } return(result); }
/// <summary> /// Visits the specified block. /// </summary> /// <param name="block">The block.</param> public override void Visit(IBlockStatement block) { if (this.insertAssumeFalseAtLine != null) { uint startLine; uint endLine; GetLocationLineSpan(GetPrimarySourceLocationFrom(block.Locations), out startLine, out endLine); if (startLine <= this.insertAssumeFalseAtLine.Value && this.insertAssumeFalseAtLine.Value < endLine) { foreach (IStatement stmt in block.Statements) { GetLocationLineSpan(GetPrimarySourceLocationFrom(stmt.Locations), out startLine, out endLine); GetPrimarySourceLocationFrom(stmt.Locations); if (this.insertAssumeFalseAtLine.Value < endLine) { AssumeStatement assumeFalse = new AssumeStatement(); CompileTimeConstant constFalse = new CompileTimeConstant(); constFalse.Value = false; assumeFalse.Condition = constFalse; this.GetOrCreateStmtListForStmt(stmt).Add(assumeFalse); break; } } } } base.Visit(block); }
private bool isEventCancellationMethodCall(IMethodCall call) { if (!call.MethodToCall.Name.Value.StartsWith("set_Cancel")) { return(false); } if (call.Arguments.Count() != 1 || call.Arguments.ToList()[0].Type != host.PlatformType.SystemBoolean) { return(false); } if (call.ThisArgument == null || !call.ThisArgument.Type.isCancelEventArgsClass(host)) { return(false); } ICompileTimeConstant constant = call.Arguments.ToList()[0] as ICompileTimeConstant; if (constant != null && constant.Value != null) { CompileTimeConstant falseConstant = new CompileTimeConstant() { Type = host.PlatformType.SystemBoolean, Value = false, }; if (constant.Value == falseConstant.Value) { return(false); } } return(true); }
private void checkMethodCallForEventCancellation(IMethodCall call) { // NAVIGATION TODO this code is duplicated from PhoneNavigationTraverser, refactor that if (!call.MethodToCall.Name.Value.StartsWith("set_Cancel")) { return; } if (call.Arguments.Count() != 1 || call.Arguments.ToList()[0].Type != host.PlatformType.SystemBoolean) { return; } ICompileTimeConstant constant = call.Arguments.ToList()[0] as ICompileTimeConstant; if (constant != null && constant.Value != null) { CompileTimeConstant falseConstant = new CompileTimeConstant() { Type = host.PlatformType.SystemBoolean, Value = false, }; if (constant.Value == falseConstant.Value) { return; } } CancelsEvents = true; }
private static IExpression InvertCompileTimeConstant(CompileTimeConstant compileTimeConst) { Contract.Requires(compileTimeConst != null); Contract.Ensures(Contract.Result<IExpression>() != null); Contract.Assume(compileTimeConst.Value is bool); //since it is used as a condition, it is assumed to be a boolean return new CompileTimeConstant() { Value = !(bool)compileTimeConst.Value, Type = compileTimeConst.Type }; }
public override void TraverseChildren(IBlockStatement block) { base.TraverseChildren(block); Contract.Assume(block is BlockStatement); var decompiledBlock = (BlockStatement)block; var statements = decompiledBlock.Statements; for (int i = 0; i < statements.Count - 1; i++) { var switchInstruction = statements[i] as SwitchInstruction; if (switchInstruction == null) { continue; } SwitchStatement result = new SwitchStatement(); result.Expression = switchInstruction.switchExpression; statements[i] = result; for (int j = 0, n = switchInstruction.SwitchCases.Count; j < n; j++) { CompileTimeConstant caseLabel = new CompileTimeConstant() { Value = j, Type = this.host.PlatformType.SystemInt32 }; var gotoCaseBody = switchInstruction.SwitchCases[j]; Contract.Assume(gotoCaseBody != null); SwitchCase currentCase = new SwitchCase() { Expression = caseLabel }; result.Cases.Add(currentCase); if (j < n - 1) { Contract.Assume(switchInstruction.SwitchCases[j + 1] != null); if (gotoCaseBody.TargetStatement == switchInstruction.SwitchCases[j + 1].TargetStatement) { continue; } } currentCase.Body.Add(gotoCaseBody); } if (i == statements.Count - 1) { return; } Contract.Assert(i + 1 <= statements.Count); var gotoStatement = statements[i + 1] as IGotoStatement; if (gotoStatement != null) { SwitchCase defaultCase = new SwitchCase() { }; // Default case is represented by a dummy Expression. defaultCase.Body.Add(statements[i + 1]); statements.RemoveAt(i + 1); result.Cases.Add(defaultCase); } } }
private void DecompileSwitch(List <IStatement> statements, int i) { if (i >= statements.Count - 1) { return; } SwitchInstruction /*?*/ switchInstruction = statements[i] as SwitchInstruction; if (switchInstruction == null) { return; } SwitchStatement result = new SwitchStatement(); result.Expression = switchInstruction.switchExpression; statements[i] = result; for (int j = 0, n = switchInstruction.switchCases.Count; j < n; j++) { CompileTimeConstant caseLabel = new CompileTimeConstant() { Value = j, Type = this.platformType.SystemInt32 }; var gotoCaseBody = switchInstruction.switchCases[j]; SwitchCase currentCase = new SwitchCase() { Expression = caseLabel }; result.Cases.Add(currentCase); if (j < n - 1 && gotoCaseBody.TargetStatement == switchInstruction.switchCases[j + 1].TargetStatement) { continue; } currentCase.Body.Add(gotoCaseBody); } if (i == statements.Count - 1) { return; } var gotoStatement = statements[i + 1] as IGotoStatement; if (gotoStatement != null) { SwitchCase defaultCase = new SwitchCase() { }; // Default case is represented by a dummy Expression. defaultCase.Body.Add(statements[i + 1]); statements.RemoveAt(i + 1); result.Cases.Add(defaultCase); } }
private MethodCall GetPointerValidationCall(IExpression pointer) { CompileTimeConstant pointerSize = new CompileTimeConstant(); pointerSize.Type = pointer.Type.PlatformType.SystemInt32.ResolvedType; pointerSize.Value = pointer.Type.PlatformType.PointerSize; MethodCall mcall = new MethodCall(); mcall.Arguments.Add(pointer); mcall.Arguments.Add(pointerSize); mcall.Locations.Add(PointerIsValidationLocation.For(pointerSize, pointer.Locations)); mcall.MethodToCall = this.PointerValidator; mcall.Type = this.PointerValidator.Type; return(mcall); }
public override void Dispatch(ICodeVisitor visitor) { CompileTimeConstant labelIndex = new CompileTimeConstant(this.rootClass.GetLabelIndex(this.TargetLabel.Name), this.TargetLabel.SourceLocation); labelIndex.SetContainingExpression(this.TargetLabel); List<Expression> arguments = new List<Expression>(1); arguments.Add(labelIndex); IMethodDefinition constructor = Dummy.Method; foreach (IMethodDefinition cons in this.rootClass.TypeDefinition.GetMembersNamed(this.Compilation.NameTable.Ctor, false)) { constructor = cons; break; } Expression thisArgument = new CreateObjectInstanceForResolvedConstructor(constructor, arguments, this.SourceLocation); //^ assume this.ContainingBlock.ContainingMethodDeclaration != null; MethodCall mcall = new ResolvedMethodCall(this.rootClass.MainMethod.MethodDefinition, thisArgument, new List<Expression>(0), this.SourceLocation); ExpressionStatement gosub = new ExpressionStatement(mcall); gosub.Dispatch(visitor); }
protected override Expression ParseBraceLabeledExpression(SourceLocationBuilder slb, TokenSet followers) { var lab = (VccLabeledExpression)this.ParseLabeledExpression(followers | Token.RightBrace); this.Skip(Token.RightBrace); var body = this.ParseExpression(followers); var labString = lab.Label.Name.Value; var labName = new VccByteStringLiteral(labString, lab.Label.SourceLocation); var labArg = lab.Expression; if (labArg is DummyExpression) labArg = new CompileTimeConstant(1, false, lab.Label.SourceLocation); if (labString == "use") { // this condition is sort of a hack, it should likely look at some function \lbl_use(...) or something labArg = new VccByteStringLiteral(labArg.SourceLocation.Source, labArg.SourceLocation); } var args = new[] { labName, labArg, body }; slb.UpdateToSpan(body.SourceLocation); return new VccMethodCall(this.GetSimpleNameFor("\\labeled_expression"), args, slb.GetSourceLocation()); }
// Do not include the type invariant public static List <IExpression> GenerateStateInvariant(IMetadataHost host, State s) { var exprs = new List <IExpression>(); foreach (var action in s.EnabledActions) { if (action.Contract != null) { var conditions = from pre in action.Contract.Preconditions select pre.Condition; exprs.AddRange(conditions); } } foreach (var action in s.DisabledActions) { if (action.Contract == null || !action.Contract.Preconditions.Any()) { var literal = new CompileTimeConstant { Type = host.PlatformType.SystemBoolean, Value = false }; exprs.Add(literal); } else { var conditions = (from pre in action.Contract.Preconditions select pre.Condition).ToList(); var condition = new LogicalNot { Type = host.PlatformType.SystemBoolean, Operand = JoinWithLogicalAnd(host, conditions, true) }; exprs.Add(condition); } } return(exprs); }
private static void AddArrayInitializers(CreateArray createArray, IFieldDefinition initialValueField, ulong[] sizes) { ITypeReference elemType = createArray.ElementType; MemoryStream memoryStream = new MemoryStream(new List <byte>(initialValueField.FieldMapping.Data).ToArray()); BinaryReader reader = new BinaryReader(memoryStream, Encoding.Unicode); ulong flatSize = 1; foreach (ulong dimensionSize in sizes) { flatSize *= dimensionSize; } while (flatSize-- > 0) { CompileTimeConstant cc = new CompileTimeConstant(); cc.Value = ReadValue(elemType.TypeCode, reader); cc.Type = elemType; createArray.Initializers.Add(cc); } }
// Do not include the type invariant protected List <IExpression> GenerateStateInvariant(IReadOnlyCollection <Action> enabledActions, IReadOnlyCollection <Action> disabledActions) { var host = CciHostEnvironment.GetInstance(); var exprs = new List <IExpression>(); foreach (var action in enabledActions) { var conditions = from pre in action.Contract.Preconditions select pre.Condition; exprs.AddRange(conditions); } foreach (var action in disabledActions) { if (action.Contract == null || !action.Contract.Preconditions.Any()) { var literal = new CompileTimeConstant { Type = host.PlatformType.SystemBoolean, Value = false }; exprs.Add(literal); continue; } var conditions = (from pre in action.Contract.Preconditions select pre.Condition).ToList(); var condition = new LogicalNot { Type = host.PlatformType.SystemBoolean, Operand = Helper.JoinWithLogicalAnd(host, conditions, true) }; exprs.Add(condition); } return(exprs); }
/// <summary> /// Convert a string to an initializer. "12" will be turned to {'1','2'}. Zeros will /// be patched if the length of the string is smaller than size. If the length of the /// string is greater than size, then only the first size of chars will be converted, /// unless if size is zero or less, in which case, the count number of chars will be /// converted. /// </summary> /// <param name="initialValue">The initial string</param> /// <param name="size">The target size</param> /// <param name="parent">The parent expression</param> /// <returns></returns> public static VccInitializer fromStringWithPatchedZeros(string initialValue, int size, Expression parent) { if (initialValue == null) return null; int count = initialValue.Length; if (size <= 0) size = count; char[] charArr = initialValue.ToCharArray(); List<Expression> exprs = new List<Expression>(); VccInitializer result = new VccInitializer(exprs, false, SourceDummy.SourceLocation); for (uint i = 0; i < size; i++) { if (i < count) { sbyte val = (sbyte)charArr[i]; Expression ch = new CompileTimeConstant(val, parent.SourceLocation); ch.SetContainingExpression(parent); exprs.Add(ch); } // If we dont have enough element, we patch zero. It is intentional that no '\0' is added // if size == count. else { Expression zeroPatch = new CompileTimeConstant(0, parent.SourceLocation); zeroPatch.SetContainingExpression(parent); exprs.Add(zeroPatch); } } result.SetContainingExpression(parent); return result; }
protected static void AddInitializationTo(ICollection<Statement> statements, Expression source, Expression target, TypeExpression targetType, BlockStatement containingBlock) { VccInitializer initializer = source as VccInitializer; if (initializer != null) { VccArrayTypeExpression arrayType = initializer.arrayTypeExpression ?? targetType as VccArrayTypeExpression; if (arrayType != null) { initializer.AddInitializingElementAssignmentsTo(statements, target, arrayType); } else if (initializer.IsOfStructuredType) { VccStructuredTypeDeclaration structType = initializer.GetStructuredTypeDecl(); if (structType != null) initializer.AddInitializingFieldAssignmentsTo(statements, target, structType); } } else { // It is not an initializer // If the expression is a string and the target is a char array, in which case we treat it as an array initializer. VccByteStringLiteral stringLiteral = source as VccByteStringLiteral; VccArrayTypeExpression arrayType = targetType as VccArrayTypeExpression; if (stringLiteral != null && arrayType != null) { string val = stringLiteral.Value as string; if (val != null) { if (arrayType.Size == null) { CompileTimeConstant ctc = new CompileTimeConstant(val.Length + 1, stringLiteral.SourceLocation); ctc.SetContainingExpression(stringLiteral); arrayType.ResetSizeWhenProvidedByInitializer(ctc); } int size = arrayType.SizeAsInt32; VccInitializer newInitializer = VccInitializer.fromStringWithPatchedZeros(val, size, stringLiteral); // No need to assign the array type expression field, because we know the element type is char. if (newInitializer != null) { newInitializer.AddInitializingElementAssignmentsTo(statements, target, arrayType); } } } else { // If the target is a union, we will try to treat the constant as an initializer. CompileTimeConstant ctc = source as CompileTimeConstant; VccUnionDeclaration unionType = MiniResolve(containingBlock.ContainingNamespaceDeclaration, targetType as VccNamedTypeExpression) as VccUnionDeclaration; if (ctc != null && unionType != null) { List<Expression> exprs = new List<Expression> {ctc}; VccInitializer newInitializer = new VccInitializer(exprs, false, source.SourceLocation); newInitializer.SetContainingBlock(containingBlock); newInitializer.AddInitializingFieldAssignmentsTo(statements, target, unionType); } else { // otherwise, generate an assignment. ExpressionStatement elementAssignment = new ExpressionStatement(new Assignment(new TargetExpression(target), source, source.SourceLocation)); elementAssignment.SetContainingBlock(containingBlock); statements.Add(elementAssignment); } } } }
internal static PointerIsValidationLocation For(CompileTimeConstant pointerSize, IEnumerable <ILocation> locations) { IPrimarySourceLocation ploc = AssertAssumeAdderVisitor.GetPrimarySourceLocationFrom(locations); return(new PointerIsValidationLocation(pointerSize, ploc)); }
private PointerIsValidationLocation(CompileTimeConstant pointerSize, IPrimarySourceLocation expressionLocation) : base(expressionLocation) { this.pointerSize = pointerSize; }
//^ requires compileTimeConstant.ValueIsPolymorhpicCompileTimeConstant; /// <summary> /// Initializes a numeric literal that could be interpreted as either signed or unsigned, depending on the type of another expression with which it is combined in a binary operator expression. /// </summary> /// <param name="compileTimeConstant">A polymorphic compile time constant.</param> /// <param name="expression">An expression that determines which sign this polymorhpic sign agnostic constant will assume when asked what its type is.</param> public VccCompileTimeConstantWhoseSignDependsOnAnotherExpression(CompileTimeConstant compileTimeConstant, Expression expression) : base(null, true, compileTimeConstant.SourceLocation) { this.compileTimeConstant = compileTimeConstant; this.expression = expression; }
private static IExpression ConvertToBoolean(IExpression expression) { Contract.Requires(expression != null); Contract.Ensures(Contract.Result <IExpression>() != null); IPlatformType platformType = expression.Type.PlatformType; var cc = expression as CompileTimeConstant; if (cc != null && TypeHelper.IsPrimitiveInteger(cc.Type)) { cc.Value = !ExpressionHelper.IsIntegralZero(cc); cc.Type = platformType.SystemBoolean; return(cc); } var conditional = expression as Conditional; if (conditional != null) { conditional.ResultIfTrue = ConvertToBoolean(conditional.ResultIfTrue); conditional.ResultIfFalse = ConvertToBoolean(conditional.ResultIfFalse); conditional.Type = platformType.SystemBoolean; return(conditional); } object /*?*/ val = null; ITypeReference type = platformType.SystemObject; ITypeReference expressionType = expression.Type; IExpression rightOperand = null; // zero or null, but has to be type-specific switch (expressionType.TypeCode) { case PrimitiveTypeCode.Boolean: { var addrDeref = expression as AddressDereference; Conversion conversion; IManagedPointerTypeReference mgdPtr; if (addrDeref != null && (conversion = addrDeref.Address as Conversion) != null && (mgdPtr = conversion.ValueToConvert.Type as IManagedPointerTypeReference) != null) { expressionType = mgdPtr.TargetType; addrDeref.Address = conversion.ValueToConvert; addrDeref.Type = expressionType; expression = addrDeref; goto default; } return(expression); } case PrimitiveTypeCode.Char: val = (char)0; type = platformType.SystemChar; break; case PrimitiveTypeCode.Float32: val = (float)0; type = platformType.SystemFloat32; break; case PrimitiveTypeCode.Float64: val = (double)0; type = platformType.SystemFloat64; break; case PrimitiveTypeCode.Int16: val = (short)0; type = platformType.SystemInt16; break; case PrimitiveTypeCode.Int32: val = (int)0; type = platformType.SystemInt32; break; case PrimitiveTypeCode.Int64: val = (long)0; type = platformType.SystemInt64; break; case PrimitiveTypeCode.Int8: val = (sbyte)0; type = platformType.SystemInt8; break; case PrimitiveTypeCode.IntPtr: val = IntPtr.Zero; type = platformType.SystemIntPtr; break; case PrimitiveTypeCode.UInt16: val = (ushort)0; type = platformType.SystemUInt16; break; case PrimitiveTypeCode.UInt32: val = (uint)0; type = platformType.SystemUInt32; break; case PrimitiveTypeCode.UInt64: val = (ulong)0; type = platformType.SystemUInt64; break; case PrimitiveTypeCode.UInt8: val = (byte)0; type = platformType.SystemUInt8; break; case PrimitiveTypeCode.UIntPtr: val = UIntPtr.Zero; type = platformType.SystemUIntPtr; break; default: rightOperand = new DefaultValue() { DefaultValueType = expressionType, Type = expressionType, }; break; } if (rightOperand == null) { rightOperand = new CompileTimeConstant() { Value = val, Type = type, }; } NotEquality result = new NotEquality() { LeftOperand = expression, RightOperand = rightOperand, Type = platformType.SystemBoolean, }; return(result); }
/// <summary> /// Adds zero or more assignments statements to the giving collection. Executing these statements will initialize the field. /// </summary> protected override void AddInitializingAssignmentsTo(ICollection<Statement> statements) { VccInitializer/*?*/ vcInit = this.Initializer as VccInitializer; if (vcInit != null) { VccArrayTypeExpression/*?*/ vcArrTypeExpr = this.Type as VccArrayTypeExpression; if (vcArrTypeExpr != null) { SimpleName fieldName = new SimpleName(this.Name, this.Name.SourceLocation, false); Expression pointerToField = fieldName; vcInit.AddInitializingElementAssignmentsTo(statements, pointerToField, vcArrTypeExpr); return; } VccNamedTypeExpression/*?*/ vcStructTypeExpr = this.Type as VccNamedTypeExpression; if (vcStructTypeExpr != null) { SimpleName varName = new SimpleName(this.Name, this.Name.SourceLocation, false); /* Because this is global variable, its type must be in the global scope, for which we can find the names of the fields. * A mini-resolve to find the list of field names. The standard resolve will not work * because we are in the process of resolving when this method is called. */ SimpleName/*?*/ typeName = vcStructTypeExpr.Expression as SimpleName; if (typeName == null) return; int typeNameUniqueKey = typeName.Name.UniqueKey; VccStructuredTypeDeclaration/*?*/ typeDecl = null; foreach (VccStructuredTypeDeclaration td in IteratorHelper.GetFilterEnumerable<INamespaceDeclarationMember, VccStructuredTypeDeclaration>(this.ContainingNamespaceDeclaration.Members)) { if (td.Name.UniqueKey == typeNameUniqueKey) { typeDecl = td; break; } } /* Now we send this field name list to generate assignment statements that initialize the fields of the current variable. */ if (typeDecl != null) vcInit.AddInitializingFieldAssignmentsTo(statements, varName, typeDecl); // TODO: name resolution error. return; } } // if the initializer is a string, and the type is a char array, convert the string into an // array initializer and continue VccByteStringLiteral stringLiteral = this.initializer as VccByteStringLiteral; VccArrayTypeExpression arrayType = this.Type as VccArrayTypeExpression; if (stringLiteral != null && arrayType != null) { string val = stringLiteral.Value as string; if (val != null) { // If the char array to be initialized doesnt have a size, set its size to hold the // initial string literal plus 1 (for the terminating zero). if (arrayType.Size == null) { CompileTimeConstant ctc = new CompileTimeConstant(val.Length + 1, stringLiteral.SourceLocation); ctc.SetContainingExpression(stringLiteral); arrayType.ResetSizeWhenProvidedByInitializer(ctc); } int size = arrayType.SizeAsInt32; Expression newInitializer = VccInitializer.fromStringWithPatchedZeros(val, size, stringLiteral); if (newInitializer != null) { this.initializer = newInitializer; this.AddInitializingAssignmentsTo(statements); } } } base.AddInitializingAssignmentsTo(statements); }
private CompileTimeConstant ParseIntegerLiteral() //^ requires this.currentToken == Token.IntegerLiteral; { string tokStr = this.scanner.GetTokenSource(); SourceLocationBuilder ctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); TypeCode tc = this.scanner.ScanNumberSuffix(); ctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); CompileTimeConstant result; switch (tc) { case TypeCode.Single: float f; if (!Single.TryParse(tokStr, System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out f)) { this.HandleError(ctx, Error.FloatOverflow); f = float.NaN; } result = new CompileTimeConstant(f, false, ctx); break; case TypeCode.Double: double d; if (!Double.TryParse(tokStr, System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out d)) { this.HandleError(ctx, Error.FloatOverflow); d = double.NaN; } result = new CompileTimeConstant(d, false, ctx); break; case TypeCode.Decimal: decimal m; if (!decimal.TryParse(tokStr, System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out m)) { this.HandleError(ctx, Error.IntOverflow); m = decimal.Zero; } result = new CompileTimeConstant(m, false, ctx); break; default: ulong ul; if (!UInt64.TryParse(tokStr, System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out ul)) { this.HandleError(ctx, Error.IntOverflow); ul = 0; } result = GetConstantOfSmallestIntegerTypeThatIncludes(ul, tc, ctx); break; } //^ assume this.currentToken == Token.IntegerLiteral; //follows from the precondition this.GetNextToken(); return result; }
private Expression ParsePrimaryExpression(TokenSet followers) //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { ISourceLocation sctx = this.scanner.SourceLocationOfLastScannedToken; Expression expression = new DummyExpression(sctx); switch (this.currentToken) { case Token.ArgList: this.GetNextToken(); expression = new RuntimeArgumentHandleExpression(sctx); break; case Token.Delegate: expression = this.ParseAnonymousMethod(followers); break; case Token.New: expression = this.ParseNew(followers|Token.Dot|Token.LeftBracket|Token.Arrow); break; case Token.Identifier: expression = this.ParseSimpleName(followers|Token.Dot|Token.DoubleColon|Token.Lambda|Token.LeftParenthesis); if (this.currentToken == Token.DoubleColon) { if (((SimpleName)expression).Name == this.nameTable.global) expression = new RootNamespaceExpression(expression.SourceLocation); expression = this.ParseQualifiedName(expression, followers|Token.Dot|Token.LessThan|Token.LeftParenthesis|Token.AddOne|Token.SubtractOne); } else if (this.currentToken == Token.Lambda) { expression = this.ParseLambda((SimpleName)expression, followers); } break; case Token.Null: expression = new NullLiteral(sctx); this.GetNextToken(); break; case Token.True: expression = new CompileTimeConstant(true, false, sctx); this.GetNextToken(); break; case Token.False: expression = new CompileTimeConstant(false, false, sctx); this.GetNextToken(); break; case Token.CharLiteral: expression = new CompileTimeConstant(this.scanner.charLiteralValue, false, sctx); this.GetNextToken(); break; case Token.HexLiteral: expression = this.ParseHexLiteral(); break; case Token.IntegerLiteral: expression = this.ParseIntegerLiteral(); break; case Token.RealLiteral: expression = this.ParseRealLiteral(); break; case Token.StringLiteral: expression = new CompileTimeConstant(this.scanner.GetString(), false, sctx); this.GetNextToken(); break; case Token.This: expression = new ThisReference(sctx); this.GetNextToken(); break; case Token.Base: expression = new BaseClassReference(sctx); this.GetNextToken(); break; case Token.Typeof: case Token.Sizeof: case Token.Default: expression = this.ParseTypeofSizeofOrDefault(followers); break; case Token.Stackalloc: return this.ParseStackalloc(followers); case Token.Checked: case Token.MakeRef: case Token.RefType: case Token.Unchecked: expression = this.ParseCheckedOrMakeRefOrRefTypeOrUnchecked(followers); break; case Token.RefValue: expression = this.ParseGetValueOfTypedReference(followers); break; case Token.Bool: case Token.Decimal: case Token.Sbyte: case Token.Byte: case Token.Short: case Token.Ushort: case Token.Int: case Token.Uint: case Token.Long: case Token.Ulong: case Token.Char: case Token.Float: case Token.Double: case Token.Object: case Token.String: expression = this.RootQualifiedNameFor(this.currentToken, sctx); this.GetNextToken(); break; case Token.LeftParenthesis: expression = this.ParseCastExpression(followers|Token.Dot|Token.LeftBracket|Token.Arrow); break; default: if (Parser.IdentifierOrNonReservedKeyword[this.currentToken]) goto case Token.Identifier; if (Parser.InfixOperators[this.currentToken]) { this.HandleError(Error.InvalidExprTerm, this.scanner.GetTokenSource()); //^ assume this.currentToken != Token.EndOfFile; //should not be a member of InfixOperators this.GetNextToken(); } else this.SkipTo(followers|Parser.PrimaryStart, Error.InvalidExprTerm, this.scanner.GetTokenSource()); if (Parser.PrimaryStart[this.currentToken]) return this.ParsePrimaryExpression(followers); goto done; } expression = this.ParseIndexerCallOrSelector(expression, followers|Token.AddOne|Token.SubtractOne); for (; ; ) { switch (this.currentToken) { case Token.AddOne: SourceLocationBuilder slb = new SourceLocationBuilder(expression.SourceLocation); slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); this.GetNextToken(); expression = new PostfixIncrement(new TargetExpression(expression), slb); break; case Token.SubtractOne: slb = new SourceLocationBuilder(expression.SourceLocation); slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); this.GetNextToken(); expression = new PostfixDecrement(new TargetExpression(expression), slb); break; case Token.Arrow: case Token.Dot: case Token.LeftBracket: expression = this.ParseIndexerCallOrSelector(expression, followers|Token.AddOne|Token.SubtractOne); break; default: goto done; } } done: this.SkipTo(followers); return expression; }
private Expression ConvertToDelegate(Expression expression, ITypeDefinition targetType, int labelIndex, RootClassDeclaration rootClass) { IMethodDefinition invokeMethod = this.GetInvokeMethod(targetType); if (invokeMethod != Dummy.Method && invokeMethod.Type.TypeCode == PrimitiveTypeCode.Void && IteratorHelper.EnumerableIsEmpty(invokeMethod.Parameters)) { IMethodDefinition matchingMethod = rootClass.MainMethod.MethodDefinition; CompileTimeConstant constant = new CompileTimeConstant(labelIndex, SourceDummy.SourceLocation); constant.SetContainingExpression(expression); Expression instance = this.GetRootClassInstance(constant, rootClass); return new CreateDelegateInstance(instance, targetType, matchingMethod, expression.SourceLocation); } return base.ImplicitConversion(expression, targetType); }
//^ requires template.ContainingBlock != containingBlock; //^ ensures this.containingBlock == containingBlock; /// <summary> /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block. /// </summary> /// <param name="containingBlock">A new value for containing block. This replaces template.ContainingBlock in the resulting copy of template.</param> /// <param name="template">The template to copy.</param> protected VccCompileTimeConstantWhoseSignDependsOnAnotherExpression(BlockStatement containingBlock, VccCompileTimeConstantWhoseSignDependsOnAnotherExpression template) : base(containingBlock, template) { this.compileTimeConstant = (CompileTimeConstant)template.compileTimeConstant.MakeCopyFor(containingBlock); this.expression = template.expression.MakeCopyFor(containingBlock); }
/// <summary> /// Returns an object that implements IExpression and that represents this expression after language specific rules have been /// applied to it in order to determine its semantics. The resulting expression is a standard representation of the semantics /// of this expression, suitable for use by language agnostic clients and complete enough for translation of the expression /// into IL. /// </summary> protected override IExpression ProjectAsNonConstantIExpression() { CompileTimeConstant result = new CompileTimeConstant(TypeHelper.TypeAlignment(this.typeExpression.ResolvedType), this.SourceLocation); result.SetContainingExpression(this); return result; }
public static IExpression Normalize(IExpression expression) { LogicalNot /*?*/ logicalNot = expression as LogicalNot; if (logicalNot != null) { IExpression operand = logicalNot.Operand; #region LogicalNot: ! LogicalNot /*?*/ operandAsLogicalNot = operand as LogicalNot; if (operandAsLogicalNot != null) { return(Normalize(operandAsLogicalNot.Operand)); } #endregion #region BinaryOperations: ==, !=, <, <=, >, >= BinaryOperation /*?*/ binOp = operand as BinaryOperation; if (binOp != null) { BinaryOperation /*?*/ result = null; if (binOp is IEquality) { result = new NotEquality(); } else if (binOp is INotEquality) { result = new Equality(); } else if (binOp is ILessThan) { result = new GreaterThanOrEqual(); } else if (binOp is ILessThanOrEqual) { result = new GreaterThan(); } else if (binOp is IGreaterThan) { result = new LessThanOrEqual(); } else if (binOp is IGreaterThanOrEqual) { result = new LessThan(); } if (result != null) { result.LeftOperand = Normalize(binOp.LeftOperand); result.RightOperand = Normalize(binOp.RightOperand); return(result); } } #endregion #region Conditionals: &&, || Conditional /*?*/ conditional = operand as Conditional; if (conditional != null) { if (ExpressionHelper.IsIntegralNonzero(conditional.ResultIfTrue) || ExpressionHelper.IsIntegralZero(conditional.ResultIfFalse)) { Conditional result = new Conditional(); LogicalNot not; //invert condition not = new LogicalNot(); not.Operand = conditional.Condition; result.Condition = Normalize(not); //invert false branch and switch with true branch not = new LogicalNot(); not.Operand = conditional.ResultIfFalse; result.ResultIfTrue = Normalize(not); //invert true branch and switch with false branch not = new LogicalNot(); not.Operand = conditional.ResultIfTrue; result.ResultIfFalse = Normalize(not); //return result.Type = conditional.Type; return(result); } } #endregion #region Constants: true, false CompileTimeConstant /*?*/ ctc = operand as CompileTimeConstant; if (ctc != null) { if (ExpressionHelper.IsIntegralNonzero(ctc)) //Is true { var val = SetBooleanFalse(ctc); if (val != null) { return(val); } else { return(expression); } } else if (ExpressionHelper.IsIntegralZero(ctc)) //Is false { var val = SetBooleanTrue(ctc); if (val != null) { return(val); } else { return(expression); } } } #endregion } return(expression); }
internal static List<SourceCustomAttribute> ConvertSpecifiersIntoAttributes(IEnumerable<Specifier> specifiers, Expression/*!*/ containingExpression) { List<SourceCustomAttribute> result = new List<SourceCustomAttribute>(1); foreach (Specifier specifier in specifiers) { DeclspecSpecifier/*?*/ declSpec = specifier as DeclspecSpecifier; if (declSpec != null) { List<Expression> arguments = new List<Expression>(declSpec.Modifiers); if (arguments.Count < 1) continue; Expression attributeTypeName = arguments[0]; SimpleName/*?*/ simpleName = attributeTypeName as SimpleName; if (!(simpleName != null || attributeTypeName is QualifiedName || attributeTypeName is AliasQualifiedName)) continue; if (simpleName != null && IsUnsupportedDeclspec(simpleName.Name.Value)) continue; AttributeTypeExpression attributeType = new AttributeTypeExpression(attributeTypeName); arguments.RemoveAt(0); SourceCustomAttribute custAttr = new SourceCustomAttribute(AttributeTargets.All, attributeType, arguments, declSpec.SourceLocation); custAttr.SetContainingExpression(containingExpression); result.Add(custAttr); } else { SpecDeclspecSpecifier specTokenSpec = specifier as SpecDeclspecSpecifier; if (specTokenSpec != null) { var attrTypeName = NamespaceHelper.CreateInSystemDiagnosticsContractsCodeContractExpr(containingExpression.ContainingBlock.Compilation.NameTable, "StringVccAttr"); AttributeTypeExpression attrType = new AttributeTypeExpression(attrTypeName); var argument = new CompileTimeConstant(specTokenSpec.Argument, specTokenSpec.SourceLocation); List<Expression> args = new List<Expression> { new CompileTimeConstant(specTokenSpec.Token, specTokenSpec.SourceLocation), argument }; SourceCustomAttribute custAttr = new SourceCustomAttribute(AttributeTargets.All, attrType, args, specTokenSpec.SourceLocation); custAttr.SetContainingExpression(containingExpression); result.Add(custAttr); } } } result.TrimExcess(); return result; }
private static CompileTimeConstant GetConstantOfSmallestIntegerTypeThatIncludes(ulong ul, TypeCode tc, SourceLocationBuilder ctx) { CompileTimeConstant result; if (ul <= int.MaxValue && tc == TypeCode.Empty) result = new CompileTimeConstant((int)ul, tc == TypeCode.Empty, ctx); else if (ul <= uint.MaxValue && (tc == TypeCode.Empty || tc == TypeCode.UInt32)) result = new CompileTimeConstant((uint)ul, tc == TypeCode.Empty, ctx); else if (ul <= long.MaxValue && (tc == TypeCode.Empty || tc == TypeCode.Int64)) result = new CompileTimeConstant((long)ul, tc == TypeCode.Empty, ctx); else result = new CompileTimeConstant(ul, tc == TypeCode.Empty, ctx); return result; }
private CompileTimeConstant ParseRealLiteral() //^ requires this.currentToken == Token.RealLiteral; { string tokStr = this.scanner.GetTokenSource(); SourceLocationBuilder ctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); TypeCode tc = this.scanner.ScanNumberSuffix(); ctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); CompileTimeConstant result; string/*?*/ typeName = null; switch (tc) { case TypeCode.Single: typeName = "float"; float fVal; if (!Single.TryParse(tokStr, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out fVal)) this.HandleError(ctx, Error.FloatOverflow, typeName); else if (fVal == 0f && tokStr.IndexOfAny(nonZeroDigits) >= 0) this.HandleError(ctx, Error.FloatOverflow, typeName); result = new CompileTimeConstant(fVal, false, ctx); break; case TypeCode.Empty: case TypeCode.Double: typeName = "double"; double dVal; if (!Double.TryParse(tokStr, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out dVal)) this.HandleError(ctx, Error.FloatOverflow, typeName); else if (dVal == 0d && tokStr.IndexOfAny(nonZeroDigits) >= 0) this.HandleError(ctx, Error.FloatOverflow, typeName); result = new CompileTimeConstant(dVal, tc == TypeCode.Empty, ctx); break; case TypeCode.Decimal: typeName = "decimal"; decimal decVal; if (!Decimal.TryParse(tokStr, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out decVal)) this.HandleError(ctx, Error.FloatOverflow, typeName); result = new CompileTimeConstant(decVal, false, ctx); break; default: this.HandleError(Error.ExpectedSemicolon); goto case TypeCode.Empty; } //^ assume this.currentToken == Token.RealLiteral; //follows from the precondition this.GetNextToken(); return result; }
private void InitializeTraverser() { Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; coreAssemblyRef = platform.CoreAssemblyRef; // TODO obtain version, culture and signature data dynamically AssemblyIdentity MSPhoneAssemblyId = new AssemblyIdentity(host.NameTable.GetNameFor("Microsoft.Phone"), "", new Version("7.0.0.0"), new byte[] { 0x24, 0xEE, 0xC0, 0xD8, 0xC8, 0x6C, 0xDA, 0x1E }, ""); AssemblyIdentity MSPhoneControlsAssemblyId = new AssemblyIdentity(host.NameTable.GetNameFor("Microsoft.Phone.Controls"), "", new Version("7.0.0.0"), new byte[] { 0x24, 0xEE, 0xC0, 0xD8, 0xC8, 0x6C, 0xDA, 0x1E }, ""); AssemblyIdentity MSPhoneSystemWindowsAssemblyId = new AssemblyIdentity(host.NameTable.GetNameFor("System.Windows"), coreAssemblyRef.Culture, coreAssemblyRef.Version, coreAssemblyRef.PublicKeyToken, ""); phoneAssembly = host.FindAssembly(MSPhoneAssemblyId); phoneSystemWindowsAssembly = host.FindAssembly(MSPhoneSystemWindowsAssemblyId); MSPhoneControlsAssembly = host.FindAssembly(MSPhoneControlsAssemblyId); // TODO BUG / XAML DEPENDENCE If a control is declared in XAML, it may be one from a library *not* linked! So, assemblies could be dummy here // TODO determine the needed types dynamically if (phoneAssembly != Dummy.Assembly) { appBarIconButtonType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarIconButton"); appBarMenuItemType = platform.CreateReference(phoneAssembly, "Microsoft", "Phone", "Shell", "ApplicationBarMenuItem"); } else { appBarIconButtonType = host.PlatformType.SystemObject; appBarMenuItemType = host.PlatformType.SystemObject; } if (phoneSystemWindowsAssembly != Dummy.Assembly) { checkBoxType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "CheckBox"); radioButtonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "RadioButton"); buttonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Button"); buttonBaseType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Primitives", "ButtonBase"); toggleButtonType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Primitives", "ToggleButton"); controlType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "Control"); uiElementType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "UIElement"); listBoxType = platform.CreateReference(phoneSystemWindowsAssembly, "System", "Windows", "Controls", "ListBox"); } else { checkBoxType = host.PlatformType.SystemObject; radioButtonType = host.PlatformType.SystemObject; buttonType = host.PlatformType.SystemObject; buttonBaseType = host.PlatformType.SystemObject; toggleButtonType = host.PlatformType.SystemObject; controlType = host.PlatformType.SystemObject; uiElementType = host.PlatformType.SystemObject; listBoxType = host.PlatformType.SystemObject; } if (MSPhoneControlsAssembly != Dummy.Assembly) { pivotType = platform.CreateReference(MSPhoneControlsAssembly, "Microsoft", "Phone", "Controls", "Pivot"); } else { pivotType = host.PlatformType.SystemObject; } trueConstant = new CompileTimeConstant() { Type = platform.SystemBoolean, Value = true }; falseConstant = new CompileTimeConstant() { Type = platform.SystemBoolean, Value = false }; IEnumerable <IPropertyDefinition> controlProperties = controlType.ResolvedType.Properties; IEnumerable <IPropertyDefinition> toggleButtonProperties = toggleButtonType.ResolvedType.Properties; IEnumerable <IPropertyDefinition> uiElementProperties = uiElementType.ResolvedType.Properties; IPropertyDefinition prop = controlProperties.Single(p => p.Name.Value == "IsEnabled"); isEnabledSetter = prop.Setter; isEnabledGetter = prop.Getter; prop = toggleButtonProperties.Single(p => p.Name.Value == "IsChecked"); isCheckedSetter = prop.Setter; isCheckedGetter = prop.Getter; prop = uiElementProperties.Single(p => p.Name.Value == "Visibility"); visibilitySetter = prop.Setter; visibilityGetter = prop.Getter; IEnumerable <IEventDefinition> buttonBaseEvents = buttonBaseType.ResolvedType.Events; IEnumerable <IEventDefinition> toggleButtonEvents = toggleButtonType.ResolvedType.Events; IEventDefinition evt = buttonBaseEvents.Single(e => e.Name.Value == "Click"); clickHandlerAdder = evt.Adder; clickHandlerRemover = evt.Remover; evt = toggleButtonEvents.Single(e => e.Name.Value == "Checked"); checkedHandlerAdder = evt.Adder; checkedHandlerRemover = evt.Remover; evt = toggleButtonEvents.Single(e => e.Name.Value == "Unchecked"); uncheckedHandlerAdder = evt.Adder; uncheckedHandlerRemover = evt.Remover; }
private Expression ParseSimpleExpression(TokenSet followers) { Expression result; TokenSet followersOrDotOrLeftParensOrLeftBracket = followers|Token.Dot|Token.LeftParens|Token.LeftBracket; switch (this.currentToken) { case Token.False: result = new CompileTimeConstant(false, this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.Identifier: result = this.ParseSimpleName(followersOrDotOrLeftParensOrLeftBracket); break; case Token.NumericLiteral: result = new CompileTimeConstant(decimal.Parse(this.scanner.GetTokenSource(), System.Globalization.CultureInfo.InvariantCulture), this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.StringLiteral: result = new CompileTimeConstant(this.scanner.GetTokenSource().Trim('"'), this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.True: result = new CompileTimeConstant(true, this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.LeftParens: result = this.ParseParenthesizedExpression(followersOrDotOrLeftParensOrLeftBracket); break; default: //TODO: error result = new DummyExpression(this.scanner.CurrentSourceLocation); break; } SourceLocationBuilder slb = new SourceLocationBuilder(result.SourceLocation); while (true) { switch (this.currentToken) { case Token.Dot: { this.GetNextToken(); SmallBasicSimpleName simpleName = this.ParseSimpleName(followers|Token.Dot|Token.Equals|Token.LeftBracket|Token.LeftParens|Token.EndOfLine); slb.UpdateToSpan(simpleName.SourceLocation); result = new QualifiedName(result, simpleName, slb); continue; } case Token.LeftBracket: { this.GetNextToken(); IEnumerable<Expression> indices = this.ParseExpressions(slb, Token.RightBracket, followers|Token.Dot|Token.Equals|Token.LeftBracket|Token.LeftParens|Token.EndOfLine); result = new SmallBasicIndexer(result, indices, slb); continue; } case Token.LeftParens: { this.GetNextToken(); IEnumerable<Expression> indices = this.ParseExpressions(slb, Token.RightParens, followers|Token.Dot|Token.Equals|Token.LeftBracket|Token.LeftParens|Token.EndOfLine); result = new MethodCall(result, indices, slb); //TODO: change this to VBMethodCall continue; } } break; } this.SkipTo(followers); return result; }
internal PlatformInvokeInformation(ITypeDeclarationMember declaringMember, SourceCustomAttribute dllImportAttribute) { this.importModule = Dummy.ModuleReference; this.importName = declaringMember.Name.Name; this.noMangle = false; this.pinvokeCallingConvention = PInvokeCallingConvention.WinApi; this.stringFormat = StringFormatKind.Unspecified; this.useBestFit = null; this.throwExceptionForUnmappableChar = null; INameTable nameTable = dllImportAttribute.ContainingBlock.NameTable; int bestFitMappingKey = nameTable.GetNameFor("BestFitMapping").UniqueKey; int callingConventionKey = nameTable.GetNameFor("CallingConvention").UniqueKey; int charSetKey = nameTable.GetNameFor("CharSet").UniqueKey; int entryPointKey = nameTable.GetNameFor("EntryPoint").UniqueKey; int exactSpellingKey = nameTable.GetNameFor("ExactSpelling").UniqueKey; int setLastErrorKey = nameTable.GetNameFor("SetLastError").UniqueKey; int throwOnUnmappableCharKey = nameTable.GetNameFor("ThrowOnUnmappableChar").UniqueKey; foreach (Expression expr in dllImportAttribute.Arguments) { CompileTimeConstant cc = expr as CompileTimeConstant; if (cc != null && cc.Value is string) { IName moduleName = expr.NameTable.GetNameFor((string)cc.Value); this.importModule = new Immutable.ModuleReference(dllImportAttribute.ContainingBlock.Compilation.HostEnvironment, new ModuleIdentity(moduleName, string.Empty)); continue; } NamedArgument narg = expr as NamedArgument; if (narg == null) { continue; } int key = narg.ArgumentName.Name.UniqueKey; if (key == bestFitMappingKey) { if (narg.ArgumentValue.Value is bool) { this.useBestFit = (bool)narg.ArgumentValue.Value; } continue; } if (key == callingConventionKey) { if (narg.ArgumentValue.Value is int) { switch ((CallingConvention)(int)narg.ArgumentValue.Value) { case CallingConvention.C: this.pinvokeCallingConvention = PInvokeCallingConvention.CDecl; break; case CallingConvention.Standard: this.pinvokeCallingConvention = PInvokeCallingConvention.StdCall; break; case CallingConvention.ExplicitThis: this.pinvokeCallingConvention = PInvokeCallingConvention.ThisCall; break; case CallingConvention.FastCall: this.pinvokeCallingConvention = PInvokeCallingConvention.FastCall; break; } } continue; } if (key == charSetKey) { if (narg.ArgumentValue.Value is int) { switch ((CharSet)(int)narg.ArgumentValue.Value) { case CharSet.Ansi: this.stringFormat = StringFormatKind.Ansi; break; case CharSet.Auto: this.stringFormat = StringFormatKind.AutoChar; break; case CharSet.Unicode: this.stringFormat = StringFormatKind.Unicode; break; } } continue; } if (key == entryPointKey) { string /*?*/ importName = narg.ArgumentValue.Value as string; if (importName != null) { this.importName = nameTable.GetNameFor(importName); } continue; } if (key == exactSpellingKey) { if (narg.ArgumentValue.Value is bool) { this.noMangle = (bool)narg.ArgumentValue.Value; } continue; } if (key == setLastErrorKey) { if (narg.ArgumentValue.Value is bool) { this.supportsLastError = (bool)narg.ArgumentValue.Value; } continue; } if (key == throwOnUnmappableCharKey) { if (narg.ArgumentValue.Value is bool) { this.throwExceptionForUnmappableChar = (bool)narg.ArgumentValue.Value; } continue; } } }
private Expression GetRootClassInstance(CompileTimeConstant labelIndex, RootClassDeclaration rootClass) { List<Expression> arguments = new List<Expression>(1); arguments.Add(labelIndex); foreach (IMethodDefinition constructor in rootClass.TypeDefinition.GetMembersNamed(this.Compilation.NameTable.Ctor, false)) { return new CreateObjectInstanceForResolvedConstructor(constructor, arguments, SourceDummy.SourceLocation); } //^ assume false; return labelIndex; }