C# Class Pchp.CodeAnalysis.CodeGen.CodeGenerator

Show file Open project: iolevel/peachpie Class Usage Examples

Public Methods

Method Description
Emit ( BoundExpression expr ) : TypeSymbol
EmitBox ( TypeSymbol valuetype ) : void
EmitCallMain ( MethodSymbol mainmethod ) : TypeSymbol

Emits call to main method.

EmitCallerRuntimeTypeHandle ( ) : void
EmitConvert ( BoundExpression expr, TypeSymbol to ) : void
EmitConvert ( TypeSymbol from, TypeRefMask fromHint, TypeSymbol to ) : void

Emits conversion from one CLR type to another using PHP conventions.

EmitConvertToBool ( BoundExpression expr, bool negation = false ) : void
EmitConvertToBool ( TypeSymbol from, TypeRefMask fromHint, bool negation = false ) : void
EmitConvertToDouble ( TypeSymbol from, TypeRefMask fromHint ) : TypeSymbol
EmitConvertToInt ( TypeSymbol from, TypeRefMask fromHint ) : void
EmitConvertToIntStringKey ( TypeSymbol from, TypeRefMask fromHint ) : void
EmitConvertToLong ( TypeSymbol from, TypeRefMask fromHint ) : void
EmitConvertToPhpArray ( TypeSymbol from, TypeRefMask fromHint ) : void

Emits conversion to PhpArray.

EmitConvertToPhpNumber ( TypeSymbol from, TypeRefMask fromHint ) : void
EmitConvertToPhpString ( TypeSymbol from, TypeRefMask fromHint ) : void

Emits conversion to Pchp.Core.PhpString (aka writable string).

EmitConvertToPhpValue ( TypeSymbol from, TypeRefMask fromHint ) : TypeSymbol
EmitConvertToPhpValue ( TypeSymbol from, TypeRefMask fromHint, ILBuilder il, Emit module, DiagnosticBag diagnostic ) : TypeSymbol
EmitConvertToString ( TypeSymbol from, TypeRefMask fromHint ) : void

Emits conversion to System.String.

EmitDebugAssert ( string messageOpt = null ) : void

Emits Debug.Assert([stack]).

EmitDebugAssertNotNull ( IPlace place, string messageOpt = null ) : void

Emits Debug.Assert([place]) in debug compile mode.

EmitDeclareFunction ( SourceFunctionSymbol f ) : void

Emits declaring function into the context.

EmitDeclareType ( SourceTypeSymbol t ) : void

Emits declaring type into the context.

EmitEcho ( BoundExpression expr ) : void
EmitFieldAddress ( FieldSymbol fld ) : void

Loads field address on top of evaluation stack.

EmitIntStringKey ( BoundExpression expr ) : void
EmitIntStringKey ( int key ) : void
EmitLoadArgument ( ParameterSymbol targetp, BoundExpression expr, List writebacks ) : void

Loads argument

EmitLoadConstant ( object value, TypeSymbol targetOpt = null ) : TypeSymbol
EmitLoadContext ( ) : TypeSymbol

Emits context onto the evaluation stack.

EmitLoadDefault ( TypeSymbol type, TypeRefMask typemask ) : void
EmitLoadDefaultOfValueType ( TypeSymbol valuetype ) : void

Emits default(valuetype). Handles special types with a default ctor.

EmitLoadToken ( MethodSymbol method, Microsoft.CodeAnalysis.SyntaxNode syntaxNodeOpt ) : TypeSymbol

Loads RuntimeMethodHandle of given method.

EmitLoadToken ( TypeSymbol type, Microsoft.CodeAnalysis.SyntaxNode syntaxNodeOpt ) : TypeSymbol

Loads RuntimeTypeHandle of given type.

EmitLogicNegation ( ) : void

Emits "!= 0" operation. This method expects I4 value on top of evaluation stack.

EmitNotNull ( IPlace place ) : void

