/// <summary> /// Create and add an instruction. /// /// This seems to be a dangerous overload, since it may hide the one below if operand is null. /// We can't remove it without checking all ~170 usages though... /// </summary> public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode, params Register[] registers) { if(registers.Any(r=> r == null)) throw new InvalidOperationException("Register must not be null. Wrong overload?"); return builder.Add(sequencePoint, opcode, (object)null, registers); }
public TranslationMessage(ISourceLocation loc, int code, string msg, bool isWarning) { this.loc = loc; this.code = code; this.msg = msg; this.isWarning = isWarning; }
/// <summary> /// Create code to box the given source value into the given type. /// </summary> public static RLRange Box(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame) { if (type.IsPrimitive) { if (type.IsByte()) builder.Add(sequencePoint, RCode.Int_to_byte, source.Register, source.Register); else if (type.IsUInt16()) builder.Add(sequencePoint, RCode.Int_to_short, source.Register, source.Register); // Call appropriate valueOf method var boxedType = type.Module.TypeSystem.Object; var r = frame.AllocateTemp(boxedType.GetReference(targetPackage)); var call = builder.Add(sequencePoint, RCode.Invoke_static, type.GetBoxValueOfMethod(), source.Registers); var last = builder.Add(sequencePoint, RCode.Move_result_object, r); return new RLRange(call, last, r); } if (type.IsGenericParameter) { var nop = builder.Add(sequencePoint, RCode.Nop); return new RLRange(nop, source); } XTypeDefinition typeDef ; if (type.TryResolve(out typeDef) && (typeDef.IsEnum)) { // Call appropriate valueOf method /*var boxedType = type.Module.TypeSystem.Object; var r = frame.AllocateTemp(boxedType.GetReference(target, nsConverter)); var call = builder.Add(sequencePoint, RCode.Invoke_static, typeDef.GetEnumUnderlyingType().GetBoxValueOfMethod(), source.Registers); var last = builder.Add(sequencePoint, RCode.Move_result_object, r); return new RLRange(call, last, r);*/ } // Just cast var checkCast = builder.Add(sequencePoint, RCode.Check_cast, type.GetReference(targetPackage), source); return new RLRange(checkCast, source); }
internal FieldDeclaration AddFieldForLocal(SimpleName localName, Expression initialValue, ISourceLocation sourceLocation) { FieldDeclaration field = new FieldDeclaration(null, FieldDeclaration.Flags.Static, TypeMemberVisibility.Private, TypeExpression.For(initialValue.Type), new NameDeclaration(localName.Name, localName.SourceLocation), null, sourceLocation); field.SetContainingTypeDeclaration(this, false); this.members.Add(field); this.localFieldFor.Add(localName.Name.UniqueKeyIgnoringCase, field.FieldDefinition); return field; }
internal Parser(Compilation compilation, ISourceLocation sourceLocation, List<IErrorMessage> scannerAndParserErrors) { this.compilation = compilation; this.nameTable = compilation.NameTable; this.scannerAndParserErrors = this.originalScannerAndParserErrors = scannerAndParserErrors; this.scanner = new Scanner(scannerAndParserErrors, sourceLocation, true); this.insideBlock = false; this.insideType = false; }
private NameDeclaration GetNameDeclarationFor(string name, ISourceLocation sourceLocation) //^ ensures result.Value == name; { IName iname = this.nameTable.GetNameFor(name); NameDeclaration result = new NameDeclaration(iname, sourceLocation); //^ assume result.Value == name; return result; }
/// <summary> /// Create and add an instruction. /// </summary> public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode, object operand, params Register[] registers) { if(operand is Register) throw new InvalidOperationException("Wrong overload. Please fix me..."); // see above. if(operand is RegisterSpec || operand is RLRange) throw new InvalidOperationException("Wrong kind of argument. Please fix me..."); // see above. return builder.Add(sequencePoint, opcode, operand, registers); }
/// <summary> /// Initializes a mapping. /// </summary> public static AttributeAnnotationMapping CreateMapping( ISourceLocation sequencePoint, AssemblyCompiler compiler, DexTargetPackage targetPackage, TypeDefinition attributeType, ClassDefinition attributeClass) { return new AttributeAnnotationMapping(attributeType, attributeClass); }
public Scanner(List<IErrorMessage>/*?*/ scannerErrors, ISourceLocation sourceLocation, bool ignoreComments) { this.scannerErrors = scannerErrors; this.sourceLocation = sourceLocation; char[] buffer = new char[16]; this.charsInBuffer = sourceLocation.CopyTo(0, buffer, 0, buffer.Length-1); this.buffer = buffer; this.endPos = this.startPos = 0; this.offset = 0; this.ignoreComments = ignoreComments; }
protected void Error_NameCollision(ISourceLocation site, NameCollisionException exception) { // Build type string StringBuilder sb = new StringBuilder(); sb.Append(AttributeHelpers.GetTypeName(exception.Types[0]).ToLower() + "s"); for (int i = 1; i < exception.Types.Length - 1; i++) sb.Append(", " + AttributeHelpers.GetTypeName(exception.Types[i]).ToLower() + "s"); if (exception.Types.Length > 1) sb.Append(" or " + AttributeHelpers.GetTypeName(exception.Types[exception.Types.Length - 1]).ToLower() + "s"); errorReporter.Error(site, "\"{1}\" can refer to multiple {0}. Remove unused usings or prefix the name with namespace qualifier.", sb.ToString(), exception.Name); }
private void HandleError(ISourceLocation errorLocation, Error error, params string[] messageParameters) // ^ modifies this.scannerAndParserErrors; //^ ensures this.currentToken == old(this.currentToken); { //^ Token oldToken = this.currentToken; if (this.originalScannerAndParserErrors == this.scannerAndParserErrors) { } this.scannerAndParserErrors.Add(new SpecSharpErrorMessage(errorLocation, (long)error, error.ToString(), messageParameters)); //^ assume this.currentToken == oldToken; }
/// <summary> /// Initializes a new instance of the error message /// </summary> /// <param name="resourceType"></param> /// <param name="sourceLocation"></param> /// <param name="errorCode"></param> /// <param name="messageKey"></param> /// <param name="relatedLocations"></param> /// <param name="messageArguments"></param> public CcsErrorMessage( Type resourceType, ISourceLocation sourceLocation, long errorCode, string messageKey, IEnumerable<ILocation> relatedLocations, string[] messageArguments) :base(sourceLocation, errorCode, messageKey, relatedLocations, messageArguments) { Contract.Requires(resourceType != null); this.resourceType = resourceType; }
/// <summary> /// Create the current type as class definition. /// </summary> internal DelegateInstanceTypeBuilder( ISourceLocation sequencePoint, AssemblyCompiler compiler, DexTargetPackage targetPackage, ClassDefinition delegateClass, XMethodDefinition invokeMethod, Prototype invokePrototype, XMethodDefinition calledMethod) { this.sequencePoint = sequencePoint; this.compiler = compiler; this.targetPackage = targetPackage; this.delegateClass = delegateClass; this.invokeMethod = invokeMethod; this.invokePrototype = invokePrototype; this.calledMethod = calledMethod; this.multicastDelegateClass = compiler.GetDot42InternalType("System", "MulticastDelegate").GetClassReference(targetPackage); }
/// <summary> /// Gets the instance type that calls the given method. /// Create if needed. /// </summary> public DelegateInstanceType GetOrCreateInstance(ISourceLocation sequencePoint, DexTargetPackage targetPackage, XMethodDefinition calledMethod) { DelegateInstanceType result; if (instances.TryGetValue(calledMethod, out result)) return result; // Ensure prototype exists if (invokePrototype == null) { invokePrototype = PrototypeBuilder.BuildPrototype(compiler, targetPackage, interfaceClass, invokeMethod); } // Not found, build it. var builder = new DelegateInstanceTypeBuilder(sequencePoint, compiler, targetPackage, InterfaceClass, invokeMethod, invokePrototype, calledMethod); result = builder.Create(); instances.Add(calledMethod, result); return result; }
/// <summary> /// Ensure the given value register is a temp register. /// If it is not, allocate a temp register an copy to it. /// </summary> public static RLRange EnsureTemp(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec value, IRegisterAllocator frame) { // Is temp? if (value.Register.Category == RCategory.Temp) return new RLRange(value); // No, allocate temp var tmp = frame.AllocateTemp(value.Type); Instruction ins; switch (value.Register.Type) { case RType.Object: ins = builder.Add(sequencePoint, RCode.Move_object, tmp.Register, value.Register); break; case RType.Wide: ins = builder.Add(sequencePoint, RCode.Move_wide, tmp.Register, value.Register); break; case RType.Value: ins = builder.Add(sequencePoint, RCode.Move, tmp.Register, value.Register); break; default: throw new ArgumentException("Unknown register type " + (int)value.Register.Type); } return new RLRange(ins, tmp); }
/// <summary> /// Create and add an instruction. /// </summary> public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode, object operand, params Register[] registers) { return builder.Add(sequencePoint, opcode, operand, registers); }
/// <summary> /// Create code to unbox the given source array of boxed type elements into an array of primitive elements. /// </summary> public static RLRange UnboxGenericArray(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, RegisterSpec boxedArray, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame, AssemblyCompiler compiler) { var internalBoxingType = compiler.GetDot42InternalType("Boxing").Resolve(); var ilUnboxMethod = internalBoxingType.Methods.First(x => x.EqualsName("UnboxTo") && (x.Parameters.Count == 2) && (x.Parameters[1].ParameterType.IsSame(type, true))); var unboxMethod = ilUnboxMethod.GetReference(targetPackage); var call = builder.Add(sequencePoint, RCode.Invoke_static, unboxMethod, boxedArray, source); return new RLRange(call, null); }
//^ [Pure] bool ISourceLocation.Contains(ISourceLocation location) { return(false); }
/// <summary> /// Create code to unbox the given source value into the given type. /// </summary> public static RLRange Unbox(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, XTypeReference type, AssemblyCompiler compiler, DexTargetPackage targetPackage, IRegisterAllocator frame) { if (type.IsPrimitive) { RCode convertAfterCode; var rUnboxed = frame.AllocateTemp(type.GetReference(targetPackage)); var unboxValueMethod = type.GetUnboxValueMethod(compiler, targetPackage, out convertAfterCode); var first = builder.Add(sequencePoint, RCode.Invoke_static, unboxValueMethod, source); var last = builder.Add(sequencePoint, type.MoveResult(), rUnboxed); if (convertAfterCode != RCode.Nop) { last = builder.Add(sequencePoint, convertAfterCode, rUnboxed, rUnboxed); } return new RLRange(first, last, rUnboxed); } XTypeDefinition enumTypeDef; if (type.IsEnum(out enumTypeDef)) { var rUnboxed = frame.AllocateTemp(type.GetReference(targetPackage)); var unboxValueMethod = enumTypeDef.Methods.First(x => x.Name == NameConstants.Enum.UnboxMethodName).GetReference(targetPackage); var first = builder.Add(sequencePoint, RCode.Invoke_static, unboxValueMethod, source); var last = builder.Add(sequencePoint, type.MoveResult(), rUnboxed); return new RLRange(first, last, rUnboxed); } if (!type.IsGenericParameter) { // Just cast var checkCast = builder.Add(sequencePoint, RCode.Check_cast, type.GetReference(targetPackage), source); return new RLRange(checkCast, source); } // Do nothing var nop = builder.Add(sequencePoint, RCode.Nop); return new RLRange(nop, source); }
internal VccNestedUnionDeclaration(NameDeclaration name, List <ITypeDeclarationMember> members, IEnumerable <Specifier> extendedAttributes, ISourceLocation sourceLocation) : base(name, members, extendedAttributes, sourceLocation) { }
public ISourceLocation GetCorrespondingSourceLocation(ISourceLocation sourceLocationInPreviousVersionOfDocument) { return(SourceDummy.SourceLocation); }
/// <summary> /// Default ctor /// </summary> public AstBasicBlock(ISourceLocation sourceLocation, IEnumerable <AstNode> body) : base(sourceLocation) { Body = (body != null) ? body.ToList() : new List <AstNode>(); }
/// <summary> /// Helper /// </summary> public static AstBlock Create <T>(ISourceLocation sourceLocation, params T[] nodes) where T : AstNode { return(new AstBlock(sourceLocation, nodes.Cast <AstNode>())); }
bool ISourceLocation.Contains(ISourceLocation location) { throw new System.NotImplementedException(); }
/// <summary> /// Create an expression that loads the given type at runtime. /// </summary> private static AstExpression LoadTypeForGenericInstance(ISourceLocation seqp, MethodSource currentMethod, XTypeReference type, XTypeDefinition typeHelperType, XTypeSystem typeSystem, bool boxPrimitiveTypes = true) { if (type.IsArray) { // Array type var arrayType = (XArrayType)type; // Load element type var prefix = LoadTypeForGenericInstance(seqp, currentMethod, ((XArrayType)type).ElementType, typeHelperType, typeSystem, boxPrimitiveTypes); // Convert to array type if (arrayType.Dimensions.Count() == 1) { var giCreateArray = typeHelperType.Methods.Single(x => (x.Name == "Array") && (x.Parameters.Count == 1)); return(new AstExpression(seqp, AstCode.Call, giCreateArray, prefix) { ExpectedType = typeSystem.Type }); } else { var giCreateArray = typeHelperType.Methods.Single(x => (x.Name == "Array") && (x.Parameters.Count == 2)); var dimensionsExpr = new AstExpression(seqp, AstCode.Ldc_I4, arrayType.Dimensions.Count()) { ExpectedType = typeSystem.Int }; return(new AstExpression(seqp, AstCode.Call, giCreateArray, prefix, dimensionsExpr) { ExpectedType = typeSystem.Type }); } } var gp = type as XGenericParameter; if (gp != null) { AstExpression gi; if (gp.Owner is XTypeReference) { // Class type parameter var owner = (XTypeReference)gp.Owner; if (owner.GetElementType().Resolve().HasDexImportAttribute()) { // Imported type return(new AstExpression(seqp, AstCode.TypeOf, typeSystem.Object) { ExpectedType = typeSystem.Type }); } if (currentMethod.IsClassCtor) { // Class ctor's cannot have type information. // Return Object instead DLog.Warning(DContext.CompilerCodeGenerator, "Class constructor of {0} tries to use generic parameter. This will always yield Object.", currentMethod.DeclaringTypeFullName); return(new AstExpression(seqp, AstCode.TypeOf, typeSystem.Object) { ExpectedType = typeSystem.Type }); } gi = currentMethod.IsStatic ? LoadStaticClassGenericInstance(seqp, typeSystem) : LoadInstanceClassGenericInstance(seqp, typeSystem); } else { // Method type parameter var owner = (XMethodReference)gp.Owner; if (owner.GetElementMethod().Resolve().DeclaringType.HasDexImportAttribute()) { // Imported type return(LoadTypeForGenericInstance(seqp, currentMethod, type.Module.TypeSystem.Object, typeHelperType, typeSystem, boxPrimitiveTypes)); } gi = LoadMethodGenericInstance(seqp, typeSystem); } var indexExpr = new AstExpression(seqp, AstCode.Ldc_I4, gp.Position) { ExpectedType = typeSystem.Int }; return(new AstExpression(seqp, AstCode.Ldelem_Ref, null, gi, indexExpr) { ExpectedType = typeSystem.Type }); } if (type is XTypeSpecification) { // Just use the element type var typeSpec = (XTypeSpecification)type; return(LoadTypeForGenericInstance(seqp, currentMethod, typeSpec.ElementType, typeHelperType, typeSystem, boxPrimitiveTypes)); } if (type.IsPrimitive && boxPrimitiveTypes) { return(new AstExpression(seqp, AstCode.BoxedTypeOf, type) { ExpectedType = typeSystem.Type }); } // Plain type reference or definition return(new AstExpression(seqp, AstCode.TypeOf, type) { ExpectedType = typeSystem.Type }); }
public bool Contains(ISourceLocation location) { throw new NotImplementedException(); }
public ISourceLocation GetCorrespondingSourceLocation(ISourceLocation sourceLocationInPreviousVersionOfDocument) { throw new NotImplementedException(); }
protected AbstractDependency([NotNull] TItem usingItem, [NotNull] TItem usedItem, ISourceLocation source) { UsingItem = usingItem; UsedItem = usedItem; Source = source; }
public static Token Error(ISourceLocation source) { return(new Token(string.Empty, TokenType.Error, LiteralTokenType.None, source)); }
ISourceLocation ISourceDocument.GetCorrespondingSourceLocation(ISourceLocation sourceLocationInPreviousVersionOfDocument) { return(SourceDummy.PrimarySourceLocation); }
internal VccDatatypeDeclaration(NameDeclaration name, List <ITypeDeclarationMember> members, IEnumerable <Specifier> extendedAttributes, IEnumerable <FunctionDeclaration> ctors, ISourceLocation sourceLocation) : base(name, members, extendedAttributes, sourceLocation) { this.Constructors = ctors; }
protected void Error_OperationSignatureMismatch(ISourceLocation site) { errorReporter.Error(site, "No operation with the specified name and parameter types can be found in the interface."); }
/// <summary> /// Default ctor /// </summary> public AstBasicBlock(ISourceLocation sourceLocation) : base(sourceLocation) { Body = new List <AstNode>(); }
internal static DomRegion ToDomRegion(this ISourceLocation location) { return(new DomRegion(location.Line, location.Column)); }
public AstBlock(ISourceLocation sourceLocation, params AstNode[] body) : this(sourceLocation, (IEnumerable <AstNode>)body) { }
private static NeuNumberLiteral NextNumberLiteral( this Tokenizer <NeuToken> tokenizer, ISourceLocation start, String source) { String?rawHint = null; /// if (tokenizer.GetTopNumericTypeHint() is NeuTypeIdentifier typeId) { switch (typeId) { case NeuSimpleTypeId simpleTypeId when simpleTypeId.GetIdentifer() is NeuIdentifier id: rawHint = id.Source; break; /// default: break; } } /// if (IsNullOrWhiteSpace(rawHint)) { rawHint = source.Contains('.') ? "Float" : "Int"; } /// switch (rawHint) { case "Int": int intValue = 0; if (!int.TryParse(source, out intValue)) { throw new Exception(); } /// var e = tokenizer.Scanner.GetLocation(); return(new NeuIntegerLiteral( source: source, start: start, end: e, value: intValue)); /// case "Float": float floatValue = 0; if (!float.TryParse(source, out floatValue)) { throw new Exception(); } /// return(new NeuFloatLiteral( source: source, start: start, end: tokenizer.Scanner.GetLocation(), value: floatValue)); /// default: throw new Exception(); } }
protected CompilerException(string message, ISourceLocation location) : base($"({location.StartLine},{location.StartColumn}):{message}") { Location = location; }
/// <summary> /// Is sequence point x equal to sequence point y? /// </summary> public static bool IsEqual(this ISourceLocation x, ISourceLocation y) { return(Instance.Compare(x, y) == 0); }
protected void Error_NameRedefinition(ISourceLocation site, NameCollisionException exception) { errorReporter.Error(site, "Redefinition of inherited {0} \"{1}\".", AttributeHelpers.GetTypeName(exception.Types[0]).ToLower(), exception.Name); }
protected void Error_OperationExceptionMismatch(ISourceLocation site) { errorReporter.Error(site, "Thrown exceptions of operation do not match with the ones defined in the interface."); }
/// <summary> /// Default ctor /// </summary> protected AstNode(ISourceLocation sourceLocation) { this.sourceLocation = sourceLocation; }
protected void Error_NamespaceImport(ISourceLocation site, Namespace @namespace) { errorReporter.Error(site, "Using namespace \"{0}\" is redundant.", @namespace.FullName); }
protected void Error_NameRedundant(ISourceLocation site, System.Type type, string name) { errorReporter.Error(site, "{0} \"{1}\" is already included.", AttributeHelpers.GetTypeName(type), name); }
public bool Contains(ISourceLocation location) { return(false); }
protected void Error_NamespaceUri(ISourceLocation site, Namespace @namespace) { errorReporter.Error(site, "URI for namespace \"{0}\" is redefined.", @namespace.FullName); }
bool ISourceLocation.Contains(ISourceLocation location) { return(this.primarySourceDocument.GetSourceLocation(this.StartIndex, this.Length).Contains(location)); }
protected void Error_OperationReturnMismatch(ISourceLocation site) { errorReporter.Error(site, "Return type of operation does not match with the one defined in the interface."); }
/// <summary> /// Default ctor /// </summary> public AstSwitch(ISourceLocation sourceLocation) : base(sourceLocation) { }
protected void Error_InterfaceMismatch(ISourceLocation site, System.Type ownerType) { errorReporter.Error(site, "Interface of endpoint and {0} does not match.", AttributeHelpers.GetTypeName(ownerType).ToLower()); }
public List <int> Values; // null for the default case /// <summary> /// Default ctor /// </summary> public CaseBlock(ISourceLocation sourceLocation) : this(sourceLocation, null) { }
protected void Error_NameExists(ISourceLocation site, NameCollisionException exception) { // Build type string StringBuilder sb = new StringBuilder(); sb.Append(AttributeHelpers.GetTypeName(exception.Types[0]).ToLower()); for (int i = 1; i < exception.Types.Length - 1; i++) sb.Append(", " + AttributeHelpers.GetTypeName(exception.Types[i]).ToLower()); if (exception.Types.Length > 1) sb.Append(" or " + AttributeHelpers.GetTypeName(exception.Types[exception.Types.Length - 1]).ToLower()); errorReporter.Error(site, "A {0} with name \"{1}\" already exists.", sb.ToString(), exception.Name); }
/// <summary> /// Create and add an instruction. /// </summary> public Instruction Add(ISourceLocation sequencePoint, RCode opcode, object operand, IEnumerable <Register> registers) { return(instructions.Add(sequencePoint, opcode, operand, registers)); }
/// <summary> /// Emit code (if needed) to convert a value from source type to destination type. /// This method is used in "store" opcodes such stloc, stfld, stsfld, call /// </summary> internal static RLRange ConvertTypeBeforeStore(this IRLBuilder builder, ISourceLocation sequencePoint, XTypeReference sourceType, XTypeReference destinationType, RegisterSpec source, DexTargetPackage targetPackage, IRegisterAllocator frame, AssemblyCompiler compiler, out bool converted) { converted = false; if (sourceType.IsSame(destinationType)) { // Unsigned conversions if (sourceType.IsByte()) { var tmp = builder.EnsureTemp(sequencePoint, source, frame); var ins = builder.Add(sequencePoint, RCode.Int_to_byte, tmp.Result, tmp.Result); converted = true; return new RLRange(tmp, ins, tmp.Result); } else if (sourceType.IsUInt16()) { var tmp = builder.EnsureTemp(sequencePoint, source, frame); var ins = builder.Add(sequencePoint, RCode.Int_to_short, tmp.Result, tmp.Result); converted = true; return new RLRange(tmp, ins, tmp.Result); } return new RLRange(source); } if (sourceType.IsArray) { var compilerHelper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName).Resolve(); var arrayType = targetPackage.DexFile.GetClass(targetPackage.NameConverter.GetConvertedFullName(compilerHelper)); var sourceArrayElementType = ((XArrayType)sourceType).ElementType; if (destinationType.ExtendsIList()) { // Use ArrayHelper.AsList to convert var convertMethodName = "AsList"; var convertMethod = arrayType.GetMethod(convertMethodName); // Add code var tmp = builder.EnsureTemp(sequencePoint, source, frame); builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register); var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register); converted = true; return new RLRange(tmp, last, tmp.Result); } if (destinationType.ExtendsICollection()) { // Use ArrayHelper.AsCollection to convert var convertMethodName = "AsCollection"; var convertMethod = arrayType.GetMethod(convertMethodName); // Add code var tmp = builder.EnsureTemp(sequencePoint, source, frame); builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register); var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register); converted = true; return new RLRange(tmp, last, tmp.Result); } if (destinationType.ExtendsIEnumerable()) { // Use ArrayHelper.As...Enumerable to convert var convertMethodName = "AsObjectEnumerable"; if (sourceArrayElementType.IsPrimitive) { if (sourceArrayElementType.IsBoolean()) convertMethodName = "AsBoolEnumerable"; else if (sourceArrayElementType.IsByte()) convertMethodName = "AsByteEnumerable"; else if (sourceArrayElementType.IsSByte()) convertMethodName = "AsSByteEnumerable"; else if (sourceArrayElementType.IsChar()) convertMethodName = "AsCharEnumerable"; else if (sourceArrayElementType.IsInt16()) convertMethodName = "AsInt16Enumerable"; else if (sourceArrayElementType.IsUInt16()) convertMethodName = "AsUInt16Enumerable"; else if (sourceArrayElementType.IsInt32()) convertMethodName = "AsInt32Enumerable"; else if (sourceArrayElementType.IsUInt32()) convertMethodName = "AsUInt32Enumerable"; else if (sourceArrayElementType.IsInt64()) convertMethodName = "AsInt64Enumerable"; else if (sourceArrayElementType.IsFloat()) convertMethodName = "AsFloatEnumerable"; else if (sourceArrayElementType.IsDouble()) convertMethodName = "AsDoubleEnumerable"; else throw new ArgumentOutOfRangeException("Unknown primitive array element type " + sourceArrayElementType); } var convertMethod = arrayType.GetMethod(convertMethodName); // Add code var tmp = builder.EnsureTemp(sequencePoint, source, frame); builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register); var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register); converted = true; return new RLRange(tmp, last, tmp.Result); } } // Do not convert return new RLRange(source); }
public VccNameDeclaration(IName name, bool isCompilerGenerated, ISourceLocation sourceLocation) : base(name, sourceLocation) { this.isCompilerGenerated = isCompilerGenerated; }
/// <summary> /// Create code to box the given source array of primitive type elements into an array of boxed elements. /// </summary> public static RLRange BoxGenericArray(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame, AssemblyCompiler compiler) { var objectArrayType = new DexLib.ArrayType(new ClassReference("java.lang.Object")); var boxedArray = frame.AllocateTemp(objectArrayType); var internalBoxingType = compiler.GetDot42InternalType("Boxing").Resolve(); var ilBoxMethod = internalBoxingType.Methods.First(x => x.EqualsName("Box") && (x.Parameters.Count == 1) && (x.Parameters[0].ParameterType.IsSame(type, true))); var boxMethod = ilBoxMethod.GetReference(targetPackage); var call = builder.Add(sequencePoint, RCode.Invoke_static, boxMethod, source); var saveArray = builder.Add(sequencePoint, RCode.Move_result_object, boxedArray); return new RLRange(call, saveArray, boxedArray); }
public VccNameDeclaration(IName name, ISourceLocation sourceLocation) : this(name, false, sourceLocation) { }
/// <summary> /// Create code to unbox the given source array of boxed type elements resulting from a call into an array of primitive elements. /// </summary> public static RLRange UnboxGenericArrayResult(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec boxedArray, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame, AssemblyCompiler compiler) { var internalBoxingType = compiler.GetDot42InternalType("Boxing").Resolve(); var primitiveArray = frame.AllocateTemp(type.GetReference(targetPackage)); var ilUnboxMethod = internalBoxingType.Methods.First(x => x.Name.StartsWith("Unbox") && (x.Parameters.Count == 1) && (x.ReturnType.IsSame(type, true))); var unboxMethod = ilUnboxMethod.GetReference(targetPackage); var call = builder.Add(sequencePoint, RCode.Invoke_static, unboxMethod, boxedArray); var saveArray = builder.Add(sequencePoint, RCode.Move_result_object, primitiveArray); return new RLRange(call, saveArray, primitiveArray); }
internal VccEnumDeclaration(NameDeclaration name, TypeExpression underlyingType, List <ITypeDeclarationMember> members, ISourceLocation sourceLocation) : base(null, Flags.None, name, underlyingType, members, sourceLocation) { }
protected VccNestedStructuredTypeDeclaration(NameDeclaration name, List <ITypeDeclarationMember> members, IEnumerable <Specifier> extendedAttributes, ISourceLocation sourceLocation) : base(null, Flags.None | (Flags)TypeMemberVisibility.Public, name, new List <GenericTypeParameterDeclaration>(0), new List <TypeExpression>(0), members, sourceLocation) { this.extendedAttributes = extendedAttributes; }
public static Token Include(string path, ISourceLocation location) { return(new Token(path, TokenType.Include, LiteralTokenType.None, location)); }