本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.EmitConvert方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitConvert方法的具体用法?C# CodeGenerator.EmitConvert怎么用?C# CodeGenerator.EmitConvert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitConvert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
internal override void Generate(CodeGenerator cg)
{
Contract.ThrowIfNull(Condition);
if (IsLoop) // perf
{
cg.Builder.EmitBranch(ILOpCode.Br, this.Condition);
// {
cg.GenerateScope(TrueTarget, NextBlock.Ordinal);
// }
// if (Condition)
cg.EmitSequencePoint(this.Condition.PhpSyntax);
cg.Builder.MarkLabel(this.Condition);
cg.EmitConvert(this.Condition, cg.CoreTypes.Boolean);
cg.Builder.EmitBranch(ILOpCode.Brtrue, TrueTarget);
}
else
{
// if (Condition)
cg.EmitSequencePoint(this.Condition.PhpSyntax);
cg.EmitConvert(this.Condition, cg.CoreTypes.Boolean);
cg.Builder.EmitBranch(ILOpCode.Brfalse, FalseTarget);
// {
cg.GenerateScope(TrueTarget, NextBlock.Ordinal);
// }
}
cg.Scope.ContinueWith(FalseTarget);
}
示例2: EmitInit
internal void EmitInit(CodeGenerator cg)
{
var fldplace = new FieldPlace(IsStatic ? null : new ArgPlace(ContainingType, 0), this);
if (this.Initializer != null)
{
// fld = <initializer>
fldplace.EmitStorePrepare(cg.Builder);
cg.EmitConvert(this.Initializer, this.Type);
fldplace.EmitStore(cg.Builder);
}
else
{
// fld = default(type)
cg.EmitInitializePlace(fldplace);
}
}
示例3: EmitClassName
/// <summary>
/// Emits name of bound type.
/// </summary>
/// <param name="cg"></param>
internal void EmitClassName(CodeGenerator cg)
{
if (TypeExpression != null)
{
cg.EmitConvert(TypeExpression, cg.CoreTypes.String);
}
else
{
if (_typeRef is PrimitiveTypeRef)
{
throw new InvalidOperationException();
}
else if (_typeRef is TranslatedTypeRef || _typeRef is ClassTypeRef)
{
var classname = ((INamedTypeRef)_typeRef).ClassName;
cg.Builder.EmitStringConstant(classname.ToString());
}
else
{
throw Roslyn.Utilities.ExceptionUtilities.UnexpectedValue(_typeRef);
}
}
}
示例4: Emit
internal override void Emit(CodeGenerator cg)
{
cg.EmitSequencePoint(this.PhpSyntax);
var rtype = cg.Routine.ReturnType;
var rvoid = rtype.SpecialType == SpecialType.System_Void;
//
if (this.Returned == null)
{
if (rvoid)
{
// <void>
}
else
{
// <default>
cg.EmitLoadDefault(rtype, cg.Routine.ResultTypeMask);
}
}
else
{
if (rvoid)
{
// <expr>;
cg.EmitPop(this.Returned.Emit(cg));
}
else
{
// return (T)<expr>;
cg.EmitConvert(this.Returned, rtype);
}
}
// .ret
cg.EmitRet(rtype);
}
示例5: EmitCallsiteCall
internal override TypeSymbol EmitCallsiteCall(CodeGenerator cg)
{
if (_name.IsDirect)
{
return base.EmitCallsiteCall(cg);
}
else
{
Debug.Assert(_name.NameExpression != null);
// faster to emit PhpCallback.Invoke
// NameExpression.AsCallback().Invoke(Context, PhpValue[])
cg.EmitConvert(_name.NameExpression, cg.CoreTypes.IPhpCallable); // (IPhpCallable)Name
cg.EmitLoadContext(); // Context
cg.Emit_NewArray(cg.CoreTypes.PhpValue, _arguments.Select(a => a.Value).ToArray()); // PhpValue[]
return cg.EmitCall(ILOpCode.Callvirt, cg.CoreTypes.IPhpCallable.Symbol.LookupMember<MethodSymbol>("Invoke"));
}
}
示例6: EmitBinaryXor
/// <summary>
/// Emits binary operation XOR.
/// </summary>
TypeSymbol EmitBinaryXor(CodeGenerator cg)
{
// LOAD <(bool) leftSon> == <(bool) rightSon>;
cg.EmitConvert(Left, cg.CoreTypes.Boolean);
cg.EmitConvert(Right, cg.CoreTypes.Boolean);
cg.EmitOpCode(ILOpCode.Ceq);
cg.EmitOpCode(ILOpCode.Ldc_i4_0);
cg.EmitOpCode(ILOpCode.Ceq);
return cg.CoreTypes.Boolean;
}
示例7: EmitBitOr
internal static TypeSymbol EmitBitOr(CodeGenerator cg, TypeSymbol xtype, BoundExpression right)
{
switch (xtype.SpecialType)
{
case SpecialType.System_Void:
case SpecialType.System_Int32:
case SpecialType.System_Boolean:
case SpecialType.System_Double:
cg.EmitConvert(xtype, 0, cg.CoreTypes.Long);
goto case SpecialType.System_Int64;
case SpecialType.System_Int64:
cg.EmitConvert(right, cg.CoreTypes.Long);
cg.Builder.EmitOpCode(ILOpCode.Or);
return cg.CoreTypes.Long;
case SpecialType.System_String:
throw new NotImplementedException(); // string | string or string | long
default:
if (right.ResultType != null && right.ResultType.SpecialType != SpecialType.System_String)
{
// value | !string -> long | long -> long
cg.EmitConvert(xtype, 0, cg.CoreTypes.Long);
goto case SpecialType.System_Int64;
}
cg.EmitConvert(xtype, 0, cg.CoreTypes.PhpValue);
cg.EmitConvert(right, cg.CoreTypes.PhpValue);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.BitwiseOr_PhpValue_PhpValue)
.Expect(cg.CoreTypes.PhpValue);
}
}
示例8: Emit
internal override TypeSymbol Emit(CodeGenerator cg)
{
cg.EmitConvert(this.Variable, cg.CoreTypes.PhpValue);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.IsEmpty_PhpValue)
.Expect(SpecialType.System_Boolean);
}
示例9: EmitStore
public void EmitStore(CodeGenerator cg, TypeSymbol valueType)
{
var type = _place.TypeOpt;
// Write Ref
if (_access.IsWriteRef)
{
if (valueType != cg.CoreTypes.PhpAlias)
{
Debug.Assert(false, "caller should get aliased value");
cg.EmitConvertToPhpValue(valueType, 0);
valueType = cg.Emit_PhpValue_MakeAlias();
}
//
if (type == cg.CoreTypes.PhpAlias)
{
// <place> = <alias>
_place.EmitStore(cg.Builder);
}
else if (type == cg.CoreTypes.PhpValue)
{
// <place> = PhpValue.Create(<alias>)
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpValue.Create_PhpAlias);
_place.EmitStore(cg.Builder);
}
else
{
Debug.Assert(false, "Assigning alias to non-aliasable variable.");
cg.EmitConvert(valueType, 0, type);
_place.EmitStore(cg.Builder);
}
}
else if (_access.IsUnset)
{
Debug.Assert(valueType == null);
// <place> =
if (type == cg.CoreTypes.PhpAlias)
{
// new PhpAlias(void)
cg.Emit_PhpValue_Void();
cg.Emit_PhpValue_MakeAlias();
}
else if (type.IsReferenceType)
{
// null
cg.Builder.EmitNullConstant();
}
else
{
// default(T)
cg.EmitLoadDefaultOfValueType(type);
}
_place.EmitStore(cg.Builder);
}
else
{
//
if (type == cg.CoreTypes.PhpAlias)
{
// <place>.Value = <value>
cg.EmitConvertToPhpValue(valueType, 0);
cg.Emit_PhpAlias_SetValue();
}
else if (type == cg.CoreTypes.PhpValue)
{
if (_thint.IsRef)
{
// Operators.SetValue(ref <place>, (PhpValue)<value>);
cg.EmitConvertToPhpValue(valueType, 0);
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.SetValue_PhpValueRef_PhpValue);
}
else
{
// <place> = <value>
cg.EmitConvertToPhpValue(valueType, 0);
_place.EmitStore(cg.Builder);
}
}
else
{
cg.EmitConvert(valueType, 0, type);
_place.EmitStore(cg.Builder);
}
}
}
示例10: EmitName
/// <summary>
/// Emits name as string, uses cached variable.
/// </summary>
void EmitName(CodeGenerator cg, BoundExpression name)
{
Contract.ThrowIfNull(cg);
Contract.ThrowIfNull(name);
if (_name_loc != null)
{
cg.Builder.EmitLocalLoad(_name_loc);
}
else
{
_cg = cg;
// return (<loc> = <name>)
_name_loc = cg.GetTemporaryLocal(cg.CoreTypes.String);
cg.EmitConvert(name, cg.CoreTypes.String);
cg.Builder.EmitOpCode(ILOpCode.Dup);
cg.Builder.EmitLocalStore(_name_loc);
}
}
示例11: EmitLoad
public TypeSymbol EmitLoad(CodeGenerator cg)
{
// resolve actual return type
TypeSymbol return_type;
if (Access.EnsureObject) return_type = cg.CoreTypes.Object;
else if (Access.EnsureArray) return_type = cg.CoreTypes.IPhpArray;
else if (Access.IsReadRef) return_type = cg.CoreTypes.PhpAlias;
else return_type = Access.TargetType ?? cg.CoreTypes.PhpValue;
var args = new List<TypeSymbol>();
// NameExpression in case of indirect call
if (!_name.IsDirect)
{
cg.EmitConvert(_name.NameExpression, cg.CoreTypes.String);
args.Add(cg.CoreTypes.String);
}
// Target()
var functype = cg.Factory.GetCallSiteDelegateType(
cg.CoreTypes.PhpTypeInfo, RefKind.None,
args.AsImmutable(),
default(ImmutableArray<RefKind>),
null,
return_type);
cg.EmitCall(ILOpCode.Callvirt, functype.DelegateInvokeMethod);
if (_boundref.IsClassConstant)
{
throw new NotImplementedException();
}
//
_lazyLoadCallSite.Construct(functype, cctor =>
{
// new GetFieldBinder(field_name, context, return, flags) // TODO: class constants
cctor.Builder.EmitStringConstant(this.NameValueOpt);
cctor.EmitLoadToken(cg.Routine.ContainingType, null);
cctor.EmitLoadToken(return_type, null);
cctor.Builder.EmitIntConstant((int)Access.AccessFlags);
cctor.EmitCall(ILOpCode.Newobj, cg.CoreMethods.Dynamic.GetFieldBinder_ctor);
});
//
return return_type;
}
示例12: EmitStorePrepare
public void EmitStorePrepare(CodeGenerator cg, InstanceCacheHolder instanceOpt = null)
{
if (_lazyStoreCallSite == null)
_lazyStoreCallSite = cg.Factory.StartCallSite("set_" + this.NameValueOpt);
// callsite.Target callsite
_lazyStoreCallSite.EmitLoadTarget(cg.Builder);
_lazyStoreCallSite.Place.EmitLoad(cg.Builder);
// instance
InstanceCacheHolder.EmitInstance(instanceOpt, cg, Instance);
// NameExpression in case of indirect call
if (!_name.IsDirect)
{
cg.EmitConvert(_name.NameExpression, cg.CoreTypes.String);
}
}
示例13: EmitLtGt
/// <summary>
/// Emits comparison operator pushing <c>bool</c> (<c>i4</c> of value <c>0</c> or <c>1</c>) onto the evaluation stack.
/// </summary>
/// <returns>Resulting type code pushed onto the top of evaliuation stack.</returns>
internal static TypeSymbol EmitLtGt(CodeGenerator cg, TypeSymbol xtype, BoundExpression right, bool lt)
{
TypeSymbol ytype;
var il = cg.Builder;
switch (xtype.SpecialType)
{
case SpecialType.System_Void:
// Operators.CompareNull(value)
throw new NotImplementedException();
case SpecialType.System_Int32:
// i4 -> i8
il.EmitOpCode(ILOpCode.Conv_i8);
goto case SpecialType.System_Int64;
case SpecialType.System_Int64:
ytype = cg.EmitConvertIntToLong(cg.Emit(right)); // bool|int -> long
if (ytype.SpecialType == SpecialType.System_Int64)
{
il.EmitOpCode(lt ? ILOpCode.Clt : ILOpCode.Cgt);
}
else if (ytype.SpecialType == SpecialType.System_Double)
{
// i8 <> r8
return cg.EmitCall(ILOpCode.Call, lt
? cg.CoreMethods.Operators.Clt_long_double
: cg.CoreMethods.Operators.Cgt_long_double);
}
else
{
ytype = cg.EmitConvertToPhpValue(ytype, 0);
// compare(i8, value) <> 0
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Compare_long_value);
il.EmitOpCode(ILOpCode.Ldc_i4_0, 1);
il.EmitOpCode(lt ? ILOpCode.Clt : ILOpCode.Cgt);
}
return cg.CoreTypes.Boolean;
case SpecialType.System_Double:
ytype = cg.EmitConvertNumberToDouble(right); // bool|int|long|number -> double
if (ytype.SpecialType == SpecialType.System_Double)
{
// r8 <> r8
il.EmitOpCode(lt ? ILOpCode.Clt : ILOpCode.Cgt);
}
else
{
// compare(r8, value)
ytype = cg.EmitConvertToPhpValue(ytype, 0);
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Compare_double_value);
// <> 0
il.EmitOpCode(ILOpCode.Ldc_i4_0, 1);
il.EmitOpCode(lt ? ILOpCode.Clt : ILOpCode.Cgt);
}
return cg.CoreTypes.Boolean;
case SpecialType.System_String:
ytype = cg.Emit(right);
if (ytype.SpecialType == SpecialType.System_String)
{
// compare(string, string)
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Compare_string_string);
}
else if (ytype.SpecialType == SpecialType.System_Int64)
{
// compare(string, long)
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Compare_string_long);
}
else if (ytype.SpecialType == SpecialType.System_Double)
{
// compare(string, double)
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Compare_string_double);
}
else
{
// compare(string, value)
ytype = cg.EmitConvertToPhpValue(ytype, 0);
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Compare_string_value);
}
// <> 0
il.EmitOpCode(ILOpCode.Ldc_i4_0, 1);
il.EmitOpCode(lt ? ILOpCode.Clt : ILOpCode.Cgt);
return cg.CoreTypes.Boolean;
case SpecialType.System_Boolean:
cg.EmitConvert(right, cg.CoreTypes.Boolean);
ytype = cg.CoreTypes.Boolean;
// compare(bool, bool)
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Compare_bool_bool);
//.........这里部分代码省略.........
示例14: EmitAppend
static TypeSymbol EmitAppend(CodeGenerator cg, TypeSymbol xtype, BoundExpression y)
{
if (xtype == cg.CoreTypes.PhpString)
{
// x.Append(y); return x;
cg.Builder.EmitOpCode(ILOpCode.Dup);
cg.EmitConvert(y, cg.CoreTypes.String);
cg.EmitCall(ILOpCode.Callvirt, cg.CoreMethods.PhpString.Append_String);
//
return xtype;
}
else
{
// concat(x, y)
cg.EmitConvert(xtype, 0, cg.CoreTypes.String);
cg.EmitConvert(y, cg.CoreTypes.String);
return cg.EmitCall(ILOpCode.Newobj, cg.CoreMethods.Ctors.PhpString_string_string);
}
}
示例15: EmitDiv
internal static TypeSymbol EmitDiv(CodeGenerator cg, TypeSymbol xtype, BoundExpression right, TypeSymbol resultTypeOpt = null)
{
var il = cg.Builder;
xtype = cg.EmitConvertIntToLong(xtype); // int|bool -> int64
TypeSymbol ytype;
switch (xtype.SpecialType)
{
case SpecialType.System_Double:
ytype = cg.EmitConvertNumberToDouble(right); // bool|int|long|number -> double
if (ytype.SpecialType == SpecialType.System_Double)
{
il.EmitOpCode(ILOpCode.Div);
return xtype; // r8
}
// double / value : double
cg.EmitConvertToPhpValue(ytype, 0);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Div_double_PhpValue);
case SpecialType.System_Int64:
ytype = cg.EmitConvertIntToLong(cg.Emit(right)); // bool|int -> long
if (ytype == cg.CoreTypes.PhpNumber)
{
// long / number : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Division_long_number)
.Expect(cg.CoreTypes.PhpNumber);
}
// long / value : number
cg.EmitConvertToPhpValue(ytype, 0);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Div_long_PhpValue);
default:
if (xtype == cg.CoreTypes.PhpNumber)
{
ytype = cg.EmitConvertIntToLong(cg.Emit(right)); // bool|int -> long
if (ytype == cg.CoreTypes.PhpNumber)
{
// nmumber / number : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Division_number_number)
.Expect(cg.CoreTypes.PhpNumber);
}
}
// x -> PhpValue
xtype = cg.EmitConvertToPhpValue(xtype, 0);
cg.EmitConvert(right, cg.CoreTypes.PhpValue);
ytype = cg.CoreTypes.PhpValue;
// value / value : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.Div_PhpValue_PhpValue);
}
}