Emits place != null expression.

EmitOpCode ( ILOpCode code ) : void
EmitParameterDefaultValue ( ParameterSymbol targetp ) : void

Emits default value of given parameter. Puts value of target parameter's type.

EmitPop ( TypeSymbol type ) : void
EmitRet ( TypeSymbol stack ) : void

Emits .ret instruction with sequence point at closing brace.

EmitRetDefault ( ) : void
EmitThis ( ) : TypeSymbol

Emits reference to this.

EmitThisOrNull ( ) : TypeSymbol
EmitUnset ( BoundReferenceExpression expr ) : void
EmitWithDisabledErrorReporting ( BoundExpression expr ) : TypeSymbol

Emits the expression decorated with error reporting disabling routine.

Emit_NewArray ( TypeSymbol elementType, BoundExpression values ) : void
Emit_PhpAlias_GetValue ( ) : TypeSymbol

Emits load of PhpAlias.Value, expecting PhpAlias on top of evaluation stack, pushing PhpValue on top of the stack.

Emit_PhpAlias_GetValueRef ( ) : void

Emits load of PhpAlias.Value, expecting PhpAlias on top of evaluation stack, pushing PhpValue on top of the stack.

Emit_PhpAlias_SetValue ( ) : void

Emits store to PhpAlias.Value, expecting PhpAlias and PhpValue on top of evaluation stack.

Emit_PhpValue_MakeAlias ( ) : TypeSymbol

Emits new PhpAlias, expecting PhpValue on top of the evaluation stack.

Emit_PhpValue_Null ( ) : TypeSymbol

Emits load of PhpValue representing null.

Emit_PhpValue_Void ( ) : TypeSymbol

Emits load of PhpValue representing void.

GetTemporaryLocal ( TypeSymbol type ) : Microsoft.CodeAnalysis.CodeGen.LocalDefinition

Returns a LocalDefinition of a temporary local variable of a specified TypeSymbol.

If a LocalDefinition of the given TypeSymbol has already been declared and returned to the pool, this local is reused. Otherwise, a new local is declared. Use this method to obtain a short-lived temporary local. Return the local to the pool of locals available for reuse by calling ReturnTemporaryLocal.

GetTemporaryLocal ( TypeSymbol type, bool immediateReturn ) : Microsoft.CodeAnalysis.CodeGen.LocalDefinition

Returns a LocalDefinition of a temporary local variable of a specified TypeSymbol.

If a LocalDefinition of the given TypeSymbol has already been declared and returned to the pool, this local is reused. Otherwise, a new local is declared. Use this method to obtain a short-lived temporary local. If immediateReturn is false, return the local to the pool of locals available for reuse by calling ReturnTemporaryLocal.

ReturnTemporaryLocal ( Microsoft.CodeAnalysis.CodeGen.LocalDefinition definition ) : void

Returns a LocalDefinition previously obtained from GetTemporaryLocal(TypeSymbol,bool) to the pool of locals available for reuse.

Private Methods

Method Description
EmitCall ( ILOpCode code, MethodSymbol method ) : TypeSymbol

Emits call to given method.

EmitCall ( ILOpCode code, MethodSymbol method, BoundExpression thisExpr, ImmutableArray arguments ) : TypeSymbol
EmitCastClass ( TypeSymbol type ) : void
EmitCastClass ( TypeSymbol from, TypeSymbol to ) : void
EmitConvertIntToLong ( TypeSymbol stack ) : TypeSymbol

In case there is Int32 or bool on the top of evaluation stack, converts it to Int64.

EmitConvertNumberToDouble ( BoundExpression expr ) : TypeSymbol

In case there is Int32 or bool or PhpNumber on the top of evaluation stack, converts it to double.

EmitConvertToClass ( TypeSymbol from, TypeRefMask fromHint, TypeSymbol to ) : void

Emits conversion to a class object.

