本文整理汇总了C#中DexTargetPackage.Record方法的典型用法代码示例。如果您正苦于以下问题:C# DexTargetPackage.Record方法的具体用法?C# DexTargetPackage.Record怎么用?C# DexTargetPackage.Record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DexTargetPackage
的用法示例。
在下文中一共展示了DexTargetPackage.Record方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMembers
/// <summary>
/// Implement the class now that all classes have been created
/// </summary>
protected override void CreateMembers(DexTargetPackage targetPackage)
{
// Build ctors
foreach (var baseCtor in GetBaseClassCtors())
{
// Build ctor
var prototype = PrototypeBuilder.BuildPrototype(Compiler, targetPackage, null, baseCtor);
var ctor = new MethodDefinition(Class, "<init>", prototype);
ctor.AccessFlags = AccessFlags.Public | AccessFlags.Constructor;
Class.Methods.Add(ctor);
// Create ctor body
var ctorBody = CreateCtorBody(prototype);
targetPackage.Record(new CompiledMethod { DexMethod = ctor, RLBody = ctorBody });
}
}
示例2: Create
/// <summary>
/// Create the current type as class definition.
/// </summary>
public void Create(ClassDefinition declaringClass, DexTargetPackage targetPackage)
{
// Find xMethod
xMethod = XBuilder.AsMethodDefinition(compiler.Module, method);
// Create method definition
dmethod = new DexLib.MethodDefinition();
dmethod.Name = GetMethodName(method, targetPackage);
dmethod.MapFileId = compiler.GetNextMapFileId();
AddMethodToDeclaringClass(declaringClass, dmethod, targetPackage);
targetPackage.Record(xMethod, dmethod);
// Set access flags
SetAccessFlags(dmethod, method);
// Create prototype
dmethod.Prototype = PrototypeBuilder.BuildPrototype(compiler, targetPackage, declaringClass, xMethod);
}
示例3: TranslateToRL
/// <summary>
/// Create a method body for the given method.
/// </summary>
internal static MethodBody TranslateToRL(AssemblyCompiler compiler, DexTargetPackage targetPackage, MethodSource source, MethodDefinition dmethod, bool generateSetNextInstructionCode, out CompiledMethod compiledMethod)
{
try
{
#if DEBUG
//Debugger.Launch();
if ((source.Method != null) && (source.Method.Name == "test6"))
{
//Debugger.Launch();
}
#endif
// Create Ast
var optimizedAst = CreateOptimizedAst(compiler, source, generateSetNextInstructionCode);
// Generate RL code
var rlBody = new MethodBody(source);
var rlGenerator = new AstCompilerVisitor(compiler, source, targetPackage, dmethod, rlBody);
optimizedAst.Accept(rlGenerator, null);
rlGenerator.Complete();
// Should we add return_void?
if (source.ReturnsVoid)
{
var instructions = rlBody.Instructions;
if ((instructions.Count == 0) || (instructions.Last().Code != RCode.Return_void && instructions.Last().Code != RCode.Throw))
{
instructions.Add(new RL.Instruction(RCode.Return_void) { SequencePoint = source.GetLastSourceLine() });
}
}
// Record results
compiledMethod = targetPackage.Record(source, rlBody, rlGenerator.Frame);
return rlBody;
}
catch (Exception ex)
{
// Forward exception with more information
var msg = string.Format("Error while compiling {0} in {1}: {2}", source.FullName, source.DeclaringTypeFullName, ex.Message);
throw new CompilerException(msg, ex);
}
}
示例4: CreateBuildMethod
/// <summary>
/// Create a method definition for the builder method that builds a custom attribute from an annotation.
/// </summary>
private static MethodDefinition CreateBuildMethod(
ISourceLocation seqp,
Mono.Cecil.MethodDefinition ctor,
List<Tuple<MethodDefinition, Mono.Cecil.TypeReference>> paramGetMethods,
AssemblyCompiler compiler,
DexTargetPackage targetPackage,
ClassDefinition attributeClass,
AttributeAnnotationInterface mapping)
{
// Create method definition
string name = CreateBuildMethodName(attributeClass);
TypeReference attributeTypeRef = ctor.DeclaringType.GetReference(targetPackage, compiler.Module);
MethodDefinition method = new MethodDefinition(attributeClass, name, new Prototype(attributeTypeRef, new Parameter(mapping.AnnotationInterfaceClass, "ann")));
method.AccessFlags = AccessFlags.Public | AccessFlags.Static | AccessFlags.Synthetic;
attributeClass.Methods.Add(method);
// Create method body
MethodBody body = new MethodBody(null);
Register annotationReg = body.AllocateRegister(RCategory.Argument, RType.Object);
//body.Instructions.Add(seqp, RCode.Check_cast, mapping.AnnotationInterfaceClass, annotationReg);
// Allocate attribute
Register attributeReg = body.AllocateRegister(RCategory.Temp, RType.Object);
body.Instructions.Add(seqp, RCode.New_instance, attributeClass, attributeReg);
// Get ctor arguments
List<Register> ctorArgRegs = new List<Register>();
foreach (var p in paramGetMethods)
{
Instruction branchIfNotSet; // this can not happen, but lets keep the code below simple.
XModel.XTypeReference xType = XBuilder.AsTypeReference(compiler.Module, p.Item2);
Register[] valueRegs = CreateLoadValueSequence(seqp, body, xType, annotationReg, p.Item1, compiler, targetPackage, out branchIfNotSet);
branchIfNotSet.Operand = body.Instructions.Add(seqp, RCode.Nop);
ctorArgRegs.AddRange(valueRegs);
}
// Invoke ctor
DexLib.MethodReference dctor = ctor.GetReference(targetPackage, compiler.Module);
body.Instructions.Add(seqp, RCode.Invoke_direct, dctor, new[] { attributeReg }.Concat(ctorArgRegs).ToArray());
// Get field values
foreach (var fieldMap in mapping.FieldToGetMethodMap)
{
var field = fieldMap.Key;
XModel.XTypeReference xFieldType = XBuilder.AsTypeReference(compiler.Module, field.FieldType);
MethodDefinition getter = fieldMap.Value;
Instruction branchIfNotSet;
Register[] valueRegs = CreateLoadValueSequence(seqp, body, xFieldType, annotationReg, getter, compiler, targetPackage, out branchIfNotSet);
var put = body.Instructions.Add(seqp, xFieldType.IPut(), valueRegs[0], attributeReg);
mapping.FixOperands.Add(Tuple.Create(put, (MemberReference)field));
branchIfNotSet.Operand = body.Instructions.Add(seqp, RCode.Nop);
}
// Get property values
foreach (var propertyMap in mapping.PropertyToGetMethodMap)
{
PropertyDefinition property = propertyMap.Key;
XTypeReference xType = XBuilder.AsTypeReference(compiler.Module, property.PropertyType);
MethodDefinition getter = propertyMap.Value;
Instruction branchIfNotSet;
Register[] valueRegs = CreateLoadValueSequence(seqp, body, xType, annotationReg, getter, compiler, targetPackage, out branchIfNotSet);
XModel.XMethodDefinition xSetMethod = XBuilder.AsMethodDefinition(compiler.Module, property.SetMethod);
var set = body.Instructions.Add(seqp, xSetMethod.Invoke(xSetMethod, null), null, new[] { attributeReg }.Concat(valueRegs).ToArray());
mapping.FixOperands.Add(Tuple.Create(set, (MemberReference)property.SetMethod));
branchIfNotSet.Operand = body.Instructions.Add(seqp, RCode.Nop);
}
// Return attribute
body.Instructions.Add(seqp, RCode.Return_object, attributeReg);
// Register method body
targetPackage.Record(new CompiledMethod() { DexMethod = method, RLBody = body });
// Return method
return method;
}
示例5: Create
/// <summary>
/// Create the current type as class definition.
/// </summary>
internal static DelegateInstanceType Create(
ISourceLocation sequencePoint,
AssemblyCompiler compiler,
DexTargetPackage targetPackage,
ClassDefinition delegateClass,
XMethodDefinition invokeMethod,
Prototype invokePrototype,
XMethodDefinition equalsMethod,
Prototype equalsPrototype,
XMethodDefinition calledMethod)
{
// Prepare called method
var target = targetPackage.DexFile;
var owner = target.GetClass(calledMethod.DeclaringType.GetClassReference(targetPackage).Fullname) ??
targetPackage.GetOrCreateGeneratedCodeClass();
var calledMethodPrototype = PrototypeBuilder.BuildPrototype(compiler, targetPackage, owner, calledMethod);
var calledMethodRef = calledMethod.GetReference(targetPackage);
if (calledMethod.DeclaringType.HasDexImportAttribute())
{
// Delegate method is a Dex import method
}
else
{
// Delegate method is a .NET method
var calledDexMethod = owner.Methods.Single(x => (x.Name == calledMethodRef.Name) && (x.Prototype.Equals(calledMethodRef.Prototype)));
if (calledDexMethod.IsPrivate)
{
calledDexMethod.IsPrivate = false;
calledDexMethod.IsProtected = true;
}
}
var @class = new ClassDefinition();
@class.Name = CreateInstanceTypeName(owner);
@class.Namespace = owner.Namespace;
@class.AccessFlags = AccessFlags.Public | AccessFlags.Final;
owner.InnerClasses.Add(@class);
// Set super class
@class.SuperClass = delegateClass;
// Implement delegate interface
//@class.Interfaces.Add(delegateInterface);
// Get type of instance
XTypeDefinition instanceType = calledMethod.DeclaringType;
TypeReference instanceTypeRef = instanceType.GetReference(targetPackage);
// Add instance field
FieldDefinition instanceField = null;
if (!calledMethod.IsStatic)
{
instanceField = new FieldDefinition();
instanceField.Name = "instance";
instanceField.Owner = @class;
instanceField.Type = instanceTypeRef;
instanceField.AccessFlags = AccessFlags.Private | AccessFlags.Final;
@class.Fields.Add(instanceField);
}
// Add ctor
var ctor = new Dot42.DexLib.MethodDefinition();
ctor.Owner = @class;
ctor.Name = "<init>";
ctor.AccessFlags = AccessFlags.Public | AccessFlags.Constructor;
ctor.Prototype = new Prototype(PrimitiveType.Void);
if (!calledMethod.IsStatic)
{
ctor.Prototype.Parameters.Add(new Parameter(instanceTypeRef, "this"));
}
@class.Methods.Add(ctor);
// Create ctor body
var ctorBody = CreateCtorBody(calledMethod, instanceField, delegateClass);
targetPackage.Record(new CompiledMethod() { DexMethod = ctor, RLBody = ctorBody });
// Add Invoke method
var invoke = new Dot42.DexLib.MethodDefinition(@class, "Invoke", invokePrototype) { AccessFlags = AccessFlags.Public };
@class.Methods.Add(invoke);
// Create body
var invokeBody = CreateInvokeBody(sequencePoint, compiler, targetPackage, calledMethod, invokeMethod, invokePrototype, calledMethodPrototype, instanceField, delegateClass);
targetPackage.Record(new CompiledMethod() { DexMethod = invoke, RLBody = invokeBody });
// Add Equals method
if (null != equalsMethod)
{
var equals = new Dot42.DexLib.MethodDefinition(@class, "equals", equalsPrototype) { AccessFlags = AccessFlags.Public };
@class.Methods.Add(equals);
// Create body
if (!calledMethod.IsStatic)
{
var equalsBody = CreateEqualsBody(sequencePoint, compiler, targetPackage, equalsMethod, equalsPrototype, instanceField, @class);
targetPackage.Record(new CompiledMethod() { DexMethod = equals, RLBody = equalsBody });
}
else
{
var equalsBody = CreateEqualsBody();
//.........这里部分代码省略.........
示例6: CreateFactoryMethod
private static MethodDefinition CreateFactoryMethod(AssemblyCompiler compiler, DexTargetPackage targetPackage, CustomAttribute attribute, AttributeAnnotationMapping mapping)
{
var targetClass = mapping.AttributeClass; // is this really the right place for the factory methods?
ISourceLocation seqp = null;
var attributeTypeDef = attribute.AttributeType.Resolve();
// create method
string methodName = CreateAttributeFactoryMethodName(targetClass);
MethodDefinition method = new MethodDefinition(targetClass, methodName, new Prototype(mapping.AttributeClass));
method.AccessFlags = AccessFlags.Public | AccessFlags.Static | AccessFlags.Synthetic;
targetClass.Methods.Add(method);
// create method body
MethodBody body = new MethodBody(null);
// Allocate attribute
Register attributeReg = body.AllocateRegister(RCategory.Temp, RType.Object);
body.Instructions.Add(seqp, RCode.New_instance, mapping.AttributeClass, attributeReg);
// collect ctor arguments
List<Register> ctorArgRegs = new List<Register>() { attributeReg };
foreach (var p in attribute.ConstructorArguments)
{
XTypeReference xType = XBuilder.AsTypeReference(compiler.Module, p.Type);
Register[] valueRegs = CreateInitializeValueInstructions(seqp, body, xType, p, compiler, targetPackage);
ctorArgRegs.AddRange(valueRegs);
}
// Invoke ctor
DexLib.MethodReference dctor = attribute.Constructor.GetReference(targetPackage, compiler.Module);
body.Instructions.Add(seqp, RCode.Invoke_direct, dctor, ctorArgRegs.ToArray());
// set field values
foreach (var p in attribute.Fields)
{
var field = GetField(attributeTypeDef, p.Name);
var xField = XBuilder.AsFieldReference(compiler.Module, field);
Register[] valueRegs = CreateInitializeValueInstructions(seqp, body, xField.FieldType, p.Argument, compiler, targetPackage);
body.Instructions.Add(seqp, xField.FieldType.IPut(), xField.GetReference(targetPackage),
valueRegs[0], attributeReg);
}
// set property values
foreach (var p in attribute.Properties)
{
PropertyDefinition property = GetSettableProperty(attributeTypeDef, p.Name);
XTypeReference xType = XBuilder.AsTypeReference(compiler.Module, property.PropertyType);
Register[] valueRegs = CreateInitializeValueInstructions(seqp, body, xType, p.Argument, compiler, targetPackage);
XMethodDefinition xSetMethod = XBuilder.AsMethodDefinition(compiler.Module, property.SetMethod);
body.Instructions.Add(seqp, xSetMethod.Invoke(xSetMethod, null),
xSetMethod.GetReference(targetPackage),
new[] { attributeReg }.Concat(valueRegs).ToArray());
}
// Return attribute
body.Instructions.Add(seqp, RCode.Return_object, attributeReg);
// Register method body
targetPackage.Record(new CompiledMethod() { DexMethod = method, RLBody = body });
// Return method
return method;
}
示例7: CreateMembers
/// <summary>
/// Implement the class now that all classes have been created
/// </summary>
protected override void CreateMembers(DexTargetPackage targetPackage)
{
// Build ctors
foreach (var baseCtor in GetBaseClassCtors())
{
// TODO: does this make sense? after all, we derive from object.
// probalby one should just remove this code, and generate a
// defaul constructor.
var prototype = PrototypeBuilder.BuildPrototype(Compiler, targetPackage, null, baseCtor);
var ctor = new MethodDefinition(Class, "<init>", prototype);
ctor.AccessFlags = AccessFlags.Public | AccessFlags.Constructor;
Class.Methods.Add(ctor);
// Create ctor body
var ctorBody = CreateCtorBody(prototype);
targetPackage.Record(new CompiledMethod { DexMethod = ctor, RLBody = ctorBody });
}
// build original type field
// Create field definition
// NOTE: at the moment the underlying type is both defined as a type and in the annotation.
// remove one or the other when we have determined which is the better way.
var dfield = new Dot42.DexLib.FieldDefinition();
dfield.Owner = Class;
dfield.Name = "underlying$";
dfield.IsSynthetic = true;
dfield.IsFinal = true;
dfield.IsStatic= true;
dfield.IsPublic = true;
dfield.Type = Compiler.Module.TypeSystem.Type.GetClassReference(targetPackage);
dfield.Value = _underlyingBuilder.Class;
Class.Fields.Add(dfield);
}
示例8: CreateMembers
/// <summary>
/// Implement the class now that all classes have been created
/// </summary>
protected override void CreateMembers(DexTargetPackage targetPackage)
{
// Build ctors
foreach (var baseCtor in GetBaseClassCtors())
{
// Build ctor
var prototype = PrototypeBuilder.BuildPrototype(Compiler, targetPackage, null, baseCtor);
var ctor = new MethodDefinition(Class, "<init>", prototype);
ctor.AccessFlags = AccessFlags.Public | AccessFlags.Constructor;
Class.Methods.Add(ctor);
// Create ctor body
var ctorBody = CreateCtorBody(prototype);
targetPackage.Record(new CompiledMethod { DexMethod = ctor, RLBody = ctorBody });
}
// build original type field
// Create field definition
var dfield = new Dot42.DexLib.FieldDefinition();
dfield.Owner = Class;
dfield.Name = "underlying$";
dfield.IsSynthetic = true;
dfield.IsFinal = true;
dfield.IsStatic= true;
dfield.IsPublic = true;
dfield.Type = Compiler.Module.TypeSystem.Type.GetClassReference(targetPackage);
// not sure if GetClassReference is the best way to go forward here.
// might depend on the sort order of the class builders.
var underlyingType = XBuilder.AsTypeReference(Compiler.Module, Type);
dfield.Value = underlyingType.GetClassReference(targetPackage);
Class.Fields.Add(dfield);
}