Example #1
0
		/// <summary>
		/// Creates a new script builder.
		/// </summary>
		/// <param name="unit">Compilation unit.</param>
		/// <param name="assemblyBuilder">Script assembly builder.</param>
		/// <param name="subnamespace">The script's subnamespace ending with a type delimiter or a <B>null</B> reference.</param>
		/// <returns>New instance.</returns>
		public ScriptBuilder(ScriptCompilationUnit/*!*/ unit, ScriptAssemblyBuilder/*!*/ assemblyBuilder, string subnamespace)
			: base(unit, assemblyBuilder.ScriptAssembly, subnamespace)
		{
			Debug.Assert(unit != null && assemblyBuilder != null);

			this.assemblyBuilder = assemblyBuilder;

			// remembers a timestamp of the source file:
			this.sourceTimestampUtc = FileSystemUtils.GetLastModifiedTimeUtc(unit.SourceUnit.SourceFile.FullPath);

			DefineBuilders(subnamespace);
		}
		/// <summary>
		/// Defines a new script belonging to the multiscript assembly builder.
		/// </summary>
		public ScriptBuilder/*!*/ DefineModule(ScriptCompilationUnit/*!*/ compilationUnit)
		{
			string subnamespace = ScriptModule.GetSubnamespace(compilationUnit.SourceUnit.SourceFile.RelativePath, true);
			ScriptBuilder sb = new ScriptBuilder(compilationUnit, this, subnamespace);
			MultiScriptAssembly.AddScriptModule(compilationUnit.SourceUnit.SourceFile, sb);
			return sb;
		}
		/// <summary>
		/// Defines one and only script belonging to the assembly builder.
		/// </summary>
		public ScriptBuilder/*!*/ DefineScript(ScriptCompilationUnit/*!*/ compilationUnit)
		{
			// defines a new script:
            string subnamespace = ScriptModule.GetSubnamespace(compilationUnit.SourceUnit.SourceFile.RelativePath, true);
            ScriptBuilder sb = new ScriptBuilder(compilationUnit, this, subnamespace);

			// adds the script into script assembly builder:
			this.SingleScriptAssembly.Module = sb;

			return sb;
		}
Example #4
0
		public StaticInclusion(ScriptCompilationUnit/*!*/ includer, CompilationUnit/*!*/ includee, Scope scope,
			bool isConditional, InclusionTypes inclusionType)
		{
			this.scope = scope;
			this.inclusionType = inclusionType;
			this.includee = includee;
			this.includer = includer;
			this.isConditional = isConditional;
		}
Example #5
0
		private void ProcessNode(ScriptCompilationUnit/*!*/ node)
		{
			Debug.Assert(node.State == CompilationUnit.States.Initial);

			// parses the unit and fills its tables:
			node.Parse(context);

			// resolves outgoing edges:
			node.ResolveInclusions(this);

			// follow DFS tree edges:
			foreach (StaticInclusion edge in node.Inclusions)
			{
				switch (edge.Includee.State)
				{
					case CompilationUnit.States.Initial:
						Debug.Assert(edge.Includee is ScriptCompilationUnit);

						// recursive descent:
						ProcessNode((ScriptCompilationUnit)edge.Includee); // TODO: consider!
						node.MergeTables(edge);
						break;

					case CompilationUnit.States.Parsed:
						// edge closing a cycle:
						pendingInclusions.Add(edge);
						break;

					case CompilationUnit.States.Processed:
						// transverse edge to already processed subtree:
						node.MergeTables(edge);
						break;

					case CompilationUnit.States.Compiled:
						// descent edge to the compiled node:
						edge.Includee.Reflect();
						node.MergeTables(edge);
						break;

					case CompilationUnit.States.Analyzed:
					case CompilationUnit.States.Reflected:
						// descent or transverse edge to already analyzed or compiled and reflected node:
						node.MergeTables(edge);
						break;

					default:
						Debug.Fail("Unexpected CU state");
						throw null;
				}
			}

			node.State = CompilationUnit.States.Processed;
		}
Example #6
0
		/// <summary>
		/// Gets the node of the graph associated with the specified source file.
		/// First, look up the table of processed nodes. 
		/// If not there, check compiled units maintained by the manager.
		/// If it is not found in the manager's cache the source file is locked so that other compilers will 
		/// wait until we finish compilation of the node. The new node is created if the compilation unit doesn't exist for it.
		/// </summary>
		internal CompilationUnit GetNode(PhpSourceFile/*!*/ sourceFile)
		{
			CompilationUnit result;
			if (!nodes.TryGetValue(sourceFile, out result))
			{
				ScriptModule module;

                module = (ScriptModule)context.Manager.LockForCompiling(sourceFile, context);

				if (module != null)
				{
					result = module.CompilationUnit;
				}
				else
				{
					ScriptCompilationUnit scriptResult = new ScriptCompilationUnit();
					scriptResult.SourceUnit = new SourceFileUnit(scriptResult, sourceFile, context.Config.Globalization.PageEncoding);
					result = scriptResult;
				}
				nodes.Add(sourceFile, result);
				NodeAdded(result);
			}

			return result;
		}