EmitConvertToEnum ( TypeSymbol from, NamedTypeSymbol to ) : void
EmitGetProperty ( IPlace holder, PropertySymbol prop ) : TypeSymbol
EmitInitializePlace ( IPlace place ) : void

Initializes place with a default value. This applies to structs without default ctor that won't work properly when uninitialized.

EmitPhpNumberAddr ( ) : void

Copies PhpNumber into a temp variable and loads its address.

EmitPhpValueAddr ( ) : void

Copies PhpValue into a temp variable and loads its address.

EmitSequencePoint ( LangElement element ) : void
EmitSequencePoint ( Span span ) : void
EmitSpecialize ( BoundExpression expr ) : TypeSymbol

If possible, based on type analysis, unwraps more specific type from a value currently on stack without a runtime type check.

EmitSpecialize ( TypeSymbol stack, TypeRefMask tmask ) : TypeSymbol

If possible, based on type analysis, unwraps more specific type from a value currently on stack without a runtime type check.

EmitStructAddr ( TypeSymbol t ) : void

Copies a value type from the top of evaluation stack into a temporary variable and loads its address.

EmitSymbolToken ( FieldSymbol symbol, Microsoft.CodeAnalysis.SyntaxNode syntaxNode ) : void
EmitSymbolToken ( TypeSymbol symbol, Microsoft.CodeAnalysis.SyntaxNode syntaxNode ) : void
EmitThisCall ( MethodSymbol target, MethodSymbol thismethod ) : TypeSymbol

Emits .call to target assuming it takes the same arguments as passed to the caller method (thismethod).

Emit_PhpValue_Void ( ILBuilder il, Emit module, DiagnosticBag diagnostic ) : TypeSymbol

Emits load of PhpValue representing void.

IsArrayOnly ( TypeRefMask tmask ) : bool

Gets value indicating the given type represents only PHP Array.

IsBooleanOnly ( TypeRefMask tmask ) : bool

Gets value indicating the given type represents a long and nothing else.

IsClassOnly ( TypeRefMask tmask ) : bool

Gets value indicating the given type represents only class types.

IsDoubleOnly ( TypeRefMask tmask ) : bool

Gets value indicating the given type represents a double and nothing else.

IsLongOnly ( TypeRefMask tmask ) : bool

Gets value indicating the given type represents a long and nothing else.

IsReadonlyStringOnly ( TypeRefMask tmask ) : bool

Gets value indicating the given type represents UTF16 readonly string and nothing else.

PlaceOrNull ( BoundExpression expr ) : IPlace

If possible, gets IPlace representing given expression (in case of a field or variable).

TryEmitVariableSpecialize ( BoundExpression expr ) : TypeSymbol

If possible, based on type analysis, unwraps most specific type from give variable without a runtime type check.

TryEmitVariableSpecialize ( IPlace place, TypeRefMask tmask ) : TypeSymbol

If possible, based on type analysis, unwraps most specific type from give variable without a runtime type check.

Method Details

Emit() public method

public Emit ( BoundExpression expr ) : TypeSymbol
expr Pchp.CodeAnalysis.Semantics.BoundExpression
return TypeSymbol

EmitBox() public method

public EmitBox ( TypeSymbol valuetype ) : void
valuetype TypeSymbol
return void

EmitCallMain() public method

Emits call to main method.
public EmitCallMain ( MethodSymbol mainmethod ) : TypeSymbol
mainmethod Pchp.CodeAnalysis.Symbols.MethodSymbol Static Main method representing the script global code.
return TypeSymbol

EmitCallerRuntimeTypeHandle() public method

public EmitCallerRuntimeTypeHandle ( ) : void
return void

EmitConvert() public method

public EmitConvert ( BoundExpression expr, TypeSymbol to ) : void
expr Pchp.CodeAnalysis.Semantics.BoundExpression
to TypeSymbol
return void

EmitConvert() public method

