Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the GlobalCode class.
        /// </summary>
        public GlobalCode(List<Statement>/*!*/ statements, SourceUnit/*!*/ sourceUnit)
        {
            Debug.Assert(statements != null && sourceUnit != null);

            this.sourceUnit = sourceUnit;
            this.statements = statements;
        }
Exemple #2
0
		/// <summary>
		/// Initializes a new instance of the GlobalCode class.
		/// </summary>
		public GlobalCode(List<Statement>/*!*/ statements, SourceUnit/*!*/ sourceUnit)
		{
			Debug.Assert(statements != null && sourceUnit != null);

			this.sourceUnit = sourceUnit;
			this.statements = statements;
			this.prependedInclusion = null;
			this.AppendedInclusion = null;

			if (!sourceUnit.CompilationUnit.IsPure)
			{
				varTable = new VariablesTable(20);
				varTable.SetAllRef();
				labels = new Dictionary<VariableName, Statement>();
			}
		}
Exemple #3
0
		/// <summary>
		/// To be used by compiler.
		/// </summary>
		internal PhpFunction(QualifiedName qualifiedName, PhpMemberAttributes memberAttributes,
			Signature astSignature, TypeSignature astTypeSignature, bool isConditional, Scope scope,
			SourceUnit/*!*/ 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
		}
Exemple #4
0
		/// <summary>
		/// Analyzes the AST of the source unit.
		/// </summary>
		internal void Analyze(SourceUnit/*!*/ sourceUnit)
		{
			state = States.FullAnalysisStarted;

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

			sourceUnit.Ast.Analyze(this);

			this.currentScope = Scope.Invalid;
		}
Exemple #5
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);
			}
		}
Exemple #6
0
		internal static void ValidateLabels(ErrorSink/*!*/ errors, SourceUnit/*!*/ sourceUnit,
			Dictionary<VariableName, Statement>/*!*/ labels)
		{
			foreach (KeyValuePair<VariableName, Statement> entry in labels)
			{
				LabelStmt label = entry.Value as LabelStmt;
				if (label != null)
				{
					if (!label.IsReferred)
						errors.Add(Warnings.UnusedLabel, sourceUnit, label.Position, entry.Key);
				}
				else
				{
					errors.Add(Errors.UndefinedLabel, sourceUnit, entry.Value.Position, entry.Key);
				}
			}
		}
Exemple #7
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;
		}
Exemple #8
0
		/// <summary>
		/// Used by compiler.
		/// </summary>
		public PhpField(VariableName name, DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes,
			bool hasInitialValue, SourceUnit/*!*/ sourceUnit, Position position)
			: base(new DPhpFieldDesc(declaringType, memberAttributes), name)
		{
			this.hasInitialValue = hasInitialValue;
			this.position = position;
			this.sourceUnit = sourceUnit;
			this.builder = new PhpFieldBuilder(this);
		}
Exemple #9
0
		public GlobalConstantDecl(SourceUnit/*!*/ sourceUnit, Position position, bool isConditional, Scope scope,
			string/*!*/ name, NamespaceDecl ns, Expression/*!*/ initializer)
			: base(position, name, initializer)
		{
			this.ns = ns;

			QualifiedName qn = (ns != null) ? new QualifiedName(new Name(name), ns.QualifiedName) : new QualifiedName(new Name(name));
			constant = new GlobalConstant(qn, PhpMemberAttributes.Public, sourceUnit, isConditional, scope, position);

			constant.SetNode(this);
		}
Exemple #10
0
 public GlobalConstantDecl(SourceUnit/*!*/ sourceUnit, Text.Span span, bool isConditional, Scope scope,
     string/*!*/ name, NamespaceDecl ns, Expression/*!*/ initializer)
     : base(span, name, initializer)
 {
     this.ns = ns;
     this.IsConditional = IsConditional;
     this.Scope = scope;
     this.SourceUnit = sourceUnit;
 }
