Ejemplo n.º 1
0
        public VclCompilerContext Compile(string filename)
        {
            var compilerContext = new VclCompilerContext();

            CompileFile(filename, compilerContext);
            return(compilerContext);
        }
Ejemplo n.º 2
0
        private void CompileFile(string filename, VclCompilerContext compilerContext)
        {
            // Track files we compile so we only compile each file once
            // All files we bring in via include directive are added to queue
            var seenFiles     = new List <string>();
            var filenameQueue = new Queue <string>();

            filenameQueue.Enqueue(filename);

            // Walk queue of files until it is empty
            while (filenameQueue.Any())
            {
                // Retrieve next file from the queue and skip if already processed
                filename = filenameQueue.Dequeue();
                if (seenFiles.Contains(filename))
                {
                    continue;
                }

                // Add to list of seen files and get file content
                seenFiles.Add(filename);
                var fileInfo = _fileProvider.GetFileInfo(filename);
                using (var fileStream = fileInfo.CreateReadStream())
                {
                    using (var reader = new StreamReader(fileStream))
                    {
                        // Read file content from reader
                        var vclContent = reader.ReadToEnd();
                        Debug.WriteLine(vclContent);

                        // Process include directives
                        var includeDirectiveCompiler = new VclCompileIncludes();
                        CompileAndVisit(vclContent, includeDirectiveCompiler);

                        // Queue any include directives we have found
                        foreach (var include in includeDirectiveCompiler.Files)
                        {
                            filenameQueue.Enqueue(include);
                        }

                        // Process all other content
                        CompileFileContent(vclContent, compilerContext);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void CompileFileContent(string vclContent, VclCompilerContext compilerContext)
        {
            // Compile named probe entries
            var probeCompiler = new VclCompileNamedProbeObjects(compilerContext);

            CompileAndVisit(vclContent, probeCompiler);

            // Ensure we have a default probe in the named probe entries
            if (!compilerContext.ProbeReferences.ContainsKey("default"))
            {
                var fieldName = "default".SafeIdentifier("_probe");
                compilerContext.ProbeReferences.Add(
                    "default", new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), fieldName));

                // Create field and add to handler class
                compilerContext.HandlerClass.Members.Add(
                    new CodeMemberField(typeof(VclProbe), fieldName)
                {
                    Attributes     = MemberAttributes.Private,
                    InitExpression =
                        new CodeObjectCreateExpression(
                            typeof(VclProbe),
                            new CodePrimitiveExpression("default"))
                });
            }

            // Compile named backend entries
            var backendCompiler = new VclCompileNamedBackendObjects(compilerContext);

            CompileAndVisit(vclContent, backendCompiler);

            // Compile named ACL entries
            var aclCompiler = new VclCompileNamedAclObjects(compilerContext);

            CompileAndVisit(vclContent, aclCompiler);

            // TODO: Compile named director entries (if we bother to implement)

            // Compile subroutines entries
            var subCompiler = new VclCompileNamedSubroutine(compilerContext);

            CompileAndVisit(vclContent, subCompiler);
        }
 public VclCompileNamedAclObjects(VclCompilerContext compilerContext)
     : base(compilerContext)
 {
 }
Ejemplo n.º 5
0
 protected VclBaseExpressionVisitor(VclCompilerContext compilerContext)
 {
     CompilerContext = compilerContext;
 }
 public VclCompileNamedBackendObjects(VclCompilerContext compilerContext)
     : base(compilerContext)
 {
 }