本文整理汇总了C#中PhpTypeCode类的典型用法代码示例。如果您正苦于以下问题:C# PhpTypeCode类的具体用法?C# PhpTypeCode怎么用?C# PhpTypeCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PhpTypeCode类属于命名空间,在下文中一共展示了PhpTypeCode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: EmitLambda
public MethodInfo EmitLambda(string name, AST.DirectVarUse variable, AST.Expression/*!*/ expression,
PhpTypeCode returnType)
{
MethodBuilder result = linqContextBuilder.DefineMethod(name, MethodAttributes.PrivateScope | MethodAttributes.SpecialName,
PhpTypeCodeEnum.ToType(returnType), new Type[] { typeof(object) });
ILEmitter il = new ILEmitter(result);
EnterLambdaDeclaration(il);
if (variable != null)
{
// <variable> = COPY(<argument>);
variable.Emit(cg);
il.Emit(OpCodes.Ldarg_1);
cg.EmitVariableCopy(CopyReason.Assigned, null);
variable.EmitAssign(cg);
}
cg.EmitConversion(expression, returnType);
il.Emit(OpCodes.Ret);
LeaveLambdaDeclaration();
return result;
}
开发者ID:jdluzen,项目名称:Phalanger,代码行数:26,代码来源:LinqBuilder.cs
示例2: EmitReturnValueCopy
/// <summary>
/// Emit <see cref="PhpVariable.Copy"/> if needed. It means <see cref="Expression.Access"/> has to be <see cref="AccessType.Read"/> and <paramref name="returnType"/> has to be copiable.
/// </summary>
/// <param name="il">The <see cref="ILEmitter"/>.</param>
/// <param name="returnType"><see cref="PhpTypeCode"/> of function call return value.</param>
protected void EmitReturnValueCopy(ILEmitter/*!*/il, PhpTypeCode returnType)
{
Debug.Assert(il != null);
// copy only if we are reading the return value &&
// only if return type is copiable:
if (access != AccessType.None && // reading, not literals:
PhpTypeCodeEnum.IsDeeplyCopied(returnType) &&
returnType != PhpTypeCode.PhpReference) // PhpSmartReference can be an issue if method returns an object field (but this is handled by binders)
{
il.LdcI4((int)CopyReason.ReturnedByCopy);
il.Emit(OpCodes.Call, Methods.PhpVariable.Copy);
}
}
开发者ID:MpApQ,项目名称:Phalanger,代码行数:19,代码来源:FunctionCall.cs
示例3: EmitSetConversion
internal void EmitSetConversion(ILEmitter/*!*/ il, PhpTypeCode sourceTypeCode, Type/*!*/ targetType)
{
LocalBuilder strictness = il.GetTemporaryLocal(typeof(PHP.Core.ConvertToClr.ConversionStrictness));
if (!ClrOverloadBuilder.EmitConvertToClr(il, sourceTypeCode, targetType, strictness))
{
Label label_ok = il.DefineLabel();
il.Ldloc(strictness);
il.LdcI4((int)PHP.Core.ConvertToClr.ConversionStrictness.Failed);
il.Emit(OpCodes.Ceq);
il.Emit(OpCodes.Brfalse, label_ok);
il.Emit(OpCodes.Ldstr, Property.DeclaringType.FullName);
il.Emit(OpCodes.Ldstr, Property.FullName);
il.Emit(OpCodes.Call, Methods.PhpException.PropertyTypeMismatch);
il.MarkLabel(label_ok, true);
}
il.ReturnTemporaryLocal(strictness);
}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:20,代码来源:Properties.cs
示例4: EmitLoadClrParameter
/// <summary>
/// Emits code that loads a specified parameter on the evaluation stack.
/// </summary>
/// <param name="paramInfo">The parameter to load.</param>
/// <param name="requiredTypeCode">Specifies whether <see cref="PhpReference"/>
/// (<see cref="PhpTypeCode.PhpReference"/>), <see cref="object"/> (<see cref="PhpTypeCode.Object"/>),
/// or the most fitting of these two should be loaded.</param>
public void EmitLoadClrParameter(ParameterInfo/*!*/ paramInfo, PhpTypeCode requiredTypeCode)
{
if (paramInfo.IsOut) il.Emit(OpCodes.Ldnull);
else
{
il.Ldarg(paramInfo.Position + paramOffset);
// dereference ref param
Type param_type = paramInfo.ParameterType;
if (param_type.IsByRef)
{
param_type = param_type.GetElementType();
il.Ldind(param_type);
}
// convert the parameter to PHP type
PhpTypeCode type_code = ClrOverloadBuilder.EmitConvertToPhp(
il,
param_type/*,
scriptContextPlace*/);
il.EmitBoxing(type_code);
}
// check whether we have to create a PhpReference
if (requiredTypeCode == PhpTypeCode.Object ||
(requiredTypeCode == PhpTypeCode.Unknown && !paramInfo.ParameterType.IsByRef)) return;
if (paramInfo.ParameterType.IsByRef)
{
LocalBuilder ref_local = il.DeclareLocal(Types.PhpReference[0]);
// remember the PhpReference in a local
il.Emit(OpCodes.Newobj, Constructors.PhpReference_Object);
il.Emit(OpCodes.Dup);
il.Stloc(ref_local);
referenceLocals[paramInfo.Position] = ref_local;
}
else
{
// no reference store-back is necessary
il.Emit(OpCodes.Newobj, Constructors.PhpReference_Object);
}
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:53,代码来源:ClrStubBuilder.cs
示例5: EmitSetItem
internal void EmitSetItem(PhpTypeCode keyTypeCode, Expression keyExpr, bool reference)
{
MethodInfo method;
switch (keyTypeCode)
{
case PhpTypeCode.Integer:
method = (reference) ? Methods.Operators.SetItemRef.Int32 : Methods.Operators.SetItem.Int32;
break;
case PhpTypeCode.String:
if (reference)
{
method = Methods.Operators.SetItemRef.String;
}
else
{
if (EmitExactStringKeyHash(keyTypeCode, keyExpr))
method = Methods.Operators.SetItemExact;
else
method = Methods.Operators.SetItem.String;
}
break;
case PhpTypeCode.Object:
method = (reference) ? Methods.Operators.SetItemRef.Object : Methods.Operators.SetItem.Object;
break;
case PhpTypeCode.Invalid:
method = Methods.Operators.SetItem.Keyless;
break;
default:
throw new ArgumentException();
}
il.Emit(OpCodes.Call, method);
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:36,代码来源:CodeGenerator.cs
示例6: ExpressionPlace
public ExpressionPlace(CodeGenerator/*!*/ codeGenerator, Expression/*!*/ expression)
{
this.codeGenerator = codeGenerator;
this.expression = expression;
this.typeCode = PhpTypeCode.Invalid;
}
开发者ID:proff,项目名称:Phalanger,代码行数:6,代码来源:Expression.cs
示例7: EmitBoxing
// Obsolete:
// <summary>
// A <see cref="Stack{T}"/> class that stores temporarily used variables. See Remarks for more information.
// </summary>
// <remarks>This stack stores locals that are used to obtain address of a variable stored in
// a runtime variables table while calling methods from <see cref="PHP.Core.Operators"/> having
// a <c>ref</c> argument. Those variables are not so short-live to be obtained by <see cref="GetTemporaryLocal"/>,
// but can be reused within a defining scope under certain circumstances.
// When <see cref="GetAddressStorageLocal"/> method is called, the temporary
// local is either popped from the cache or a new local is defined if the cache is empty.
// If the variable become useless, <see cref="ReturnAddressStorageLocal"/> method should
// be called to push the variable back to cache. Once the variable is returned to cache it must not have
// been used unless it is obtained again by <see cref="GetAddressStorageLocal"/> method.
// The cache is created when the first local is returned.
// </remarks>
#endregion
#region PHP Specific
internal void EmitBoxing(PhpTypeCode type)
{
switch (type)
{
case PhpTypeCode.Integer:
il.Emit(OpCodes.Box, typeof(Int32));
break;
case PhpTypeCode.LongInteger:
il.Emit(OpCodes.Box, typeof(Int64));
break;
case PhpTypeCode.Double:
il.Emit(OpCodes.Box, typeof(Double));
break;
case PhpTypeCode.Boolean:
il.Emit(OpCodes.Box, typeof(Boolean));
break;
case PhpTypeCode.Void:
il.Emit(OpCodes.Ldnull);
break;
}
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:45,代码来源:ILEmitter.cs
示例8: EmitNodeWriteRef
/// <summary>
/// Emits code to prepare an evaluation stack for storing a reference into a variable.
/// Supports operators chaining. Store is finished by calling <see cref="EmitAssign"/>.
/// </summary>
/// <param name="codeGenerator"></param>
private PhpTypeCode EmitNodeWriteRef(CodeGenerator codeGenerator)
{
ChainBuilder chain = codeGenerator.ChainBuilder;
// Case 3: a_[x]_[x] never reached
Debug.Assert(chain.IsArrayItem == false);
// Case 4,5 never reached
// 4: a[x]->...
// 5: ...->a[]->...
Debug.Assert(chain.IsMember == false);
// 1, 2, 6, 7
if (this.isMemberOf != null)
{
// 6, 7: ...->a[x]_[x]_
chain.Create();
chain.Begin();
// Store isMemberOf for lazy emit
chain.SetObjectForLazyEmit(this);
chain.IsArrayItem = true;
chain.IsLastMember = false;
chain.Lengthen(); // for own []
array.Emit(codeGenerator);
indexTypeCode = codeGenerator.EmitArrayKey(chain, index);
// Note that EmitAssign will finish the work (SetArrayItem or PhpArray.Add)
}
else
{
// 1, 2
Debug.Assert(this.isMemberOf == null);
if (array is ItemUse || array is DirectStFldUse || array is IndirectStFldUse /* ??? */)
{
// 2: a[]_[]_
chain.Create();
chain.Begin();
chain.IsArrayItem = true;
chain.IsLastMember = true;
array.Emit(codeGenerator);
indexTypeCode = codeGenerator.EmitArrayKey(chain, index);
// Note that further work will be done by EmitAssign (SetArrayItem or PhpArray.Add)
}
// 1: a_[x]_
// Do nothing now, let the work be done in EmitAssign()
// Note further work will be done by EmitAssign (either SetItem or SetItemRef);
}
return PhpTypeCode.Unknown;
}
开发者ID:Ashod,项目名称:Phalanger,代码行数:56,代码来源:ItemUse.cs
示例9: EmitCallSetObjectField
private static void EmitCallSetObjectField(CodeGenerator/*!*/ codeGenerator, PhpTypeCode stackTypeCode)
{
// CALL Operators.SetObjectProperty(<STACK:instance>,<STACK:field name>,<STACK:field value>, <type desc>)
codeGenerator.EmitLoadClassContext();
codeGenerator.IL.Emit(OpCodes.Call, Methods.Operators.SetObjectProperty);
//always when function with void return argument is called it's necesarry to add nop instruction due to debugger
if (codeGenerator.Context.Config.Compiler.Debug)
{
codeGenerator.IL.Emit(OpCodes.Nop);
}
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:13,代码来源:VariableUse.cs
示例10: EmitReturnValueHandling
/// <summary>
/// Emits instructions to conform a required access type.
/// </summary>
/// <param name="callExpression">Expression emitting the call.</param>
/// <param name="loadAddress">Whether to load an address of the return value.</param>
/// <param name="result">The type code of a top item of the evaluation stack.</param>
public void EmitReturnValueHandling(Expression/*!*/ callExpression, bool loadAddress, ref PhpTypeCode result)
{
Debug.Assert(callExpression != null);
if (loadAddress)
{
if (result == PhpTypeCode.PhpReference)
{
// LOADADDR STACK.Value;
il.Emit(OpCodes.Ldflda, Fields.PhpReference_Value);
}
else
{
if (result == PhpTypeCode.Void)
il.Emit(OpCodes.Ldnull);
// local = STACK;
// LOADADDR local;
LocalBuilder local = il.GetTemporaryLocal(PhpTypeCodeEnum.ToType(result), true);
il.Stloc(local);
il.Ldloca(local);
}
result = PhpTypeCode.ObjectAddress;
return;
}
switch (callExpression.GetAccess())
{
case AccessType.None:
// return value is discarded:
if (result != PhpTypeCode.Void)
{
il.Emit(OpCodes.Pop);
result = PhpTypeCode.Void;
}
break;
case AccessType.ReadUnknown:
case AccessType.ReadRef:
if (result != PhpTypeCode.PhpReference)
{
// return value is "boxed" to PhpReference:
if (result != PhpTypeCode.Void)
{
EmitBoxing(result);
EmitVariableCopy(CopyReason.ReturnedByCopy, callExpression);
il.Emit(OpCodes.Newobj, Constructors.PhpReference_Object);
}
else
{
il.Emit(OpCodes.Newobj, Constructors.PhpReference_Void);
}
result = PhpTypeCode.PhpReference;
}
break;
case AccessType.Read:
if (result == PhpTypeCode.PhpReference)
{
// return value is dereferenced:
il.Emit(OpCodes.Ldfld, Fields.PhpReference_Value);
result = PhpTypeCode.Object;
}
else if (result == PhpTypeCode.Void)
{
// null value is loaded as a result:
il.Emit(OpCodes.Ldnull);
result = PhpTypeCode.Object;
}
break;
default:
Debug.Fail(null);
break;
}
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:86,代码来源:CodeGenerator.cs
示例11: EmitConversion
/// <summary>
/// Emits IL instructions that convert the top of evaluation stack to a specified type.
/// </summary>
/// <remarks>
/// Emits a call to one of <see cref="PHP.Core.Convert"/> methods to do the conversion.
/// The method result is left on the evaluation stack.
/// </remarks>
internal void EmitConversion(Expression/*!*/ expression, PhpTypeCode dst)
{
// expression is evaluable:
if (expression.HasValue())
{
switch (dst)
{
case PhpTypeCode.String:
il.Emit(OpCodes.Ldstr, PHP.Core.Convert.ObjectToString(expression.GetValue()));
break;
case PhpTypeCode.Boolean:
il.LdcI4(PHP.Core.Convert.ObjectToBoolean(expression.GetValue()) ? 1 : 0);
break;
case PhpTypeCode.Integer:
il.LdcI4(PHP.Core.Convert.ObjectToInteger(expression.GetValue()));
break;
case PhpTypeCode.Double:
il.Emit(OpCodes.Ldc_R8, PHP.Core.Convert.ObjectToDouble(expression.GetValue()));
break;
case PhpTypeCode.Object:
il.LoadLiteral(expression.GetValue());
break;
default:
Debug.Fail("Conversion not implemented.");
break;
}
}
else
{
// emits the expression:
PhpTypeCode src = expression.Emit(this);
// emits no conversion if types are the same:
if (src == dst) return;
// emits boxing if needed (conversion methods takes object):
EmitBoxing(src);
switch (dst)
{
case PhpTypeCode.String:
il.Emit(OpCodes.Call, Methods.Convert.ObjectToString);
break;
case PhpTypeCode.Boolean:
il.Emit(OpCodes.Call, Methods.Convert.ObjectToBoolean);
break;
case PhpTypeCode.Integer:
il.Emit(OpCodes.Call, Methods.Convert.ObjectToBoolean);
break;
case PhpTypeCode.Double:
il.Emit(OpCodes.Call, Methods.Convert.ObjectToDouble);
break;
case PhpTypeCode.Object:
// nop //
break;
default:
Debug.Fail("Conversion is not implemented.");
break;
}
}
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:78,代码来源:CodeGenerator.cs
示例12: EmitEcho
/// <summary>
/// Emits IL instructions to process the <B>echo</B> and <B>print</B> commands.
/// </summary>
/// <param name="expressions">List of expressions to be echoed. They will be evaluated first. The list cannot be null and it must contain at least one element.</param>
public void EmitEcho(Expression[]/*!*/expressions)
{
Debug.Assert(expressions != null);
Debug.Assert(expressions.Length > 0);
// known types of resulting values
PhpTypeCode[] types = new PhpTypeCode[expressions.Length];
// construct the array with values
// to preserve the proper order of evaluation and output
il.LdcI4(expressions.Length);
il.Emit(OpCodes.Newarr, typeof(object));
for (int i = 0; i < expressions.Length; ++i)
{
// array[<i>] = <expressions[i]>;
il.Emit(OpCodes.Dup);
il.LdcI4(i);
EmitBoxing(types[i] = expressions[i].Emit(this));
il.Emit(OpCodes.Stelem_Ref);
}
// echo the values
for (int i = 0; i < expressions.Length; ++i)
{
il.Emit(OpCodes.Dup); // array
il.LdcI4(i); // <i>
il.Emit(OpCodes.Ldelem_Ref); // object array[<i>]
il.EmitUnboxingForArg(types[i]); // UnBox value type, if value-type was boxed here, prepared for method call argument
// convert object to string or PhpBytes to hold the right type on the stack (valid IL)
if (types[i] == PhpTypeCode.PhpBytes) il.Emit(OpCodes.Castclass, Types.PhpBytes[0]);
else if (types[i] == PhpTypeCode.String) il.Emit(OpCodes.Castclass, Types.String[0]);
EmitLoadScriptContext();
// CALL ScriptContext.Echo(<obj>, <ScriptContext>)
EmitEchoStaticCall(types[i]);
}
il.Emit(OpCodes.Pop);// remove the array from the stack
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:43,代码来源:CodeGenerator.cs
示例13: EmitName
internal void EmitName(string fullName, Expression nameExpr, bool createChain, PhpTypeCode dstType)
{
Debug.Assert(fullName != null ^ nameExpr != null);
if (fullName != null)
{
il.Emit(OpCodes.Ldstr, fullName);
}
else
{
if (createChain) ChainBuilder.Create();
EmitConversion(nameExpr, dstType);
if (createChain) ChainBuilder.End();
}
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:15,代码来源:CodeGenerator.cs
示例14: EmitEchoStaticCall
///// <summary>
///// Emits IL instructions for calling the best overload of <see cref="PHP.Core.ScriptContext.Echo"/> method.
///// </summary>
///// <param name="typecode"><see cref="PHP.Core.PhpTypeCode"/> of the parameter.</param>
///// <remarks>GetUserEntryPoint parameters are expected on the evaluation stack. Nothing is left on the evaluation stack.</remarks>
//private void EmitEchoCall(PhpTypeCode typecode)
//{
// switch (typecode)
// {
// case PhpTypeCode.Object:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.Object);
// break;
// case PhpTypeCode.String:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.String);
// break;
// case PhpTypeCode.PhpBytes:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.PhpBytes);
// break;
// case PhpTypeCode.Integer:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.Int);
// break;
// case PhpTypeCode.LongInteger:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.LongInt);
// break;
// case PhpTypeCode.Double:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.Double);
// break;
// case PhpTypeCode.Boolean:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.Bool);
// break;
// default:
// il.Emit(OpCodes.Call, Methods.ScriptContext.Echo.Object);
// break;
// }
//}
/// <summary>
/// Emits IL instructions for calling the best overload of <see cref="PHP.Core.ScriptContext.Echo"/> static method.
/// </summary>
/// <param name="typecode"><see cref="PHP.Core.PhpTypeCode"/> of the parameter.</param>
/// <remarks>Nothing is left on the evaluation stack. Emitted method call expects two parameters on the evaluation stack: (value, ScriptContext).</remarks>
private void EmitEchoStaticCall(PhpTypeCode typecode)
{
switch (typecode)
{
case PhpTypeCode.Object:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.Object);
break;
case PhpTypeCode.String:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.String);
break;
case PhpTypeCode.PhpBytes:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.PhpBytes);
break;
case PhpTypeCode.Integer:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.Int);
break;
case PhpTypeCode.LongInteger:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.LongInt);
break;
case PhpTypeCode.Double:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.Double);
break;
case PhpTypeCode.Boolean:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.Bool);
break;
default:
il.Emit(OpCodes.Call, Methods.ScriptContext.EchoStatic.Object);
break;
}
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:85,代码来源:CodeGenerator.cs
示例15: EmitSetItem
/// <summary>
/// Emits IL instructions that sets the value to an <see cref="PHP.Core.PhpArray"/> item.
/// </summary>
/// <remarks>This method is used to set the item of an array having the index determined (not <B>null</B>).
/// This method is called only in simple cases when operators chained are <b>not</b> involved.
/// See short example of PHP code below.
/// Expects that the reference to the object whose item should be set, the index and the value
/// are loaded on the evaluation stack. Nothing is left on the evaluation stack.
/// stack.
/// </remarks>
/// <example>$a[3] = "foo"; $a[] = "foo";</example>
/// <example>$x[y] =& p; $x[] =& p;</example>
public void EmitSetItem(PhpTypeCode keyTypeCode, Expression index, bool reference)
{
codeGenerator.EmitSetItem(keyTypeCode, index, reference);
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:16,代码来源:Chains.cs
示例16: EmitPopValue
private static void EmitPopValue(CodeGenerator/*!*/ codeGenerator, PhpTypeCode stackTypeCode)
{
// just pop the value that was meant to be written
codeGenerator.IL.Emit(OpCodes.Pop);
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:5,代码来源:VariableUse.cs
示例17: EmitAssign
/// <summary>
/// Finishes the write operation starte by <see cref="Emit"/>.
/// </summary>
internal override PhpTypeCode EmitAssign(CodeGenerator/*!*/ codeGenerator)
{
ChainBuilder chain = codeGenerator.ChainBuilder;
PhpTypeCode result;
switch (access)
{
case AccessType.WriteAndReadRef:
case AccessType.WriteAndReadUnknown:
case AccessType.ReadAndWrite:
case AccessType.ReadAndWriteAndReadRef:
case AccessType.ReadAndWriteAndReadUnknown:
case AccessType.Write:
case AccessType.WriteRef:
{
bool reference = access == AccessType.WriteRef;
// Note that some work was done in Emit() !
// In cases 3, 4, 5 EmitAssign is not called
if (isMemberOf != null ||
(isMemberOf == null && (array is DirectStFldUse || array is IndirectStFldUse || array is ItemUse)))
{
// 2, 6, 7
chain.EmitSetArrayItem(indexTypeCode, index, reference);
chain.End();
}
else
{
// Note: The value which should be stored is already loaded on the evaluation stack.
// Push the destination array and index and call the operator
// 1: a_[x]_
Debug.Assert(array is SimpleVarUse);
chain.IsArrayItem = true;
chain.IsLastMember = true;
indexTypeCode = codeGenerator.EmitArrayKey(chain, index);
array.Emit(codeGenerator);
chain.EmitSetItem(indexTypeCode, index, reference);
// Store the changed variable into table of variables (do nothing in optimalized functions)
((SimpleVarUse)array).EmitLoadAddress_StoreBack(codeGenerator);
}
result = PhpTypeCode.Void;
break;
}
case AccessType.None:
// do nothing
result = PhpTypeCode.Void;
break;
case AccessType.Read:
// do nothing
result = PhpTypeCode.Object;
break;
case AccessType.ReadRef:
// Do nothing
result = PhpTypeCode.PhpReference;
break;
default:
Debug.Fail();
result = PhpTypeCode.Invalid;
break;
}
return result;
}
开发者ID:Ashod,项目名称:Phalanger,代码行数:73,代码来源:ItemUse.cs
示例18: EmitConversionToAmbiguousVararg
private void EmitConversionToAmbiguousVararg(int argIndex, Type/*!*/ formalParamType, LocalBuilder/*!*/ tmpStrictness,
PhpTypeCode argLocalTypeCode, LocalBuilder/*!*/ argLocal, LocalBuilder[] formals)
{
Debug.Assert(formalParamType.IsArray);
Type element_type = formalParamType.GetElementType();
Label success_label = il.DefineLabel();
// IF (overloadStrictness == ImplExactMatch) GOTO <success_label>
il.Ldloc(tmpStrictness);
il.LdcI4((int)ConversionStrictness.ImplExactMatch);
il.Emit(OpCodes.Beq, success_label);
// formal = new ELEMENT_TYPE[1] { CONVERT(stack, out strictness) };
EmitCreateParamsArray(element_type, formals[argIndex], 1);
il.Ldloc(formals[argIndex]);
il.LdcI4(0);
// reload the argument
il.Ldloc(argLocal);
bool ct_ok = EmitConvertToClr(il, argLocalTypeCode, element_type, tmpStrictness);
il.Stelem(element_type);
il.MarkLabel(success_label, true);
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:25,代码来源:ClrOverloadBuilder.cs
示例19: EmitNodeWrite
/// <summary>
/// Emits code to prepare an evaluation stack for storing a value into a variable.
/// Supports operators chaining. Store is finished by calling <see cref="EmitAssign"/>.
/// </summary>
/// <param name="codeGenerator"></param>
private PhpTypeCode EmitNodeWrite(CodeGenerator codeGenerator)
{
ChainBuilder chain = codeGenerator.ChainBuilder;
if (chain.IsArrayItem)
{
// 3: a_[x]_[v]
Debug.Assert(this.isMemberOf == null);
return chain.EmitEnsureItem(array, index, true);
}
// 1, 2, 4, 5, 6, 7
if (chain.IsMember)
{
// 4, 5
if (this.isMemberOf != null)
{
// 5: ...->a[]->...
// Store isMemberOf for lazy emit
chain.SetObjectForLazyEmit(this);
chain.IsArrayItem = true;
chain.IsLastMember = false;
}
else
{
// 4: a_[x]_->c->..., a[x]_[x]_->c->...
chain.IsArrayItem = true;
chain.IsLastMember = true;
}
PhpTypeCode result = chain.EmitEnsureItem(array, index, false);
chain.IsArrayItem = false;
return result;
}
// 1, 2, 6, 7
if (this.isMemberOf != null)
{
// 6, 7: ...->a[x]_[x]_
chain.Create();
chain.Begin();
// Store isMemberOf for lazy emit
chain.SetObjectForLazyEmit(this);
chain.IsArrayItem = true;
chain.IsLastMember = false;
chain.Lengthen(); // for own []
array.Emit(codeGenerator);
indexTypeCode = codeGenerator.EmitArrayKey(chain, index);
// Note that EmitAssign will finish the work (SetArrayItem or PhpArray.Add)
return PhpTypeCode.Unknown;
}
// 1, 2
Debug.Assert(this.isMemberOf == null);
if (array is ItemUse || array is DirectStFldUse || array is IndirectStFldUse /* ??? */)
{
// 2: a[]_[]_
chain.Create();
chain.Begin();
chain.IsArrayItem = true;
chain.IsLastMember = true;
array.Emit(codeGenerator);
indexTypeCode = codeGenerator.EmitArrayKey(chain, index);
// Note that further work will be done by EmitAssign (SetArrayItem or PhpArray.Add)
return PhpTypeCode.Unknown;
}
// 1: a_[x]_
// Do nothing now, let the work be done in EmitAssign()
return PhpTypeCode.Unknown;
}
开发者ID:Ashod,项目名称:Phalanger,代码行数:79,代码来源:ItemUse.cs
示例20: EmitConvertToClr
/// <summary>
/// Converts a PHP value to the given CLR type (the caller passes a <paramref name="strictnessLocal"/> that will
/// receive one of the <see cref="PHP.Core.ConvertToClr.ConversionStrictness"/> enumeration values that
/// describe the conversion result (the Failed value indicates that conversion was not successful).
/// </summary>
/// <returns><B>True</B> if it the conversion will surely succeed.</returns>
internal static bool EmitConvertToClr(ILEmitter/*!*/ il, PhpTypeCode typeCode,
Type/*!*/ formalType, LocalBuilder/*!*/ strictnessLocal)
{
Debug.Assert(strictnessLocal.LocalType == typeof(ConversionStrictness));
// preprocess the value according to the PHP type code
switch (typeCode)
{
case PhpTypeCode.PhpReference:
{
// dereference
il.Emit(OpCodes.Ldfld, Fields.PhpReference_Value);
typeCode = PhpTypeCode.Object;
break;
}
case PhpTypeCode.ObjectAddress:
{
// dereference
il.Emit(OpCodes.Ldind_Ref);
typeCode = PhpTypeCode.Object;
break;
}
case PhpTypeCode.LinqSource:
case PhpTypeCode.PhpRuntimeChain:
{
Debug.Fail();
return true;
}
}
// special treatment for generic parameters
if (formalType.IsGenericParameter)
{
EmitConvertToClrGeneric(il, formalType, strictnessLocal);
return false;
}
// convert CLR type
return EmitConvertObjectToClr(il, typeCode, formalType, strictnessLocal);
}
开发者ID:hansdude,项目名称:Phalanger,代码行数:48,代码来源:ClrOverloadBuilder.cs
注:本文中的PhpTypeCode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论