Emits conversion from one CLR type to another using PHP conventions.
public EmitConvert ( TypeSymbol from, TypeRefMask fromHint, TypeSymbol to ) : void
from TypeSymbol Type of value on top of evaluation stack.
fromHint TypeRefMask Type hint in case of a multityple type choices (like PhpValue or PhpNumber or PhpAlias).
to TypeSymbol Target CLR type.
return void

EmitConvertToBool() public method

public EmitConvertToBool ( BoundExpression expr, bool negation = false ) : void
expr Pchp.CodeAnalysis.Semantics.BoundExpression
negation bool
return void

EmitConvertToBool() public method

public EmitConvertToBool ( TypeSymbol from, TypeRefMask fromHint, bool negation = false ) : void
from TypeSymbol
fromHint TypeRefMask
negation bool
return void

EmitConvertToDouble() public method

public EmitConvertToDouble ( TypeSymbol from, TypeRefMask fromHint ) : TypeSymbol
from TypeSymbol
fromHint TypeRefMask
return TypeSymbol

EmitConvertToInt() public method

public EmitConvertToInt ( TypeSymbol from, TypeRefMask fromHint ) : void
from TypeSymbol
fromHint TypeRefMask
return void

EmitConvertToIntStringKey() public method

public EmitConvertToIntStringKey ( TypeSymbol from, TypeRefMask fromHint ) : void
from TypeSymbol
fromHint TypeRefMask
return void

EmitConvertToLong() public method

public EmitConvertToLong ( TypeSymbol from, TypeRefMask fromHint ) : void
from TypeSymbol
fromHint TypeRefMask
return void

EmitConvertToPhpArray() public method

Emits conversion to PhpArray.
public EmitConvertToPhpArray ( TypeSymbol from, TypeRefMask fromHint ) : void
from TypeSymbol
fromHint TypeRefMask
return void

EmitConvertToPhpNumber() public method

public EmitConvertToPhpNumber ( TypeSymbol from, TypeRefMask fromHint ) : void
from TypeSymbol
fromHint TypeRefMask
return void

EmitConvertToPhpString() public method

Emits conversion to Pchp.Core.PhpString (aka writable string).
public EmitConvertToPhpString ( TypeSymbol from, TypeRefMask fromHint ) : void
from TypeSymbol
fromHint TypeRefMask
return void

EmitConvertToPhpValue() public method

public EmitConvertToPhpValue ( TypeSymbol from, TypeRefMask fromHint ) : TypeSymbol
from TypeSymbol
fromHint TypeRefMask
return TypeSymbol

EmitConvertToPhpValue() public static method

public static EmitConvertToPhpValue ( TypeSymbol from, TypeRefMask fromHint, ILBuilder il, Emit module, DiagnosticBag diagnostic ) : TypeSymbol
from TypeSymbol
fromHint TypeRefMask
il Microsoft.CodeAnalysis.CodeGen.ILBuilder
module Emit
diagnostic DiagnosticBag
return TypeSymbol

EmitConvertToString() public method

Emits conversion to System.String.
public EmitConvertToString ( TypeSymbol from, TypeRefMask fromHint ) : void
from TypeSymbol
fromHint TypeRefMask
return void

EmitDebugAssert() public method

Emits Debug.Assert([stack]).
public EmitDebugAssert ( string messageOpt = null ) : void
messageOpt string Optional second argument for assert.
return void

EmitDebugAssertNotNull() public method

Emits Debug.Assert([place]) in debug compile mode.
public EmitDebugAssertNotNull ( IPlace place, string messageOpt = null ) : void
place IPlace The variable to emit assertion for.
messageOpt string Optional second argument for assert.
return void

EmitDeclareFunction() public method

Emits declaring function into the context.
public EmitDeclareFunction ( SourceFunctionSymbol f ) : void
f Pchp.CodeAnalysis.Symbols.SourceFunctionSymbol
return void

