本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.EmitSymbolToken方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitSymbolToken方法的具体用法?C# CodeGenerator.EmitSymbolToken怎么用?C# CodeGenerator.EmitSymbolToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitSymbolToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
internal override TypeSymbol Emit(CodeGenerator cg)
{
Debug.Assert(Access.IsRead || Access.IsNone);
var type = cg.Emit(Operand);
//
if (Access.IsNone)
{
cg.EmitPop(type);
return cg.CoreTypes.Void;
}
// dereference
if (type == cg.CoreTypes.PhpAlias)
{
// <alias>.Value.AsObject()
cg.Emit_PhpAlias_GetValueRef();
type = cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.AsObject);
}
// PhpValue -> object
if (type == cg.CoreTypes.PhpValue)
{
// Template: Operators.AsObject(value) is T
type = cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.AsObject_PhpValue);
}
//
if (AsType.ResolvedType != null)
{
if (type.IsReferenceType && type != cg.CoreTypes.PhpArray && type != cg.CoreTypes.PhpString)
{
// Template: value is T : object
cg.Builder.EmitOpCode(ILOpCode.Isinst);
cg.EmitSymbolToken(AsType.ResolvedType, null);
// object != null
cg.Builder.EmitNullConstant(); // .ldnull
cg.Builder.EmitOpCode(ILOpCode.Cgt_un); // .cgt.un
}
else
{
cg.EmitPop(type); // Operand is never an object instance
// FALSE
cg.Builder.EmitBoolConstant(false);
}
//
return cg.CoreTypes.Boolean;
}
else
{
AsType.EmitLoadTypeInfo(cg, false);
// Template: Operators.IsInstanceOf(value, type);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.IsInstanceOf_Object_PhpTypeInfo);
}
throw new NotImplementedException();
}
示例2: EmitLoad
//.........这里部分代码省略.........
}
throw new NotImplementedException();
}
// Ensure Alias (&...->Field)
else if (Access.IsReadRef)
{
if (type == cg.CoreTypes.PhpAlias)
{
// TODO: <place>.AddRef()
EmitOpCode_Load(cg);
return type;
}
else if (type == cg.CoreTypes.PhpValue)
{
// return <place>.EnsureAlias()
EmitOpCode_LoadAddress(cg); // &PhpValue
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.EnsureAlias)
.Expect(cg.CoreTypes.PhpAlias);
}
else
{
Debug.Assert(false, "value cannot be aliased");
// new PhpAlias((PhpValue)<place>, 1)
EmitOpCode_Load(cg);
cg.EmitConvertToPhpValue(type, 0);
return cg.Emit_PhpValue_MakeAlias();
}
}
// Read (...->Field) & Dereference eventually
else
{
if (type == cg.CoreTypes.PhpAlias)
{
EmitOpCode_Load(cg);
if (Access.TargetType != null)
{
// convert PhpValue to target type without loading whole value and storing to temporary variable
switch (Access.TargetType.SpecialType)
{
default:
if (Access.TargetType == cg.CoreTypes.PhpArray)
{
// <PhpAlias>.Value.ToArray()
cg.Builder.EmitOpCode(ILOpCode.Ldflda);
cg.EmitSymbolToken(cg.CoreMethods.PhpAlias.Value, null);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.ToArray);
}
break;
}
}
return cg.Emit_PhpAlias_GetValue();
}
else if (type == cg.CoreTypes.PhpValue)
{
if (Access.TargetType != null)
{
// convert PhpValue to target type without loading whole value and storing to temporary variable
switch (Access.TargetType.SpecialType)
{
case SpecialType.System_Double:
EmitOpCode_LoadAddress(cg); // &PhpValue.ToDouble()
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.ToDouble);
case SpecialType.System_Int64:
EmitOpCode_LoadAddress(cg); // &PhpValue.ToLong()
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.ToLong);
case SpecialType.System_Boolean:
EmitOpCode_LoadAddress(cg); // &PhpValue.ToBoolean()
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.ToBoolean);
case SpecialType.System_String:
EmitOpCode_LoadAddress(cg); // &PhpValue.ToString(ctx)
cg.EmitLoadContext();
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.ToString_Context);
case SpecialType.System_Object:
EmitOpCode_LoadAddress(cg); // &PhpValue.ToClass()
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.ToClass);
default:
if (Access.TargetType == cg.CoreTypes.PhpArray)
{
EmitOpCode_LoadAddress(cg); // &PhpValue.ToArray()
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.ToArray);
}
break;
}
}
// TODO: dereference if applicable (=> PhpValue.Alias.Value)
EmitOpCode_Load(cg);
return type;
}
else
{
EmitOpCode_Load(cg);
return type;
}
}
}
示例3: EmitOpCode
/// <summary>
/// Emits ldfld, stfld, ldflda, ldsfld, stsfld.
/// </summary>
/// <param name="cg"></param>
/// <param name="code">ld* or st* OP code.</param>
void EmitOpCode(CodeGenerator cg, ILOpCode code)
{
Debug.Assert(Field != null);
cg.Builder.EmitOpCode(code);
cg.EmitSymbolToken(Field, null);
}