Esempio n. 1
0
            public override Evaluation EvaluatePriorAnalysis(BinaryEx node, CompilationSourceUnit sourceUnit)
            {
                Evaluation left_eval  = node.LeftExpr.EvaluatePriorAnalysis(sourceUnit);
                Evaluation right_eval = node.RightExpr.EvaluatePriorAnalysis(sourceUnit);

                return(Evaluation.ReadOnlyEvaluate(node, left_eval, right_eval));
            }
Esempio n. 2
0
            public override Evaluation EvaluatePriorAnalysis(T node, CompilationSourceUnit sourceUnit)
            {
                var className = node.ClassName;

                if (!string.IsNullOrEmpty(className.QualifiedName.Name.Value))
                {
                    constant = sourceUnit.TryResolveClassConstantGlobally(className, node.Name);
                }

                return((constant != null && constant.HasValue) ? new Evaluation(node, constant.Value) : new Evaluation(node));
            }
Esempio n. 3
0
		/// <summary>
		/// Called when a <see cref="PHP.Core.AST.GlobalCode"/> AST node is entered during the emit phase.
		/// </summary>
		public void EnterGlobalCodeDeclaration(VariablesTable variablesTable,
            Dictionary<VariableName, Statement> labels, CompilationSourceUnit/*!*/ sourceUnit)
		{
			CompilerLocationStack.GlobalCodeContext gc_context = new CompilerLocationStack.GlobalCodeContext();

			// no need to backup current source unit as it is no longer needed:
			this.sourceUnit = sourceUnit;

			// set whether access to variables should be generated via locals or table
			gc_context.OptimizedLocals = this.OptimizedLocals;
			this.OptimizedLocals = false;

			// global code returns object
			gc_context.ReturnsPhpReference = this.ReturnsPhpReference;
			this.ReturnsPhpReference = false;

            // CallSites
            Debug.Assert(this.callSites == null, "Unclosed CallSite!");
            this.callSites = new CallSitesBuilder(
                sourceUnit.CompilationUnit.Module.GlobalType.RealModuleBuilder,
                sourceUnit.SourceFile.RelativePath.ToString(),
                null/*Unknown at compile time*/);

			// set ILEmitter for global code
			gc_context.IL = il;
			il = CompilationUnit.ModuleBuilder.CreateGlobalCodeEmitter();

			// set current variables table (at codeGenerator)
			gc_context.CurrentVariablesTable = currentVariablesTable;
			currentVariablesTable = variablesTable;

			// set current labels table (at codeGenerator)
			gc_context.CurrentLabels = currentLabels;
			currentLabels = labels;

			// set OpCode for loading hashtable with variables at runtime
			gc_context.RTVariablesTablePlace = RTVariablesTablePlace;
			RTVariablesTablePlace = new IndexedPlace(PlaceHolder.Argument, 1);

			// set Script Context place
			gc_context.ScriptContextPlace = ScriptContextPlace;
			ScriptContextPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgContext);

			// set Class Context place
			gc_context.ClassContextPlace = TypeContextPlace;
			TypeContextPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgIncluder);

			// set Self place
			gc_context.SelfPlace = SelfPlace;
			SelfPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgSelf);

            // set late static bind place
            gc_context.LateStaticBindTypePlace = LateStaticBindTypePlace;
            LateStaticBindTypePlace = null;

			// set Result place and return label
			gc_context.ResultPlace = ResultPlace;
			gc_context.ReturnLabel = ReturnLabel;
			ResultPlace = null;

			// set exception block nesting:
			gc_context.ExceptionBlockNestingLevel = ExceptionBlockNestingLevel;
			ExceptionBlockNestingLevel = 0;

			locationStack.PushGlobalCode(gc_context);
		}
Esempio n. 4
0
        /// <summary>
        /// Used by the compiler.
        /// </summary>
        internal PhpLambdaFunction(Signature astSignature, CompilationSourceUnit/*!*/ sourceUnit, Position position)
            : base(
            new PhpRoutineDesc(
                DTypeDesc.Create(typeof(PHP.Library.SPL.Closure)),
                PhpMemberAttributes.Private | PhpMemberAttributes.Static | PhpMemberAttributes.Final),
            astSignature,
            new TypeSignature(FormalTypeParam.EmptyList))
        {
            Debug.Assert(sourceUnit != null && position.IsValid);

            this.position = position;
            this.sourceUnit = sourceUnit;
        }
Esempio n. 5
0
		/// <summary>
		/// Used by the compiler.
		/// </summary>
		internal PhpMethod(PhpType/*!*/ declaringType, Name name, PhpMemberAttributes memberAttributes, bool hasBody,
      Signature astSignature, TypeSignature astTypeSignature, CompilationSourceUnit/*!*/ sourceUnit, Position position)
			: base(new PhpRoutineDesc(declaringType.TypeDesc, memberAttributes), astSignature, astTypeSignature)
		{
			Debug.Assert(declaringType != null && sourceUnit != null && position.IsValid);

			this.name = name;
			this.position = position;
			this.hasBody = hasBody;
			this.sourceUnit = sourceUnit;
		}
Esempio n. 6
0
		/// <summary>
		/// To be used by compiler.
		/// </summary>
		internal PhpFunction(QualifiedName qualifiedName, PhpMemberAttributes memberAttributes,
			Signature astSignature, TypeSignature astTypeSignature, bool isConditional, Scope scope,
			CompilationSourceUnit/*!*/ sourceUnit, Position position)
			: base(new PhpRoutineDesc(sourceUnit.CompilationUnit.Module, memberAttributes), astSignature, astTypeSignature)
		{
			Debug.Assert(sourceUnit != null && position.IsValid);

			this.declaration = new Declaration(sourceUnit, this, false, isConditional, scope, position);
			this.qualifiedName = qualifiedName;
			this.version = new VersionInfo();
			this.signature = null; // to be written up
		}
