本文整理汇总了C#中ISourceLocation类的典型用法代码示例。如果您正苦于以下问题:C# ISourceLocation类的具体用法?C# ISourceLocation怎么用?C# ISourceLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISourceLocation类属于命名空间,在下文中一共展示了ISourceLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Box
/// <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);
}
示例2: Add
/// <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);
}
示例3: TranslationMessage
public TranslationMessage(ISourceLocation loc, int code, string msg, bool isWarning)
{
this.loc = loc;
this.code = code;
this.msg = msg;
this.isWarning = isWarning;
}
示例4: AddFieldForLocal
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;
}
示例5: GetNameDeclarationFor
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;
}
示例6: Parser
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;
}
示例7: CreateMapping
/// <summary>
/// Initializes a mapping.
/// </summary>
public static AttributeAnnotationMapping CreateMapping(
ISourceLocation sequencePoint,
AssemblyCompiler compiler,
DexTargetPackage targetPackage,
TypeDefinition attributeType,
ClassDefinition attributeClass)
{
return new AttributeAnnotationMapping(attributeType, attributeClass);
}
示例8: Scanner
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;
}
示例9: Error_NameCollision
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);
}
示例10: HandleError
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;
}
示例11: CcsErrorMessage
/// <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;
}
示例12: DelegateInstanceTypeBuilder
/// <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);
}
示例13: GetOrCreateInstance
/// <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;
}
示例14: EnsureTemp
/// <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);
}
示例15: ConvertTypeBeforeStore
/// <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);
}