Exemple #11
0
 internal void Add(ErrorInfo info, SourceUnit sourceUnit, Text.Span pos, object arg1, object arg2)
 {
     Add(info, CoreResources.GetString(info.MessageId, arg1, arg2), sourceUnit, pos);
 }
Exemple #12
0
 internal void Add(ErrorInfo info, SourceUnit sourceUnit, Text.Span pos)
 {
     Add(info, CoreResources.GetString(info.MessageId), sourceUnit, pos);
 }
Exemple #13
0
 internal void Add(ErrorInfo info, SourceUnit sourceUnit, Position pos, params string[] args)
 {
     Add(info, CoreResources.GetString(info.MessageId, args), sourceUnit, pos);
 }
Exemple #14
0
 internal void Add(ErrorInfo info, SourceUnit sourceUnit, Position pos, object arg1, object arg2, object arg3)
 {
     Add(info, CoreResources.GetString(info.MessageId, arg1, arg2, arg3), sourceUnit, pos);
 }
Exemple #15
0
		/// <summary>
		/// Used by the compiler.
		/// </summary>
		internal PhpMethod(PhpType/*!*/ declaringType, Name name, PhpMemberAttributes memberAttributes, bool hasBody,
	  Signature astSignature, TypeSignature astTypeSignature, SourceUnit/*!*/ 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;
		}
Exemple #16
0
        /// <summary>
        /// Used by the compiler.
        /// </summary>
        internal PhpLambdaFunction(Signature astSignature, SourceUnit/*!*/ 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;
        }
Exemple #17
0
		internal void Add(ErrorInfo info, SourceUnit sourceUnit, Position pos, object arg1, object arg2, object arg3)
		{
			Add(info, CoreResources.GetString(info.MessageId, arg1, arg2, arg3), sourceUnit, pos);
		}
Exemple #18
0
		internal void Add(ErrorInfo info, SourceUnit sourceUnit, Position pos, params string[] args)
		{
			Add(info, CoreResources.GetString(info.MessageId, args), sourceUnit, pos);
		}
Exemple #19
0
		private void Add(ErrorInfo info, string/*!*/ message, SourceUnit sourceUnit, Position pos)
		{
			Debug.Assert(message != null);
			
			string full_path;
			ErrorPosition mapped_pos;

			// missing source unit means the file name shouldn't be reported (it is not available)
			if (sourceUnit != null)
			{
				full_path = sourceUnit.GetMappedFullSourcePath(pos.FirstLine);
				mapped_pos = new ErrorPosition(
					sourceUnit.GetMappedLine(pos.FirstLine), pos.FirstColumn,
					sourceUnit.GetMappedLine(pos.LastLine), pos.LastColumn);
			}
			else
			{
				full_path = null;
				mapped_pos = ErrorPosition.Invalid;
			}

			// filter disabled warnings:
			if (info.Id < 0 || (info.Group & (int)disabledGroups) == 0 && Array.IndexOf(disabledWarnings, info.Id) == -1)
			{
				// do not count disabled warnings and related locations et. al.:
                var severity = UpgradeSeverity(info.Severity);
                if (Add(info.Id, message, severity, info.Group, full_path, mapped_pos) && info.Id >= 0)
					counts[severity]++;
			}		
		}
Exemple #20
0
		internal void Validate(SourceUnit/*!*/ sourceUnit, ErrorSink/*!*/ errors)
		{
			Debug.Assert(position.IsValid);

			// no abstract fields:
			if (IsAbstract)
			{
				errors.Add(Errors.PropertyDeclaredAbstract, SourceUnit, position);
				memberDesc.MemberAttributes &= ~PhpMemberAttributes.Abstract;
			}

			// no final fields:
			if (IsFinal)
			{
				errors.Add(Errors.PropertyDeclaredFinal, SourceUnit, position);
				memberDesc.MemberAttributes &= ~PhpMemberAttributes.Final;
			}
		}
Exemple #21
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, SourceUnit/*!*/ 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 Compiler.CodeGenerator.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);
		}