/// <summary> /// Creates new type context, flow context and flow state for the routine. /// </summary> public static FlowState CreateInitialState(SourceRoutineSymbol /*!*/ routine, FlowContext flowCtx = null) { Contract.ThrowIfNull(routine); // get or create typeCtx var typeCtx = routine.TypeRefContext; if (flowCtx == null) { // create FlowContext flowCtx = new FlowContext(typeCtx, routine); } // create FlowState var state = new FlowState(flowCtx); // handle input parameters type foreach (var p in routine.SourceParameters) { var local = state.GetLocalHandle(new VariableName(p.Name)); var ptype = p.GetResultType(typeCtx); state.SetLocalType(local, ptype); } // $this if (routine.GetPhpThisVariablePlace() != null) { InitThisVar(flowCtx, state); } // return(state); }
/// <summary> /// Creates new type context, flow context and flow state for the routine. /// </summary> public static FlowState CreateInitialState(SourceRoutineSymbol /*!*/ routine, FlowContext flowCtx = null) { Contract.ThrowIfNull(routine); // get or create typeCtx var typeCtx = routine.TypeRefContext; if (flowCtx == null) { // create FlowContext flowCtx = new FlowContext(typeCtx, routine); } // create FlowState var state = new FlowState(flowCtx); // handle input parameters type foreach (var p in routine.SourceParameters) { var local = state.GetLocalHandle(new VariableName(p.Name)); var ptype = p.GetResultType(typeCtx); if (p.IsNotNull) { // remove 'null' type from the mask, // it cannot be null ptype = typeCtx.WithoutNull(ptype); } else if (p.Type.IsReferenceType) // a reference type that can be null { ptype |= typeCtx.GetNullTypeMask(); } state.SetLocalType(local, ptype); if (p.Syntax.PassedByRef && !p.Syntax.IsVariadic) { state.MarkLocalByRef(local); } } // $this if (routine.GetPhpThisVariablePlace() != null) { InitThisVar(flowCtx, state); } // return(state); }
private static bool TryGetVariableHandle(BoundVariable boundvar, FlowState state, out VariableHandle varHandle) { if (boundvar.Name != null) // direct variable name { if (boundvar.VariableKind == VariableKind.LocalVariable || boundvar.VariableKind == VariableKind.Parameter) { varHandle = state.GetLocalHandle(boundvar.Name); return(true); } } // varHandle = default(VariableHandle); return(false); }
private static bool TryGetVariableHandle(IVariableReference boundvar, FlowState state, out VariableHandle varHandle) { if (boundvar is LocalVariableReference local && local.BoundName.IsDirect) // direct variable name { if (local.VariableKind == VariableKind.LocalVariable || local.VariableKind == VariableKind.Parameter || local.VariableKind == VariableKind.LocalTemporalVariable) { varHandle = state.GetLocalHandle(local.BoundName.NameValue); return(true); } } // varHandle = default(VariableHandle); return(false); }
/// <summary> /// Creates new type context, flow context and flow state for the routine. /// </summary> public static FlowState CreateInitialState(SourceRoutineSymbol /*!*/ routine, FlowContext flowCtx = null) { Contract.ThrowIfNull(routine); // get or create typeCtx var typeCtx = routine.TypeRefContext; // create or reuse FlowContext flowCtx ??= new FlowContext(typeCtx, routine); // pre-allocate locals map // https://github.com/peachpiecompiler/peachpie/issues/1002 foreach (var variable in routine.LocalsTable.Variables) { if (variable is Semantics.LocalVariableReference local && local.VariableKind == VariableKind.LocalVariable) { flowCtx.GetVarIndex(variable.BoundName.NameValue); } } // create FlowState var state = new FlowState(flowCtx); // populate input parameters type foreach (var p in routine.SourceParameters) { var local = state.GetLocalHandle(new VariableName(p.Name)); var ptype = p.GetResultType(typeCtx); state.SetLocalType(local, ptype); } // $this if (routine.GetPhpThisVariablePlace() != null) { InitThisVar(flowCtx, state); } // return(state); }
/// <summary> /// Creates new type context, flow context and flow state for the routine. /// </summary> public static FlowState CreateInitialState(SourceRoutineSymbol /*!*/ routine) { Contract.ThrowIfNull(routine); // create typeCtx var typeCtx = routine.TypeRefContext; // create FlowContext var flowCtx = new FlowContext(typeCtx, routine); // create FlowState var state = new FlowState(flowCtx); // handle input parameters type var parameters = routine.SourceParameters; foreach (var p in parameters) { var local = state.GetLocalHandle(new VariableName(p.Name)); state.SetLocalType(local, p.GetResultType(typeCtx)); if (p.Syntax.PassedByRef && !p.Syntax.IsVariadic) { state.MarkLocalByRef(local); } } // $this if (routine.GetPhpThisVariablePlace() != null) { InitThisVar(flowCtx, state); } // return(state); }