本文整理汇总了C#中Emitter.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# Emitter.FindType方法的具体用法?C# Emitter.FindType怎么用?C# Emitter.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Emitter
的用法示例。
在下文中一共展示了Emitter.FindType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override void Compile(Emitter.Emitter emitter)
{
var type = Expression.GetExpressionType(emitter);
if (type.IsAnyOf("int", "float", "complex"))
{
if(type == "complex")
{
// simple case: the complex is a constant
if(Expression is ComplexNode)
{
(Expression as ComplexNode).Imaginary *= -1;
Expression.Compile(emitter);
}
// complex case: complex is an expression result
else
{
Expression.Compile(emitter);
// tmp = ...
var tmpVar = emitter.CurrentMethod.Scope.Introduce("complex", emitter.FindType("complex").Type);
emitter.EmitSaveVariable(tmpVar);
// tmp.real
emitter.EmitLoadVariableAddress(tmpVar);
emitter.EmitCall(emitter.AssemblyImport(typeof(SN.Complex).GetMethod("get_Real")));
// tmp.imaginary * -1
emitter.EmitLoadVariableAddress(tmpVar);
emitter.EmitCall(emitter.AssemblyImport(typeof(SN.Complex).GetMethod("get_Imaginary")));
emitter.EmitLoadFloat(-1);
emitter.EmitMul();
// new complex
emitter.EmitNewObj(emitter.FindMethod("complex", ".ctor", "float", "float"));
}
}
else
{
// multiply by -1
Expression.Compile(emitter);
if (type == "int")
emitter.EmitLoadInt(-1);
else
emitter.EmitLoadFloat(-1);
emitter.EmitMul();
}
}
else
Error(String.Format(Resources.errInvertType, type));
}
示例2: Compile
public override void Compile(Emitter.Emitter emitter)
{
// check if constructor exists
TypeNode type = null;
try
{
type = emitter.FindType(Name);
}
catch
{
Error(String.Format(Resources.errTypeNotFound, Name));
}
// check if type is an enum?
if (type.Enum)
{
// the constructor in an enum is pseudo-private
// so that it can only be called from another method
// of the same enum type
if(emitter.CurrentMethod == null || emitter.CurrentMethod.Owner != type)
Error(String.Format(Resources.errConstructEnum, Name));
}
MethodNode method = null;
var signature = GetSignature(emitter);
try
{
method = emitter.FindMethod(Name, ".ctor", signature);
}
catch
{
Error(String.Format(Resources.errConstructorNotFound, Name, signature.Join(" ")));
}
// parameters
for (int idx = 0; idx < Parameters.Count; idx++)
{
Parameters[idx].Compile(emitter);
emitter.EmitUpcastBasicType(Parameters[idx].GetExpressionType(emitter), method.Parameters[idx].Type.Signature);
}
emitter.EmitNewObj(method);
}
示例3: Compile
public override void Compile(Emitter.Emitter emitter)
{
var currType = emitter.CurrentType;
var currMethod = emitter.CurrentMethod;
emitter.CurrentType = emitter.FindType(PlannerID);
// convert the IdentifierGet to IdentifierInvoke with two faux arguments
AppendActionParameters(emitter);
// extract closured variables
var detector = new Utils.ClosureDetector();
Closures = detector.Process(Action, emitter);
DeclareClosuredVariables(emitter);
// generate closured code for emitter
CompileBody(emitter);
emitter.CurrentType = currType;
emitter.CurrentMethod = currMethod;
CompileInitiation(emitter);
}
示例4: Compile
public override void Compile(Emitter.Emitter emitter)
{
var currType = emitter.CurrentType;
var currMethod = emitter.CurrentMethod;
emitter.CurrentType = emitter.FindType(EmitterID);
// extract closured variables
var detector = new Utils.ClosureDetector();
ActionClosures = detector.Process(Action, emitter);
if (Condition != null)
ConditionClosures = detector.Process(Condition, emitter);
MergeClosures();
DeclareClosuredVariables(emitter);
// generate closured code for emitter
CompileBody(emitter);
emitter.CurrentType = currType;
emitter.CurrentMethod = currMethod;
CompileInitiation(emitter);
}
示例5: DeclareClosuredVariables
/// <summary>
/// Create fields in the emitter type to save local variables intos
/// </summary>
private void DeclareClosuredVariables(Emitter.Emitter emitter)
{
var flowSimType = emitter.FindType(PlannerID);
foreach (var curr in Closures)
{
var fld = emitter.CreateField(flowSimType, "_" + curr.Key, new SignatureNode(curr.Value));
emitter.PrepareField(fld);
}
}
示例6: CompileInitiation
/// <summary>
/// Generate code to setup the currently defined emitter
/// </summary>
/// <param name="emitter"></param>
private void CompileInitiation(Emitter.Emitter emitter)
{
var flowSimType = emitter.FindType(PlannerID);
var tmpVar = emitter.CurrentMethod.Scope.Introduce(PlannerID, flowSimType.Type);
// tmp = new flowsimN()
emitter.EmitNewObj(emitter.FindMethod(PlannerID, ".ctor"));
emitter.EmitSaveVariable(tmpVar);
SaveClosuredVariables(emitter, tmpVar);
// call FlowSimulation.Start(planner)
emitter.EmitLoadVariable(tmpVar);
var method = emitter.AssemblyImport(typeof(FlowSimulation).GetMethod("Start", new[] { typeof(Planner) }));
emitter.EmitCall(method);
}
示例7: Resolve
/// <summary>
/// Resolve the identifier meaning
/// </summary>
public void Resolve(Emitter.Emitter emitter)
{
// already resolved?
if (Kind != IdentifierKind.Unresolved) return;
// atmark?
if (AtmarkPrefix)
{
if (emitter.CurrentType == null)
Error(Resources.errFieldOutsideType);
OwnerType = emitter.CurrentType.Name;
var field = emitter.FindField(emitter.CurrentType.Name, Name);
if (field != null)
Kind = field.Static ? IdentifierKind.StaticField : IdentifierKind.Field;
else
Error(String.Format(Resources.errFieldNotFound, Name, emitter.CurrentType.Name));
// additional check: dynamic field from static method
if (emitter.CurrentMethod.Static && !field.Static)
Error(String.Format(Resources.errDynamicFromStatic, field.Name));
}
// other prefix?
else if (TypePrefix != null || ExpressionPrefix != null)
{
OwnerType = (TypePrefix != null ? TypePrefix.Data : ExpressionPrefix.GetExpressionType(emitter));
if (OwnerType == "null")
Error(Resources.errNullAccessor);
if(OwnerType.EndsWith("[]") && Name == "size")
{
Kind = IdentifierKind.SizeProperty;
return;
}
// check class existence
emitter.FindType(OwnerType);
// field ?
try
{
emitter.FindField(OwnerType, Name);
Kind = (TypePrefix != null ? IdentifierKind.StaticField : IdentifierKind.Field);
return;
}
catch { }
// method ?!
MethodNode method = null;
try
{
method = emitter.FindMethod(OwnerType, Name);
}
catch
{
Error(String.Format(Resources.errTypeIdentifierUnresolved, OwnerType, Name));
}
if (ExpressionPrefix == null && !method.Static)
Error(String.Format(Resources.errNonStaticMethod, Name));
Kind = (TypePrefix != null ? IdentifierKind.StaticMethod : IdentifierKind.Method);
}
else
{
MethodNode method = null;
// local variable
if (emitter.CurrentMethod.Scope.Exists(Name))
{
Kind = IdentifierKind.Variable;
return;
}
// parameter
if(emitter.CurrentMethod.Parameters.Contains(Name))
{
Kind = IdentifierKind.Parameter;
return;
}
// search for a method
try
{
method = emitter.FindMethod(emitter.CurrentType != null ? emitter.CurrentType.Name : "", true, Name);
}
catch
{
Error(String.Format(Resources.errIdentifierUnresolved, Name));
}
OwnerType = method.Owner.Name;
if(method.Static)
//.........这里部分代码省略.........
示例8: Compile
public override void Compile(Emitter.Emitter emitter)
{
var fromType = Expression.GetExpressionType(emitter);
var toType = ToType;
var simpleTypes = new[] { "bool", "int", "float", "long", "complex" };
if (emitter.ResolveType(toType) == null)
Error(String.Format(Resources.errTypeNotFound, toType));
// compile the expression itself
Expression.Compile(emitter);
// idiotic case?
if (fromType == toType) return;
if(fromType == "null")
{
if(toType.IsAnyOf(simpleTypes))
Error(String.Format(Resources.errInvalidNullCast, toType));
// no actual casting is required
}
// cast simple types
else if(fromType.IsAnyOf(simpleTypes))
{
if (toType.IsAnyOf(simpleTypes))
{
switch(toType)
{
case "bool": emitter.EmitConvertToBool(); break;
case "int": emitter.EmitConvertToInt(); break;
case "float": emitter.EmitConvertToFloat(); break;
default: throw new NotImplementedException();
}
}
else
Error(String.Format(Resources.errInvalidCast, fromType, toType));
}
else
{
// complex type to simple type: search for a conversion method
if(toType.IsAnyOf(simpleTypes))
{
// to_b, to_f, to_i
string methodName = "to_" + toType[0];
MethodNode converter = null;
try
{
converter = emitter.FindMethod(fromType, methodName);
}
catch
{
Error(String.Format(Resources.errInvalidCast, fromType, toType));
}
// call the method
emitter.EmitCall(converter);
}
else
{
if (fromType.Contains("[]") || toType.Contains("[]"))
Error(Resources.errCastArray);
if(!emitter.TypeCastable(fromType, toType))
Error(String.Format(Resources.errInvalidCast, fromType, toType));
var type = emitter.FindType(toType);
emitter.EmitCast(type.Type);
}
}
}
示例9: Resolve
private void Resolve(Emitter.Emitter emitter)
{
// already resolved?
if (Kind != IdentifierKind.Unresolved) return;
// atmark?
if (AtmarkPrefix)
{
OwnerType = emitter.CurrentType.Name;
var field = emitter.FindField(emitter.CurrentType.Name, Name);
if (field != null)
Kind = field.Static ? IdentifierKind.StaticField : IdentifierKind.Field;
else
Error(String.Format(Resources.errFieldNotFound, Name, emitter.CurrentType.Name));
// additional check: dynamic field from static method
if (emitter.CurrentMethod.Static && !field.Static)
Error(String.Format(Resources.errDynamicFromStatic, field.Name));
IdentifierType = field.Type.Signature;
}
// other prefix?
else if (TypePrefix != null || ExpressionPrefix != null)
{
OwnerType = (TypePrefix != null ? TypePrefix.Data : ExpressionPrefix.GetExpressionType(emitter));
// check class existence
var type = emitter.FindType(OwnerType);
if (type == null)
Error(String.Format(Resources.errTypeNotFound, OwnerType), TypePrefix);
// field ?
var field = emitter.FindField(OwnerType, Name);
Kind = (TypePrefix != null ? IdentifierKind.StaticField : IdentifierKind.Field);
IdentifierType = field.Type.Signature;
}
else
{
// local variable
if (emitter.CurrentMethod.Scope.Exists(Name))
{
Kind = IdentifierKind.Variable;
IdentifierType = emitter.CurrentMethod.Scope.Find(Name).Type;
}
// parameter
else if (emitter.CurrentMethod.Parameters.Contains(Name))
{
Kind = IdentifierKind.Parameter;
IdentifierType = emitter.CurrentMethod.Parameters[Name].Type.Signature;
}
// no luck at all
else
Error(String.Format(Resources.errIdentifierUnresolved, Name));
}
}
示例10: CompileInitiation
/// <summary>
/// Generate code to setup the currently defined emitter
/// </summary>
/// <param name="emitter"></param>
private void CompileInitiation(Emitter.Emitter emitter)
{
var emitterType = emitter.FindType(EmitterID);
var tmpVar = emitter.CurrentMethod.Scope.Introduce(EmitterID, emitterType.Type);
// tmp = new emitterN()
emitter.EmitNewObj(emitter.FindMethod(EmitterID, ".ctor"));
emitter.EmitSaveVariable(tmpVar);
// step
if (Step != null)
{
// validate step
var stepType = Step.GetExpressionType(emitter);
if (!stepType.IsAnyOf("int", "float"))
Error(Resources.errEmitStepExpected);
// tmp.Step = step
emitter.EmitLoadVariable(tmpVar);
Step.Compile(emitter);
if (stepType == "int")
emitter.EmitConvertToFloat();
emitter.EmitSaveField(emitter.FindField(EmitterID, "step"));
}
// distribution
if (Distribution != null)
{
// validate distr
if (Distribution.GetExpressionType(emitter) != "distr")
Error(Resources.errEmitDistributionExpected);
// tmp.Distr = distr
emitter.EmitLoadVariable(tmpVar);
Distribution.Compile(emitter);
emitter.EmitSaveField(emitter.FindField(EmitterID, "distr"));
}
// limit
if (Limit != null)
{
// validate distr
if (Limit.GetExpressionType(emitter) != "int")
Error(Resources.errEmitLimitExpected);
// tmp.Distr = distr
emitter.EmitLoadVariable(tmpVar);
Limit.Compile(emitter);
emitter.EmitSaveField(emitter.FindField(EmitterID, "limit"));
}
SaveClosuredVariables(emitter, tmpVar);
// register emitter in the system
emitter.EmitLoadVariable(tmpVar);
var registerMethod = emitter.AssemblyImport(typeof(Simulation).GetMethod("RegisterEmitter", new[] { typeof(EventEmitter) }));
emitter.EmitCall(registerMethod);
}
示例11: Resolve
public void Resolve(Emitter.Emitter emitter)
{
// build signature
var signature = GetSignature(emitter);
MethodNode method;
// type prefix ?
if(TypePrefix != null)
{
OwnerType = TypePrefix.Data;
Static = true;
// check class existence
emitter.FindType(OwnerType);
method = emitter.FindMethod(TypePrefix.Data, Name, signature);
if (!method.Static)
Error(String.Format(Resources.errNonStaticMethod, Name));
}
// expression prefix ?
else if(ExpressionPrefix != null)
{
OwnerType = ExpressionPrefix.GetExpressionType(emitter);
if (OwnerType == "null")
Error(Resources.errNullAccessor);
emitter.FindMethod(OwnerType, Name, signature);
}
// local or visible method ?
else
{
// try to find method in local type, if there's one
var tmpOwner = emitter.CurrentType != null ? emitter.CurrentType.Name : "";
method = emitter.FindMethod(tmpOwner, true, Name, signature);
OwnerType = method.Owner.Name;
Static = method.Static;
}
}