EmitDeclareType() public method

Emits declaring type into the context.
public EmitDeclareType ( SourceTypeSymbol t ) : void
t Pchp.CodeAnalysis.Symbols.SourceTypeSymbol
return void

EmitEcho() public method

public EmitEcho ( BoundExpression expr ) : void
expr Pchp.CodeAnalysis.Semantics.BoundExpression
return void

EmitFieldAddress() public method

Loads field address on top of evaluation stack.
public EmitFieldAddress ( FieldSymbol fld ) : void
fld Pchp.CodeAnalysis.Symbols.FieldSymbol
return void

EmitIntStringKey() public method

public EmitIntStringKey ( BoundExpression expr ) : void
expr Pchp.CodeAnalysis.Semantics.BoundExpression
return void

EmitIntStringKey() public method

public EmitIntStringKey ( int key ) : void
key int
return void

EmitLoadArgument() public method

Loads argument
public EmitLoadArgument ( ParameterSymbol targetp, BoundExpression expr, List writebacks ) : void
targetp Pchp.CodeAnalysis.Symbols.ParameterSymbol
expr Pchp.CodeAnalysis.Semantics.BoundExpression
writebacks List
return void

EmitLoadConstant() public method

public EmitLoadConstant ( object value, TypeSymbol targetOpt = null ) : TypeSymbol
value object
targetOpt TypeSymbol
return TypeSymbol

EmitLoadContext() public method

Emits context onto the evaluation stack.
public EmitLoadContext ( ) : TypeSymbol
return TypeSymbol

EmitLoadDefault() public method

public EmitLoadDefault ( TypeSymbol type, TypeRefMask typemask ) : void
type TypeSymbol
typemask TypeRefMask
return void

EmitLoadDefaultOfValueType() public method

Emits default(valuetype). Handles special types with a default ctor.
public EmitLoadDefaultOfValueType ( TypeSymbol valuetype ) : void
valuetype TypeSymbol
return void

EmitLoadToken() public method

Loads RuntimeMethodHandle of given method.
public EmitLoadToken ( MethodSymbol method, Microsoft.CodeAnalysis.SyntaxNode syntaxNodeOpt ) : TypeSymbol
method Pchp.CodeAnalysis.Symbols.MethodSymbol
syntaxNodeOpt Microsoft.CodeAnalysis.SyntaxNode
return TypeSymbol

EmitLoadToken() public method

Loads RuntimeTypeHandle of given type.
public EmitLoadToken ( TypeSymbol type, Microsoft.CodeAnalysis.SyntaxNode syntaxNodeOpt ) : TypeSymbol
type TypeSymbol
syntaxNodeOpt Microsoft.CodeAnalysis.SyntaxNode
return TypeSymbol

EmitLogicNegation() public method

Emits "!= 0" operation. This method expects I4 value on top of evaluation stack.
public EmitLogicNegation ( ) : void
return void

EmitNotNull() public method

Emits place != null expression.
public EmitNotNull ( IPlace place ) : void
place IPlace
return void

EmitOpCode() public method

public EmitOpCode ( ILOpCode code ) : void
code ILOpCode
return void

EmitParameterDefaultValue() public method

Emits default value of given parameter. Puts value of target parameter's type.
public EmitParameterDefaultValue ( ParameterSymbol targetp ) : void
targetp Pchp.CodeAnalysis.Symbols.ParameterSymbol Parameter to emit its default value.
return void

EmitPop() public method

public EmitPop ( TypeSymbol type ) : void
type TypeSymbol
return void

EmitRet() public method

Emits .ret instruction with sequence point at closing brace.
public EmitRet ( TypeSymbol stack ) : void
stack TypeSymbol
return void

EmitRetDefault() public method

public EmitRetDefault ( ) : void
return void

EmitThis() public method

Emits reference to this.
public EmitThis ( ) : TypeSymbol
return TypeSymbol

