本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.Emit方法的具体用法?C# CodeGenerator.Emit怎么用?C# CodeGenerator.Emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.Emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
internal override void Generate(CodeGenerator cg)
{
Debug.Assert(this.Enumeree != null);
// get the enumerator,
// bind actual MoveNext() and CurrentValue and CurrentKey
// Template: using(
// a) enumerator = enumeree.GetEnumerator()
// b) enumerator = Operators.GetEnumerator(enumeree)
// ) ...
cg.EmitSequencePoint(this.Enumeree.PhpSyntax);
var enumereeType = cg.Emit(this.Enumeree);
Debug.Assert(enumereeType.SpecialType != SpecialType.System_Void);
var getEnumeratorMethod = enumereeType.LookupMember<MethodSymbol>(WellKnownMemberNames.GetEnumeratorMethodName);
TypeSymbol enumeratorType;
if (enumereeType.IsOfType(cg.CoreTypes.PhpArray))
{
cg.Builder.EmitBoolConstant(_aliasedValues);
// PhpArray.GetForeachtEnumerator(bool)
enumeratorType = cg.EmitCall(ILOpCode.Callvirt, cg.CoreMethods.PhpArray.GetForeachEnumerator_Boolean); // TODO: IPhpArray
}
// TODO: IPhpEnumerable
// TODO: IPhpArray
// TODO: Iterator
else if (getEnumeratorMethod != null && getEnumeratorMethod.ParameterCount == 0 && enumereeType.IsReferenceType)
{
// enumeree.GetEnumerator()
enumeratorType = cg.EmitCall(getEnumeratorMethod.IsVirtual ? ILOpCode.Callvirt : ILOpCode.Call, getEnumeratorMethod);
}
else
{
cg.EmitConvertToPhpValue(enumereeType, 0);
cg.Builder.EmitBoolConstant(_aliasedValues);
cg.EmitCallerRuntimeTypeHandle();
// Operators.GetForeachEnumerator(PhpValue, bool, RuntimeTypeHandle)
enumeratorType = cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.GetForeachEnumerator_PhpValue_Bool_RuntimeTypeHandle);
}
//
_current = enumeratorType.LookupMember<PropertySymbol>(WellKnownMemberNames.CurrentPropertyName); // TODO: Err if no Current
_currentValue = enumeratorType.LookupMember<PropertySymbol>(_aliasedValues ? "CurrentValueAliased" : "CurrentValue");
_currentKey = enumeratorType.LookupMember<PropertySymbol>("CurrentKey");
_disposeMethod = enumeratorType.LookupMember<MethodSymbol>("Dispose", m => m.ParameterCount == 0 && !m.IsStatic);
//
_enumeratorLoc = cg.GetTemporaryLocal(enumeratorType);
cg.Builder.EmitLocalStore(_enumeratorLoc);
// bind methods
_moveNextMethod = enumeratorType.LookupMember<MethodSymbol>(WellKnownMemberNames.MoveNextMethodName); // TODO: Err if there is no MoveNext()
Debug.Assert(_moveNextMethod.ReturnType.SpecialType == SpecialType.System_Boolean);
Debug.Assert(_moveNextMethod.IsStatic == false);
if (_disposeMethod != null)
{
/* Template: try { body } finally { enumerator.Dispose }
*/
// try {
cg.Builder.AssertStackEmpty();
cg.Builder.OpenLocalScope(ScopeType.TryCatchFinally);
cg.Builder.OpenLocalScope(ScopeType.Try);
//
EmitBody(cg);
// }
cg.Builder.CloseLocalScope(); // /Try
// finally {
cg.Builder.OpenLocalScope(ScopeType.Finally);
// enumerator.Dispose() & cleanup
EmitDisposeAndClean(cg);
// }
cg.Builder.CloseLocalScope(); // /Finally
cg.Builder.CloseLocalScope(); // /TryCatchFinally
}
else
{
EmitBody(cg);
EmitDisposeAndClean(cg);
}
}
示例2: EmitBitOr
internal static TypeSymbol EmitBitOr(CodeGenerator cg, BoundExpression left, BoundExpression right)
{
// most common cases:
if (cg.IsLongOnly(left.TypeRefMask) || cg.IsLongOnly(right.TypeRefMask))
{
// i64 | i64 : i64
cg.EmitConvert(left, cg.CoreTypes.Long);
cg.EmitConvert(right, cg.CoreTypes.Long);
cg.Builder.EmitOpCode(ILOpCode.Or);
return cg.CoreTypes.Long;
}
//
return EmitBitOr(cg, cg.Emit(left), right);
}
示例3: EmitStrictEquality
internal static TypeSymbol EmitStrictEquality(CodeGenerator cg, BoundExpression left, BoundExpression right)
=> EmitStrictEquality(cg, cg.Emit(left), right);
示例4: 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();
}
示例5: EmitSub
/// <summary>
/// Emits subtraction operator.
/// </summary>
internal static TypeSymbol EmitSub(CodeGenerator cg, BoundExpression left, BoundExpression right, TypeSymbol resultTypeOpt = null)
{
return EmitSub(cg, cg.Emit(left), right, resultTypeOpt);
}
示例6: EmitDivision
/// <summary>
/// Emits <c>/</c> operator.
/// </summary>
TypeSymbol EmitDivision(CodeGenerator cg)
=> EmitDiv(cg, cg.Emit(Left), Right);
示例7: 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);
}
}
示例8: EmitMultiply
/// <summary>
/// Emits <c>*</c> operation.
/// </summary>
TypeSymbol EmitMultiply(CodeGenerator cg)
=> EmitMul(cg, cg.Emit(Left), Right);
示例9: EmitMul
internal static TypeSymbol EmitMul(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)
{
// r8 * r8 : r8
il.EmitOpCode(ILOpCode.Mul);
return xtype; // r8
}
else if (ytype == cg.CoreTypes.PhpValue)
{
// r8 * value : r8
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_double_value)
.Expect(SpecialType.System_Double);
}
//
throw new NotImplementedException($"Mul(double, {ytype.Name})");
case SpecialType.System_Int64:
ytype = cg.EmitConvertIntToLong(cg.Emit(right));
if (ytype.SpecialType == SpecialType.System_Int64)
{
// i8 * i8 : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_long)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype.SpecialType == SpecialType.System_Double)
{
// i8 * r8 : r8
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_double)
.Expect(SpecialType.System_Double);
}
else if (ytype == cg.CoreTypes.PhpNumber)
{
// i8 * number : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_number)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype == cg.CoreTypes.PhpValue)
{
// i8 * value : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_value)
.Expect(cg.CoreTypes.PhpNumber);
}
//
throw new NotImplementedException($"Mul(int64, {ytype.Name})");
default:
if (xtype == cg.CoreTypes.PhpNumber)
{
ytype = cg.EmitConvertIntToLong(cg.Emit(right));
if (ytype.SpecialType == SpecialType.System_Int64)
{
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_long)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype.SpecialType == SpecialType.System_Double)
{
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_double)
.Expect(cg.CoreTypes.Double);
}
else if (ytype == cg.CoreTypes.PhpNumber)
{
// number * number : number
cg.EmitConvertToPhpNumber(ytype, right.TypeRefMask);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_number)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype == cg.CoreTypes.PhpValue)
{
// number * value : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_value)
.Expect(cg.CoreTypes.PhpNumber);
}
else
{
// TODO: unconvertible
// number * number : number
cg.EmitConvertToPhpNumber(ytype, right.TypeRefMask);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_number)
.Expect(cg.CoreTypes.PhpNumber);
}
//
throw new NotImplementedException($"Mul(PhpNumber, {ytype.Name})");
}
else if (xtype == cg.CoreTypes.PhpValue)
{
ytype = cg.EmitConvertIntToLong(cg.Emit(right)); // bool|int -> long
if (ytype == cg.CoreTypes.PhpValue)
{
// value * value : number
//.........这里部分代码省略.........
示例10: 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);
//.........这里部分代码省略.........
示例11: EmitPow
/// <summary>
/// Emits <c>pow</c> operator.
/// </summary>
TypeSymbol EmitPow(CodeGenerator cg)
{
return EmitPow(cg, cg.Emit(Left), Left.TypeRefMask, Right);
}
示例12: EmitAdd
/// <summary>
/// Emits <c>+</c> operator suitable for actual operands.
/// </summary>
private static TypeSymbol EmitAdd(CodeGenerator cg, BoundExpression left, BoundExpression right, TypeSymbol resultTypeOpt = null)
{
// Template: x + y
return EmitAdd(cg, cg.Emit(left), right, resultTypeOpt);
}
示例13: EmitMinus
TypeSymbol EmitMinus(CodeGenerator cg)
{
// Template: 0L - Operand
var il = cg.Builder;
var t = cg.Emit(this.Operand);
switch (t.SpecialType)
{
case SpecialType.System_Double:
// -r8
il.EmitOpCode(ILOpCode.Neg);
return t;
case SpecialType.System_Int32:
// -(i8)i4
il.EmitOpCode(ILOpCode.Conv_i8); // i4 -> i8
il.EmitOpCode(ILOpCode.Neg); // result will fit into long for sure
return cg.CoreTypes.Long;
case SpecialType.System_Int64:
// PhpNumber.Minus(i8) : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Negation_long)
.Expect(cg.CoreTypes.PhpNumber);
default:
if (t != cg.CoreTypes.PhpNumber)
{
cg.EmitConvertToPhpNumber(t, 0);
}
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Negation)
.Expect(cg.CoreTypes.PhpNumber);
}
}
示例14: EmitPlus
TypeSymbol EmitPlus(CodeGenerator cg)
{
// Template: 0L + Operand
// convert value to a number
var il = cg.Builder;
var t = cg.Emit(this.Operand);
switch (t.SpecialType)
{
case SpecialType.System_Double:
case SpecialType.System_Int32:
case SpecialType.System_Int64:
return t;
case SpecialType.System_Boolean:
// (long)(int)bool
il.EmitOpCode(ILOpCode.Conv_i4);
il.EmitOpCode(ILOpCode.Conv_i8);
return cg.CoreTypes.Long;
default:
if (t != cg.CoreTypes.PhpNumber)
{
cg.EmitConvertToPhpNumber(t, 0);
}
return cg.CoreTypes.PhpNumber;
}
}
示例15: EmitBitNot
TypeSymbol EmitBitNot(CodeGenerator cg)
{
var il = cg.Builder;
var t = cg.Emit(this.Operand);
switch (t.SpecialType)
{
case SpecialType.System_Double:
case SpecialType.System_Int32:
// r8|i4 -> i8
il.EmitOpCode(ILOpCode.Conv_i8);
goto case SpecialType.System_Int64;
case SpecialType.System_Int64:
il.EmitOpCode(ILOpCode.Not); // ~i64 : i64
return cg.CoreTypes.Long;
case SpecialType.System_Boolean:
throw new NotImplementedException(); // Err
default:
if (t == cg.CoreTypes.PhpArray)
{
// ERR
}
// ~ PhpValue
cg.EmitConvert(t, Operand.TypeRefMask, cg.CoreTypes.PhpValue);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.BitwiseNot_PhpValue);
}
}