public bool Compile( CompilationUnit unit, FileInfo fileInfo ) { using(StreamReader reader = new StreamReader(fileInfo.FullName)) { return Compile( unit, reader ); } }
public SourceUnit(CompilationUnit compilationUnit, String filename) { statements = new ASTNodeCollection(this); namespaces = new ASTNodeCollection(this); this.compilationUnit = compilationUnit; this.filename = filename; }
public void ExecutePass(CompilationUnit unit) { DeclareAndPopulateGlobalSourceUnit(unit); TypeBuilderSkeletonStep builderVisitor = CreateAssemblyStructure(unit); builderVisitor.VisitNode( unit ); }
public void ExecutePass(CompilationUnit unit) { Method2ScopeVisitor method2scope = new Method2ScopeVisitor(); method2scope.VisitNode(unit); IdentifierNormalizationVisitor identVisitor = new IdentifierNormalizationVisitor(); identVisitor.VisitNode(unit); }
public SourceUnit Parse(CompilationUnit unit, TextReader reader) { RookLexer lexer = new RookLexer(reader); RookBaseParser parser = new RookBaseParser(lexer); parser.ErrorReport = errorReport; return parser.sourceUnit(unit); }
public override void VisitCompilationUnit(CompilationUnit compilationUnit) { nodeStack.Push( nodes.Add("CompilationUnit") ); CurrentNode.Tag = compilationUnit; base.VisitCompilationUnit(compilationUnit); nodeStack.Pop(); }
public void ExecutePass(CompilationUnit unit) { VisitNode(unit); if (errorReport.HasErrors) return; // Now we register the single var declaration as type members (fields) // and ensure they are on the symbol table - sanity check FieldsVisitor visitor = new FieldsVisitor(); visitor.VisitCompilationUnit(unit); }
public bool Compile( String[] files ) { CompilationUnit cunit = new CompilationUnit(); foreach( String file in files ) { if (!Compile(cunit, new FileInfo(file))) { return false; } } return RunPasses(cunit); }
private void DeclareAndPopulateGlobalSourceUnit(CompilationUnit unit) { SourceUnit globalUnit = new SourceUnit(unit, "<global>"); TypeDefinitionStatement globalType = new TypeDefinitionStatement( AccessLevel.Public, "RookGlobal" ); globalUnit.Statements.Add( globalType ); MethodDefinitionStatement entryPoint = new MethodDefinitionStatement( AccessLevel.Public ); entryPoint.Name = "self.main"; foreach(SourceUnit sunit in unit.SourceUnits) { foreach(IStatement stmt in sunit.Statements) { if (stmt.StatementType == StatementType.TypeDefinition) continue; stmt.Parent.RemoveChild( stmt ); if (stmt.StatementType == StatementType.MethodDef) { (stmt as MethodDefinitionStatement).IsStatic = true; } if (stmt.StatementType == StatementType.MultipleVarDeclaration) { // TODO: Ensure no instance vars defined } if (stmt.StatementType == StatementType.ExpressionStmt || stmt.StatementType == StatementType.MultipleVarDeclaration ) { entryPoint.Statements.Add( stmt ); } else { globalType.Statements.Add( stmt ); } } } if (entryPoint.Statements.Count != 0) { globalType.Statements.Add( entryPoint ); // Might be necessary // unit.EntryPointMethod = entryPoint; } unit.SourceUnits.Add(globalUnit); }
public void ExecutePass(CompilationUnit unit) { // Lots of emission code here // Finally emit the types CreateTypesStep step = new CreateTypesStep(); step.PerformStep( unit ); unit.AssemblyBuilder.Save( "RookGenAssembly.exe" ); // assembly.Save( "RookGenAssembly.exe" ); }
private TypeBuilderSkeletonStep CreateAssemblyStructure(CompilationUnit unit) { AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "RookGenAssembly"; AssemblyBuilder assembly = Thread.GetDomain().DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess.Save ); ModuleBuilder module = assembly.DefineDynamicModule( "RookModule", "RookModule.mod", true); unit.AssemblyBuilder = assembly; unit.ModuleBuilder = module; return new TypeBuilderSkeletonStep( module, typeContainer, resolver, errorReport ); }
public override void VisitCompilationUnit(CompilationUnit compilationUnit) { base.VisitCompilationUnit(compilationUnit); while (toProcess.Count != 0) { int lastCount = toProcess.Count; ReProcessTypesOnQueue(); if (lastCount == toProcess.Count) { // Something that couldn't be resolved! enableErrorReporting = true; ReProcessTypesOnQueue(); break; } } }
/// <summary> /// Handy for the test cases /// </summary> public SourceUnit Parse(String contents) { CompilationUnit unit = new CompilationUnit(); return Parse(unit, new StringReader(contents)); }
public SourceUnit Parse(CompilationUnit unit, String contents) { return Parse(unit, new StringReader(contents + "\r\n")); }
private void ExecutePass(ICompilerPass pass, CompilationUnit unit) { if (PrePassExecution != null) { PrePassExecution(this, pass, unit, container.ErrorReportService); } pass.ExecutePass(unit); if (PostPassExecution != null) { PostPassExecution(this, pass, unit, container.ErrorReportService); } }
public void PerformStep(CompilationUnit unit) { VisitNode(unit); }
public TreeWalker(CompilationUnit unit, TreeNodeCollection nodes) { this.nodes = nodes; VisitNode(unit); }
private void CreateAst(CompilationUnit unit, TreeNodeCollection nodes) { nodes.Clear(); new TreeWalker(unit, nodes); }
public bool Compile( CompilationUnit cunit, TextReader reader ) { container.ParserService.Parse(cunit, reader); return !container.ErrorReportService.HasErrors; }
private bool RunPasses(CompilationUnit cunit) { if (!container.ErrorReportService.HasErrors) { ICompilerPass builderSkeleton = container[ typeof(CreateBuilderSkeleton) ] as ICompilerPass; ExecutePass( builderSkeleton, cunit ); } if (!container.ErrorReportService.HasErrors) { ICompilerPass scopePass = container[ typeof(ScopePass) ] as ICompilerPass; ExecutePass( scopePass, cunit ); } if (!container.ErrorReportService.HasErrors) { ICompilerPass typeResPass = container[ typeof(TypeResolutionPass) ] as ICompilerPass; ExecutePass( typeResPass, cunit ); } if (!container.ErrorReportService.HasErrors) { ICompilerPass emission = container[ typeof(Emission) ] as ICompilerPass; emission.ExecutePass(cunit); } return !container.ErrorReportService.HasErrors; }
public void PerformStep(CompilationUnit unit) { }
public override void VisitCompilationUnit(CompilationUnit compilationUnit) { base.VisitCompilationUnit(compilationUnit); ProcessNodesInQueue(); }
public SourceUnit sourceUnit( CompilationUnit cunit ) //throws RecognitionException, TokenStreamException { SourceUnit unit; topLevelScope = cunit.DefiningSymbolTable; unit = new SourceUnit(cunit, getFilename()); PushScope(unit, ScopeType.SourceUnit); nothing(); { switch ( LA(1) ) { case LITERAL_namespace: { namespace_declaration(unit.Namespaces); break; } case EOF: case CLASS: case DO: case DEF: case BEGIN: case NUM_INT: case NUM_FLOAT: case NUM_LONG: case STATEMENT_END: case IDENT: case STATICIDENT: case INSTIDENT: case LITERAL_self: case LPAREN: case LITERAL_require: case LITERAL_redo: case LITERAL_break: case LITERAL_next: case LITERAL_retry: case LITERAL_lambda: case LCURLY: case LITERAL_raise: case LITERAL_yield: case LITERAL_not: case LNOT: case PLUS: case MINUS: case BNOT: case LBRACK: case LITERAL_base: case STRING_LITERAL: case CHAR_LITERAL: { suite(unit.Statements); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } nothing(); match(Token.EOF_TYPE); if (0==inputState.guessing) { cunit.SourceUnits.Add(unit); PopScope(); if (!ErrorReport.HasErrors && scopes.Count != 0) ErrorReport.Error("Invalid scope count. " + "Something seems to be very wrong. Contact Castle's team and report the " + "code that caused this error."); } return unit; }
public virtual void VisitCompilationUnit(CompilationUnit compilationUnit) { VisitNode(compilationUnit.EntryPointSourceUnit); VisitNodes(compilationUnit.SourceUnits); }
private void PostPassExecution(object sender, ICompilerPass pass, CompilationUnit unit, IErrorReport errorService) { CreateAst(unit, resultingAST.Nodes); }
public void ExecutePass(CompilationUnit unit) { }
public bool Compile( TextReader reader ) { CompilationUnit cunit = new CompilationUnit(); if (Compile(cunit, reader)) { return RunPasses(cunit); } return false; }