EmitThisOrNull() public method

public EmitThisOrNull ( ) : TypeSymbol
return TypeSymbol

EmitUnset() public method

public EmitUnset ( BoundReferenceExpression expr ) : void
expr Pchp.CodeAnalysis.Semantics.BoundReferenceExpression
return void

EmitWithDisabledErrorReporting() public method

Emits the expression decorated with error reporting disabling routine.
public EmitWithDisabledErrorReporting ( BoundExpression expr ) : TypeSymbol
expr Pchp.CodeAnalysis.Semantics.BoundExpression
return TypeSymbol

Emit_NewArray() public method

public Emit_NewArray ( TypeSymbol elementType, BoundExpression values ) : void
elementType TypeSymbol
values Pchp.CodeAnalysis.Semantics.BoundExpression
return void

Emit_PhpAlias_GetValue() public method

Emits load of PhpAlias.Value, expecting PhpAlias on top of evaluation stack, pushing PhpValue on top of the stack.
public Emit_PhpAlias_GetValue ( ) : TypeSymbol
return TypeSymbol

Emit_PhpAlias_GetValueRef() public method

Emits load of PhpAlias.Value, expecting PhpAlias on top of evaluation stack, pushing PhpValue on top of the stack.
public Emit_PhpAlias_GetValueRef ( ) : void
return void

Emit_PhpAlias_SetValue() public method

Emits store to PhpAlias.Value, expecting PhpAlias and PhpValue on top of evaluation stack.
public Emit_PhpAlias_SetValue ( ) : void
return void

Emit_PhpValue_MakeAlias() public method

Emits new PhpAlias, expecting PhpValue on top of the evaluation stack.
public Emit_PhpValue_MakeAlias ( ) : TypeSymbol
return TypeSymbol

Emit_PhpValue_Null() public method

Emits load of PhpValue representing null.
public Emit_PhpValue_Null ( ) : TypeSymbol
return TypeSymbol

Emit_PhpValue_Void() public method

Emits load of PhpValue representing void.
public Emit_PhpValue_Void ( ) : TypeSymbol
return TypeSymbol

GetTemporaryLocal() public method

Returns a LocalDefinition of a temporary local variable of a specified TypeSymbol.
If a LocalDefinition of the given TypeSymbol has already been declared and returned to the pool, this local is reused. Otherwise, a new local is declared. Use this method to obtain a short-lived temporary local. Return the local to the pool of locals available for reuse by calling ReturnTemporaryLocal.
public GetTemporaryLocal ( TypeSymbol type ) : Microsoft.CodeAnalysis.CodeGen.LocalDefinition
type TypeSymbol The requested of the local.
return Microsoft.CodeAnalysis.CodeGen.LocalDefinition

GetTemporaryLocal() public method

Returns a LocalDefinition of a temporary local variable of a specified TypeSymbol.
If a LocalDefinition of the given TypeSymbol has already been declared and returned to the pool, this local is reused. Otherwise, a new local is declared. Use this method to obtain a short-lived temporary local. If immediateReturn is false, return the local to the pool of locals available for reuse by calling ReturnTemporaryLocal.
public GetTemporaryLocal ( TypeSymbol type, bool immediateReturn ) : Microsoft.CodeAnalysis.CodeGen.LocalDefinition
type TypeSymbol The requested of the local.
immediateReturn bool True to immediately return the local builder to the pool of locals /// available for reuse (no need to call ).
return Microsoft.CodeAnalysis.CodeGen.LocalDefinition

ReturnTemporaryLocal() public method

Returns a LocalDefinition previously obtained from GetTemporaryLocal(TypeSymbol,bool) to the pool of locals available for reuse.
public ReturnTemporaryLocal ( Microsoft.CodeAnalysis.CodeGen.LocalDefinition definition ) : void
definition Microsoft.CodeAnalysis.CodeGen.LocalDefinition The to return to the pool.
return void