Esempio n. 7
0
		/// <summary>
		/// Analyzes the AST of the source unit.
		/// </summary>
        internal void Analyze(CompilationSourceUnit/*!*/ sourceUnit)
		{
			state = States.FullAnalysisStarted;

			this.sourceUnit = sourceUnit;
			this.currentNamespace = sourceUnit.CurrentNamespace;
			this.currentScope = Scope.Global;

			sourceUnit.Ast.Analyze(this);

			this.currentScope = Scope.Invalid;
		}
Esempio n. 8
0
		internal void AnalyzeMembers(IEnumerable<Declaration>/*!*/ declarations)
		{
			state = States.MemberAnalysisStarted;

			foreach (Declaration decl in declarations)
			{
				this.sourceUnit = decl.SourceUnit;

				if (decl.Node != null)
					decl.Node.AnalyzeMembers(this);
			}
		}
Esempio n. 9
0
 Evaluation IExpressionCompiler.EvaluatePriorAnalysis(Expression node, CompilationSourceUnit sourceUnit)
 {
     return(EvaluatePriorAnalysis((T)node, sourceUnit));
 }
Esempio n. 10
0
 public virtual Evaluation EvaluatePriorAnalysis(T node, CompilationSourceUnit sourceUnit)
 {
     // in-evaluable by default:
     return(new Evaluation(node));
 }
Esempio n. 11
0
		/// <summary>
		/// Used by compiler.
		/// </summary>
		public GlobalConstant(QualifiedName qualifiedName, PhpMemberAttributes memberAttributes,
            CompilationSourceUnit/*!*/ sourceUnit, bool isConditional, Scope scope, Text.Span position)
			: base(new DConstantDesc(sourceUnit.CompilationUnit.Module, memberAttributes, null))
		{
            Debug.Assert(sourceUnit != null);

			this.qualifiedName = qualifiedName;
			this.declaration = new Declaration(sourceUnit, this, false, isConditional, scope, position);
            //this.origin = origin;

            if (sourceUnit.CompilationUnit is ScriptCompilationUnit)    // J: place the constant into <script> type so it can be reflected properly
                scriptTypeBuilder = ((ScriptCompilationUnit)sourceUnit.CompilationUnit).ScriptBuilder.ScriptTypeBuilder;
		}
Esempio n. 12
0
 public override Evaluation EvaluatePriorAnalysis(GlobalConstUse node, CompilationSourceUnit sourceUnit)
 {
     constant = sourceUnit.TryResolveGlobalConstantGlobally(node.Name);
     return((constant != null && constant.HasValue) ? new Evaluation(node, constant.Value) : new Evaluation(node));
 }
Esempio n. 13
0
            public override Evaluation EvaluatePriorAnalysis(PseudoClassConstUse node, CompilationSourceUnit sourceUnit)
            {
                var value = TryGetValue(node);

                if (value != null)
                {
                    return(new Evaluation(node, value));
                }
                else
                {
                    return(base.EvaluatePriorAnalysis(node, sourceUnit));
                }
            }
Esempio n. 14
0
		/// <summary>
		/// Called when a <see cref="PHP.Core.AST.GlobalCode"/> AST node is left during the emit phase.
		/// </summary>
		public void LeaveGlobalCodeDeclaration()
		{
			CompilerLocationStack.GlobalCodeContext gc_context = locationStack.PeekGlobalCode();
			locationStack.Pop();

			// clear (for convenience):
			this.sourceUnit = null;

            // close CallSites:
            this.callSites.Bake();

			// restore:
            this.callSites = null;
			this.il = gc_context.IL;
			this.ScriptContextPlace = gc_context.ScriptContextPlace;
			this.TypeContextPlace = gc_context.ClassContextPlace;
            this.LateStaticBindTypePlace = null;
			this.SelfPlace = gc_context.SelfPlace;
			this.ResultPlace = gc_context.ResultPlace;
			this.ReturnLabel = gc_context.ReturnLabel;
			this.currentVariablesTable = gc_context.CurrentVariablesTable;
			this.currentLabels = gc_context.CurrentLabels;
			this.RTVariablesTablePlace = gc_context.RTVariablesTablePlace;
			this.OptimizedLocals = gc_context.OptimizedLocals;
			this.ReturnsPhpReference = gc_context.ReturnsPhpReference;
			this.ExceptionBlockNestingLevel = gc_context.ExceptionBlockNestingLevel;
		}
Esempio n. 15
0
 public override Evaluation EvaluatePriorAnalysis(Literal node, CompilationSourceUnit sourceUnit)
 {
     return(new Evaluation(node, GetValue(node)));
 }
Esempio n. 16
0
 public override Evaluation EvaluatePriorAnalysis(UnaryEx node, CompilationSourceUnit sourceUnit)
 {
     return(node.Expr.EvaluatePriorAnalysis(sourceUnit).ReadOnlyEvaluate(node));
 }
Esempio n. 17
0
        public static Evaluation EvaluatePriorAnalysis(this Expression /*!*/ node, CompilationSourceUnit /*!*/ sourceUnit)
        {
            var nodecompiler = node.ExpressionCompiler();

            return(nodecompiler.EvaluatePriorAnalysis(node, sourceUnit));
        }