Beispiel #1
0
        public CompilationSourceUnit(CompilationUnitBase /*!*/ compilationUnit, PhpSourceFile /*!*/ sourceFile, Encoding /*!*/ encoding, ILineBreaks /*!*/ lineBreaks)
            : base(sourceFile, encoding, lineBreaks)
        {
            Debug.Assert(compilationUnit != null);

            this.compilationUnit           = compilationUnit;
            this.namingContextFieldBuilder = null;        // to be filled during compilation just before the unit gets emitted
            this.symbolDocumentWriter      = null;        // to be filled during compilation just before the unit gets emitted
        }
Beispiel #2
0
        public SourceUnit(CompilationUnitBase /*!*/ compilationUnit, PhpSourceFile /*!*/ sourceFile, Encoding /*!*/ encoding)
        {
            Debug.Assert(compilationUnit != null && sourceFile != null && encoding != null);

            this.compilationUnit           = compilationUnit;
            this.sourceFile                = sourceFile;
            this.encoding                  = encoding;
            this.namingContextFieldBuilder = null;        // to be filled during compilation just before the unit gets emitted
            this.symbolDocumentWriter      = null;        // to be filled during compilation just before the unit gets emitted
        }
Beispiel #3
0
        public SourceCodeUnit(CompilationUnitBase /*!*/ compilationUnit, string /*!*/ code, PhpSourceFile /*!*/ sourceFile,
                              Encoding /*!*/ encoding, int line, int column)
            : base(compilationUnit, sourceFile, encoding)
        {
            this.code   = code;
            this.line   = line;
            this.column = column;

            this.initialState = Lexer.LexicalStates.ST_IN_SCRIPTING;
        }
Beispiel #4
0
        public SourceCodeUnit(CompilationUnitBase /*!*/ compilationUnit, string /*!*/ code, PhpSourceFile /*!*/ sourceFile,
                              Encoding /*!*/ encoding, int line, int column)
            : base(compilationUnit, sourceFile, encoding, Text.LineBreaks.Create(code))
        {
            this.code   = code;
            this.line   = line;
            this.column = column;

            // opening and closing script tags are not present
            this.initialState = Lexer.LexicalStates.ST_IN_SCRIPTING;
        }
		public override IPhpModuleBuilder/*!*/ DefineModule(CompilationUnitBase/*!*/ compilationUnit)
		{
			return DefineModule((PureCompilationUnit)compilationUnit);
		}
Beispiel #6
0
 /// <summary>
 /// Used by the loader.
 /// </summary>
 protected PhpModule(DAssembly/*!*/ assembly)
     : base(assembly)
 {
     this._compilationUnit = null; // lazy init or unused
 }
Beispiel #7
0
 /// <summary>
 /// Used by the builder.
 /// </summary>
 protected PhpModule(CompilationUnitBase/*!*/ compilationUnit, PhpAssembly/*!*/ assembly)
     : base(assembly)
 {
     this._compilationUnit = compilationUnit;
 }
Beispiel #8
0
 public VirtualSourceFileUnit(CompilationUnitBase /*!*/ compilationUnit, string /*!*/ code,
                              PhpSourceFile /*!*/ sourceFile, Encoding /*!*/ encoding)
     : base(compilationUnit, sourceFile, encoding)
 {
     this.code = code;
 }
Beispiel #9
0
 public PhpScriptSourceUnit(CompilationUnitBase /*!*/ compilationUnit, string /*!*/ code, PhpSourceFile /*!*/ sourceFile,
                            Encoding /*!*/ encoding, int line, int column)
     : base(compilationUnit, code, sourceFile, encoding, line, column)
 {
     this.initialState = Lexer.LexicalStates.INITIAL;
 }
Beispiel #10
0
		/// <summary>
		/// Adds a new module to application's assembly.
		/// </summary>
		/// <param name="compiledUnit">Unit being compiled.</param>
		/// <param name="ctx">A compilation context.</param>
		/// <returns>The builder where compiler should emit the resulting code.</returns>
		public IPhpModuleBuilder/*!*/ DefineModuleBuilder(CompilationUnitBase/*!*/ compiledUnit, CompilationContext ctx)
		{
			return assemblyBuilder.DefineModule(compiledUnit);
		}
