本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator类的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator类的具体用法?C# CodeGenerator怎么用?C# CodeGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeGenerator类属于Pchp.CodeAnalysis.CodeGen命名空间,在下文中一共展示了CodeGenerator类的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: Emit
internal override void Emit(CodeGenerator cg)
{
cg.EmitSequencePoint(this.PhpSyntax);
//
var t = cg.Emit(Thrown);
if (t.IsReferenceType)
{
if (!t.IsEqualToOrDerivedFrom(cg.CoreTypes.Exception))
{
throw new NotImplementedException(); // Wrap to System.Exception
}
}
else
{
//if (t == cg.CoreTypes.PhpValue)
//{
//}
throw new NotImplementedException(); // Wrap to System.Exception
}
// throw <stack>;
cg.Builder.EmitThrow(false);
}
示例3: EmitInit
internal override void EmitInit(CodeGenerator cg)
{
if (cg.HasUnoptimizedLocals)
{
return;
}
// declare variable in global scope
var il = cg.Builder;
var def = il.LocalSlotManager.DeclareLocal(
(Cci.ITypeReference)_symbol.Type, _symbol as ILocalSymbolInternal,
this.Name, SynthesizedLocalKind.UserDefined,
LocalDebugId.None, 0, LocalSlotConstraints.None, false, default(ImmutableArray<TypedConstant>), false);
_place = new LocalPlace(def);
il.AddLocalToScope(def);
//
if (_symbol is SynthesizedLocalSymbol)
return;
// Initialize local variable with void.
// This is mandatory since even assignments reads the target value to assign properly to PhpAlias.
// TODO: Once analysis tells us, the target cannot be alias, this step won't be necessary.
// TODO: only if the local will be used uninitialized
cg.EmitInitializePlace(_place);
}
示例4: Construct
public void Construct(NamedTypeSymbol functype, Action<CodeGenerator> binder_builder)
{
var callsitetype = _factory.CallSite_T.Construct(functype);
// TODO: check if it wasn't constructed already
_target.SetContainingType((SubstitutedNamedTypeSymbol)callsitetype);
_fld.SetFieldType(callsitetype);
_callsite_create = (MethodSymbol)_factory.CallSite_T_Create.SymbolAsMember(callsitetype);
// create callsite
// static .cctor {
var cctor = _factory.CctorBuilder;
// fld = CallSite<T>.Create( <BINDER> )
var fldPlace = this.Place;
fldPlace.EmitStorePrepare(cctor);
var cctor_cg = new CodeGenerator(cctor, _factory._cg.Module, _factory._cg.Diagnostics, _factory._cg.DeclaringCompilation.Options.OptimizationLevel, false, _factory._container, null, null);
binder_builder(cctor_cg);
cctor.EmitCall(_factory._cg.Module, _factory._cg.Diagnostics, ILOpCode.Call, this.CallSite_Create);
fldPlace.EmitStore(cctor);
// }
}
示例5: EmitInit
void EmitInit(Emit.PEModuleBuilder module)
{
// void Init(Context)
var tt = DeclaringCompilation.CoreTypes;
var diagnostic = DiagnosticBag.GetInstance();
// override IStaticInit.Init(Context) { .. }
var initMethod = new SynthesizedMethodSymbol(this, "Init", false, true, tt.Void, Accessibility.Public);
initMethod.SetParameters(new SynthesizedParameterSymbol(initMethod, tt.Context, 0, RefKind.None, "ctx"));
var body = MethodGenerator.GenerateMethodBody(module, initMethod, (il) =>
{
var cg = new CodeGenerator(il, module, diagnostic, OptimizationLevel.Release, false, this, new ArgPlace(tt.Context, 1), new ArgPlace(this, 0));
foreach (var fld in this.Fields)
{
if (fld.RequiresContext)
{
fld.EmitInit(cg);
}
}
//
il.EmitRet(true);
},
null, diagnostic, false);
module.SetMethodBody(initMethod, body);
module.SynthesizedManager.AddMethod(this, initMethod);
}
示例6: Emit
internal virtual void Emit(CodeGenerator cg)
{
// emit contained statements
if (_statements.Count != 0)
{
_statements.ForEach(cg.Generate);
}
//
cg.Generate(this.NextEdge);
}
示例7: GenerateMethodBody
internal static MethodBody GenerateMethodBody(
PEModuleBuilder moduleBuilder,
SourceRoutineSymbol routine,
int methodOrdinal,
//ImmutableArray<LambdaDebugInfo> lambdaDebugInfo,
//ImmutableArray<ClosureDebugInfo> closureDebugInfo,
//StateMachineTypeSymbol stateMachineTypeOpt,
VariableSlotAllocator variableSlotAllocatorOpt,
DiagnosticBag diagnostics,
//ImportChain importChainOpt,
bool emittingPdb)
{
return GenerateMethodBody(moduleBuilder, routine, (builder) =>
{
DiagnosticBag diagnosticsForThisMethod = DiagnosticBag.GetInstance();
var optimization = moduleBuilder.Compilation.Options.OptimizationLevel;
var codeGen = new CodeGenerator(routine, builder, moduleBuilder, diagnosticsForThisMethod, optimization, emittingPdb);
//if (diagnosticsForThisMethod.HasAnyErrors())
//{
// // we are done here. Since there were errors we should not emit anything.
// return null;
//}
// We need to save additional debugging information for MoveNext of an async state machine.
//var stateMachineMethod = method as SynthesizedStateMachineMethod;
//bool isStateMachineMoveNextMethod = stateMachineMethod != null && method.Name == WellKnownMemberNames.MoveNextMethodName;
//if (isStateMachineMoveNextMethod && stateMachineMethod.StateMachineType.KickoffMethod.IsAsync)
//{
// int asyncCatchHandlerOffset;
// ImmutableArray<int> asyncYieldPoints;
// ImmutableArray<int> asyncResumePoints;
// codeGen.Generate(out asyncCatchHandlerOffset, out asyncYieldPoints, out asyncResumePoints);
// var kickoffMethod = stateMachineMethod.StateMachineType.KickoffMethod;
// // The exception handler IL offset is used by the debugger to treat exceptions caught by the marked catch block as "user unhandled".
// // This is important for async void because async void exceptions generally result in the process being terminated,
// // but without anything useful on the call stack. Async Task methods on the other hand return exceptions as the result of the Task.
// // So it is undesirable to consider these exceptions "user unhandled" since there may well be user code that is awaiting the task.
// // This is a heuristic since it's possible that there is no user code awaiting the task.
// asyncDebugInfo = new Cci.AsyncMethodBodyDebugInfo(kickoffMethod, kickoffMethod.ReturnsVoid ? asyncCatchHandlerOffset : -1, asyncYieldPoints, asyncResumePoints);
//}
//else
{
codeGen.Generate();
}
}, variableSlotAllocatorOpt, diagnostics, emittingPdb);
}
示例8: EmitLoadStatics
/// <summary>
/// Emits load of statics holder.
/// </summary>
internal TypeSymbol EmitLoadStatics(CodeGenerator cg)
{
var statics = TryGetStatics();
if (statics != null && statics.GetMembers().OfType<IFieldSymbol>().Any())
{
// Template: <ctx>.GetStatics<_statics>()
cg.EmitLoadContext();
return cg.EmitCall(ILOpCode.Callvirt, cg.CoreMethods.Context.GetStatic_T.Symbol.Construct(statics))
.Expect(statics);
}
return null;
}
示例9: EmitFieldsCctor
void EmitFieldsCctor(Emit.PEModuleBuilder module)
{
var sflds = GetMembers().OfType<SourceFieldSymbol>().Where(f => f.IsStatic && !f.RequiresHolder).ToList();
if (sflds.Count != 0)
{
// emit initialization of app static fields
// note, their initializers do not have Context available, since they are not bound to a Context
var cctor = module.GetStaticCtorBuilder(this);
var cg = new CodeGenerator(cctor, module, DiagnosticBag.GetInstance(), OptimizationLevel.Release, false, this, null, null);
foreach (var f in sflds)
{
f.EmitInit(cg);
}
}
}
示例10: 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);
}
}
示例11: EmitLoadTypeInfo
/// <summary>
/// Emits load of <c>PhpTypeInfo</c>.
/// </summary>
/// <param name="cg">Code generator instance.</param>
/// <param name="throwOnError">Emits PHP error in case type is not declared.</param>
/// <remarks>Emits <c>NULL</c> in case type is not declared.</remarks>
internal void EmitLoadTypeInfo(CodeGenerator cg, bool throwOnError = false)
{
Debug.Assert(cg != null);
Debug.Assert(throwOnError == false, "Not Implemented!"); // TODO: if (throwOnError) { if (DUP == null) PhpException.TypeNotDeclared(<typename>)
if (this.ResolvedType != null)
{
// CALL GetPhpTypeInfo<T>()
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Dynamic.GetPhpTypeInfo_T.Symbol.Construct(this.ResolvedType));
}
else
{
// CALL <ctx>.GetDeclaredType(<typename>)
cg.EmitLoadContext();
this.EmitClassName(cg);
cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Context.GetDeclaredType_string);
}
}
示例12: EmitCtors
internal void EmitCtors(Emit.PEModuleBuilder module)
{
bool requiresInit = false;
// .ctor()
var tt = DeclaringCompilation.CoreTypes;
var diagnostic = DiagnosticBag.GetInstance();
var ctor = new SynthesizedCtorSymbol(this);
var body = MethodGenerator.GenerateMethodBody(module, ctor, (il) =>
{
var cg = new CodeGenerator(il, module, diagnostic, OptimizationLevel.Release, false, this, null, new ArgPlace(this, 0));
foreach (var fld in this.Fields)
{
if (fld.RequiresContext)
{
requiresInit = true;
}
else
{
fld.EmitInit(cg);
}
}
//
il.EmitRet(true);
},
null, diagnostic, false);
module.SetMethodBody(ctor, body);
module.SynthesizedManager.AddMethod(this, ctor);
//
if (requiresInit)
{
EmitInit(module);
}
}
示例13: 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);
}
}
}
示例14: EmitEquality
/// <summary>
/// Emits check for values equality.
/// Lefts <c>bool</c> on top of evaluation stack.
/// </summary>
TypeSymbol EmitEquality(CodeGenerator cg)
{
// x == y
return EmitEquality(cg, Left, Right);
}
示例15: 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;
}