コード例 #1
0
			void ParserFileTestTest::TestLogic(void) {
				ParserAPI test;
				TIME(test.ParseFile(FILE_PATH));
				if (test.HasError()) {
					__list_parsing_errors(test);
					ASSERT(!test.HasError()); // certain failure here, to stop the test
				}
				ASTNode* root = test.GetAST();
				ASSERT(root != 0x00);
				
				FileOutputStream _fout("treeVisualisation.txt", FileOutputStream::Mode::Truncate());
				FileOutputStream _foutxml("treeVisualisation.xml", FileOutputStream::Mode::Truncate());
				BufferedOutputStream fout(_fout);
				BufferedOutputStream foutxml(_foutxml);
				ASTTreeVisualisationVisitor visitor(fout);
				ASTMITTreeVisualizerXMLProducerVisitor mitvis(foutxml);
				TIME(root->Accept(&visitor))
				TIME(root->Accept(&mitvis))
				test.DeleteListAndAST();
			}
コード例 #2
0
ファイル: SINRunTester.cpp プロジェクト: HistoricalValue/sin
			void RunFileTest::TestLogic(void) {
				ASTNode* root;
				ParserAPI test;
				test.ParseFile(FILE_PATH);
				if (test.HasError()) {
					logger->Notice("Parsing errors for file " FILE_PATH);
					__list_parsing_errors(test);
					// Try another file
					logger->Notice("trying \"./sin_tun_test.sin\"");
					ParserAPI test0;
					test0.ParseFile("sin_run_test.sin");
					if (test0.HasError()) {
						logger->Notice("Parsing errors for file ./sin_run_test.sin");
						__list_parsing_errors(test0);
						ASSERT(!test0.HasError()); // certain failure here, to stop the test
					}
					else {
						logger->Notice("fallback sin_run_test.sin passed");
						root = test0.GetAST();
					}
				}
				else
					root = test.GetAST();
				ASSERT(root != 0x00);
				
				FileOutputStream _foutxml("RunTreeVisualisation.xml", FileOutputStream::Mode::Truncate());
				FileOutputStream _fouttxt("RunTreeVisualisation.txt", FileOutputStream::Mode::Truncate());
				FileOutputStream _ctrltxt("RunTreeCtrlVisualisation.txt", FileOutputStream::Mode::Truncate());
				FileOutputStream _metatxt("ShiftToMetaEvaluatorASTVisitor.txt", FileOutputStream::Mode::Truncate());

				BufferedOutputStream foutxml(_foutxml);
				BufferedOutputStream fouttxt(_fouttxt);
				BufferedOutputStream ctrltxt(_ctrltxt); 
				BufferedOutputStream metatxt(_metatxt); 
				

				ASTTreeCtrlVisitor						ctrlvis(ctrltxt);
				ASTTreeVisualisationVisitor				visitor(fouttxt);
				//ASTTreeVisualisationVisitor				metaVisualVisitor(metatxt);
				//ASTMITTreeVisualizerXMLProducerVisitor	mitvis(foutxml);
				//ASTCloneVisitor							cloneVisitor;
				//ASTUnparseTreeVisitor					uparseVisitor;
				//
				root->Accept(&visitor);
				root->Accept(&ctrlvis);
				//root->Accept(&mitvis);
				//root->Accept(&uparseVisitor);
				//root->Accept(&cloneVisitor);

				//String unpasedString1 = uparseVisitor.UnparsedString();
				//uparseVisitor.CleanUnparsedString();

				//cloneVisitor.Root()->Accept(&uparseVisitor);
				//String unpasedString2 = uparseVisitor.UnparsedString();
				//
				//SINASSERT(unpasedString1 == unpasedString2);

				//

				//static_cast<OutputStream&>(STDOUT) << "\n\n" << unpasedString2 << "\n\n\n";

				foutxml.flush();
				fouttxt.flush();
				ctrltxt.flush();


				//ASTNode & lastKid = static_cast<ASTNode &>(*root->rbegin());
				//cloneVisitor.Resset();
				//lastKid.Accept(&cloneVisitor);
				//uparseVisitor.CleanUnparsedString();
				//ASTNode * cloneRoot = cloneVisitor.Root();
				//cloneRoot->Accept(&uparseVisitor);
				//static_cast<OutputStream&>(STDOUT) << "\n\n" << uparseVisitor.UnparsedString() << "\n\n\n";
				//cloneVisitor.DeleteListAndAST();


				VM::VirtualState vs;
				vs.SetPrintHandler(&__print_handler);

				Library::Library lib;

				Library::Functions::print			print;
				Library::Functions::println			println;
				Library::Functions::arguments		arguments;
				Library::Functions::totalarguments	totalarguments;
				Library::Functions::tostring		tostring;
				Library::Functions::strtonum		strtonum;
				Library::Functions::typeof			typeof;
				Library::Functions::fileopen        fileopen;
				Library::Functions::fileread        fileread;
				
				lib.InstallFunction(&print			);
				lib.InstallFunction(&println		);
				lib.InstallFunction(&arguments		);
				lib.InstallFunction(&totalarguments	);
				lib.InstallFunction(&tostring		);
				lib.InstallFunction(&strtonum		);
				lib.InstallFunction(&typeof			);
				lib.InstallFunction(&fileopen       );
				lib.InstallFunction(&fileread       );

				// TODO remove the reference here and watch it burn 
				SymbolTable *globalSymTable = &vs.CurrentStable();
				globalSymTable->Insert("print",          SINEWCLASS(MemoryCellLibFunction, (&print)));
				globalSymTable->Insert("println",        SINEWCLASS(MemoryCellLibFunction, (&println)));
				globalSymTable->Insert("arguments",      SINEWCLASS(MemoryCellLibFunction, (&arguments)));
				globalSymTable->Insert("totalarguments", SINEWCLASS(MemoryCellLibFunction, (&totalarguments)));
				globalSymTable->Insert("tostring",       SINEWCLASS(MemoryCellLibFunction, (&tostring)));
				globalSymTable->Insert("strtonum",       SINEWCLASS(MemoryCellLibFunction, (&strtonum)));
				globalSymTable->Insert("typeof",         SINEWCLASS(MemoryCellLibFunction, (&typeof)));
				globalSymTable->Insert("fileopen",       SINEWCLASS(MemoryCellLibFunction, (&fileopen)));
				globalSymTable->Insert("fileread",       SINEWCLASS(MemoryCellLibFunction, (&fileread)));

				
				TreeEvaluationVisitor eval(&lib, &vs);
				
				try {
					root->Accept(&eval);
				} catch(SIN::RunTimeError rte) {
					static_cast<OutputStream&>(STDOUT) << rte.CompleteMessage() << "\n";
					exit(-1);
				} catch(...) {
					static_cast<OutputStream&>(STDOUT) << "Unexpected exception" << "\n";
					exit(-1);
				}
				//ShiftToMetaEvaluatorASTVisitor shifter(eval);
				//root->Accept(&shifter);
				//shifter.Root()->Accept(&metaVisualVisitor);
				
				

				metatxt.flush();
				test.DeleteListAndAST();
//				shifter.DeleteListAndAST();
			}
コード例 #3
0
void ASTCodeGenVisitor::VisitNextASTNode(ASTNode* s) {
  ASTNode* next = s->GetNextASTNode();
  if (next) {
    next->Accept(*this);
  }
}