Beispiel #11
0
 /// <summary>
 /// Used by the builder.
 /// </summary>
 protected PhpModule(CompilationUnitBase /*!*/ compilationUnit, PhpAssembly /*!*/ assembly)
     : base(assembly)
 {
     this._compilationUnit = compilationUnit;
 }
		/// <summary>
		/// Persists a built script to a file.
		/// </summary>
		/// <param name="compilationUnit">The unit being compiled.</param>
		/// <param name="ctx">Compilation context.</param>
		public void Persist(CompilationUnitBase/*!*/ compilationUnit, CompilationContext/*!*/ ctx)
		{
			Debug.Assert(compilationUnit is ScriptCompilationUnit && ctx is WebCompilationContext);

			WebCompilationContext context = (WebCompilationContext)ctx;
			ScriptCompilationUnit unit = (ScriptCompilationUnit)compilationUnit;
			SingleScriptAssemblyBuilder assembly_builder = (SingleScriptAssemblyBuilder)unit.ModuleBuilder.AssemblyBuilder;

			assembly_builder.Save();

            string ns = ScriptModule.GetSubnamespace(unit.SourceUnit.SourceFile.RelativePath, false);

            if (SaveOnlyAssembly)
            {
                // assembly not loaded into memory yet (we need to load from fs to not break debugging)
                string file = assembly_builder.Assembly.Path;

                CacheEntry entry;
                LoadSSA(ns, file, out entry);
            }
            else
            {
                // We only add the assembly into the cache, if it was built and loaded into memory.
                // Otherwise the assembly has to be reloaded from the disk.
                // This is because of debugging, since we don't want to load dynamic assemblies into memory, which breaks debug symbols.

                // makes up a list of dependent assembly names:
                string[] includers = new string[unit.Includers.Count];
                int i = 0;
                foreach (StaticInclusion inclusion in unit.Includers)
                    includers[i++] = ScriptModule.GetSubnamespace(inclusion.Includer.SourceUnit.SourceFile.RelativePath, false);

                // what assemblies are included by this one?
                string[] inclusions = new string[unit.Inclusions.Count];
                int j = 0;
                foreach (StaticInclusion inclusion in unit.Inclusions)
                    inclusions[j++] = ScriptModule.GetSubnamespace(new RelativePath(0, inclusion.Includee.RelativeSourcePath), false);

                // adds dependencies on the source file and the included assemblies:
                SetCacheEntry(ns,
                    new CacheEntry(
                        assembly_builder.SingleScriptAssembly.GetScriptType(),
                        assembly_builder.SingleScriptAssembly, context.RequestTimestamp, includers, inclusions, true), true, true);
            }
		}
		/// <summary>
		/// Creates a new instance of <see cref="ScriptBuilder"/> to be used for compilation of the script's assembly.
		/// </summary>
		/// <param name="compiledUnit">Unit being compiled.</param>
		/// <param name="ctx">The current compilation context.</param>
		/// <returns>The script builder.</returns>
		public IPhpModuleBuilder DefineModuleBuilder(CompilationUnitBase/*!*/ compiledUnit, CompilationContext/*!*/ ctx)
		{
			Debug.Assert(compiledUnit is ScriptCompilationUnit && ctx is WebCompilationContext);
			WebCompilationContext context = (WebCompilationContext)ctx;
			ScriptCompilationUnit unit = (ScriptCompilationUnit)compiledUnit;

			// creates an assembly name:
			AssemblyName name = context.GetAssemblyFullName(unit.SourceUnit.SourceFile);

			// creates a script assembly builder:
			SingleScriptAssemblyBuilder builder = new SingleScriptAssemblyBuilder(applicationContext,
				name, outDir, name.Name + AssemblyExt, AssemblyKinds.WebPage, context.Config.Compiler.Debug, false, context.SaveOnlyAssembly, null);
            
			return builder.DefineScript(unit);
		}
Beispiel #14
0
 public VirtualSourceFileUnit(CompilationUnitBase /*!*/ compilationUnit, string /*!*/ code,
                              PhpSourceFile /*!*/ sourceFile, Encoding /*!*/ encoding)
     : base(compilationUnit, sourceFile, encoding, Text.LineBreaks.Create(code))
 {
     this.code = code;
 }
		public override IPhpModuleBuilder DefineModule(CompilationUnitBase/*!*/ compilationUnit)
		{
			return DefineModule((ScriptCompilationUnit)compilationUnit);
		}
		public abstract IPhpModuleBuilder/*!*/ DefineModule(CompilationUnitBase/*!*/ compilationUnit);
Beispiel #17
0
 public SourceFileUnit(CompilationUnitBase /*!*/ compilationUnit, PhpSourceFile /*!*/ sourceFile, Encoding /*!*/ encoding)
     : base(compilationUnit, sourceFile, encoding)
 {
     Debug.Assert(!(compilationUnit is TransientCompilationUnit) && encoding != null && sourceFile != null);
 }
Beispiel #18
0
 /// <summary>
 /// Used by the loader.
 /// </summary>
 protected PhpModule(DAssembly /*!*/ assembly)
     : base(assembly)
 {
     this._compilationUnit = null; // lazy init or unused
 }
Beispiel #19
0
		/// <summary>
		/// Ignored. All modules are stored in a single assembly which is persisted in <see cref="Finish"/>.
		/// </summary>
		public void Persist(CompilationUnitBase/*!*/ compiledUnit, CompilationContext/*!*/ ctx)
		{
			// nop //
		}