Пример #1
0
		public bool Compile( CompilationUnit unit, FileInfo fileInfo )
		{
			using(StreamReader reader = new StreamReader(fileInfo.FullName))
			{
				return Compile( unit, reader );
			}
		}
Пример #2
0
		public SourceUnit(CompilationUnit compilationUnit, String filename)
		{
			statements = new ASTNodeCollection(this);
			namespaces = new ASTNodeCollection(this);
			this.compilationUnit = compilationUnit;
			this.filename = filename;
		}
Пример #3
0
		public void ExecutePass(CompilationUnit unit)
		{
			DeclareAndPopulateGlobalSourceUnit(unit);

			TypeBuilderSkeletonStep builderVisitor = CreateAssemblyStructure(unit);

			builderVisitor.VisitNode( unit );
		}
Пример #4
0
		public void ExecutePass(CompilationUnit unit)
		{
			Method2ScopeVisitor method2scope = new Method2ScopeVisitor();
			method2scope.VisitNode(unit);

			IdentifierNormalizationVisitor identVisitor = new IdentifierNormalizationVisitor();
			identVisitor.VisitNode(unit);
		}
Пример #5
0
		public SourceUnit Parse(CompilationUnit unit, TextReader reader)
		{
			RookLexer lexer = new RookLexer(reader);

			RookBaseParser parser = new RookBaseParser(lexer);
			parser.ErrorReport = errorReport;

			return parser.sourceUnit(unit);
		}
Пример #6
0
		public override void VisitCompilationUnit(CompilationUnit compilationUnit)
		{
			nodeStack.Push( nodes.Add("CompilationUnit") );
			CurrentNode.Tag = compilationUnit;

			base.VisitCompilationUnit(compilationUnit);

			nodeStack.Pop();
		}
Пример #7
0
		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);
		}
Пример #8
0
		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);
		}
Пример #9
0
		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);
		}
Пример #10
0
		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" );
		}
Пример #11
0
		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 );
		}
Пример #12
0
		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;
				}
			}
		}
Пример #13
0
		/// <summary>
		/// Handy for the test cases
		/// </summary>
		public SourceUnit Parse(String contents)
		{
			CompilationUnit unit = new CompilationUnit();

			return Parse(unit, new StringReader(contents));
		}
Пример #14
0
		public SourceUnit Parse(CompilationUnit unit, String contents)
		{
			return Parse(unit, new StringReader(contents + "\r\n"));
		}
Пример #15
0
		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);
			}
		}
Пример #16
0
		public void PerformStep(CompilationUnit unit)
		{
			VisitNode(unit);
		}
Пример #17
0
		public TreeWalker(CompilationUnit unit, TreeNodeCollection nodes)
		{
			this.nodes = nodes;

			VisitNode(unit);
		}
Пример #18
0
		private void CreateAst(CompilationUnit unit, TreeNodeCollection nodes)
		{
			nodes.Clear(); new TreeWalker(unit, nodes);
		}
Пример #19
0
		public bool Compile( CompilationUnit cunit, TextReader reader )
		{
			container.ParserService.Parse(cunit, reader);

			return !container.ErrorReportService.HasErrors;
		}
Пример #20
0
		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)
		{
			
		}
Пример #22
0
		public override void VisitCompilationUnit(CompilationUnit compilationUnit)
		{
			base.VisitCompilationUnit(compilationUnit);

			ProcessNodesInQueue();
		}
Пример #23
0
	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;
	}
Пример #24
0
		public virtual void VisitCompilationUnit(CompilationUnit compilationUnit)
		{
			VisitNode(compilationUnit.EntryPointSourceUnit);
			VisitNodes(compilationUnit.SourceUnits);
		}
Пример #25
0
		private void PostPassExecution(object sender, ICompilerPass pass, CompilationUnit unit, IErrorReport errorService)
		{
			CreateAst(unit, resultingAST.Nodes);
		}
Пример #26
0
		public void ExecutePass(CompilationUnit unit)
		{
			
		}
Пример #27
0
		public bool Compile( TextReader reader )
		{
			CompilationUnit cunit = new CompilationUnit();

			if (Compile(cunit, reader))
			{
				return RunPasses(cunit);
			}

			return false;
		}