From e8b3188be9094cbd82b926a43a06cfc6aa6c5d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 28 Dec 2017 13:02:48 +0100 Subject: [PATCH] Scripts - Also watch included files --- c-opcomp.hh | 1 + c-opmgr.cc | 20 +++++++++++++++++--- c-opparser.cc | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/c-opcomp.hh b/c-opcomp.hh index 8ba3ed4..6009093 100644 --- a/c-opcomp.hh +++ b/c-opcomp.hh @@ -14,6 +14,7 @@ struct T_OpsParserOutput { opast::T_RootNode root; T_KeyValueTable< T_String , opast::E_DataType > types; + ebcl::T_Set< T_FSPath > files{ ebcl::UseTag< ebcl::ArrayBacked< 16 > >( ) }; }; // The actual parser diff --git a/c-opmgr.cc b/c-opmgr.cc index c0034b5..d2c8a6a 100644 --- a/c-opmgr.cc +++ b/c-opmgr.cc @@ -88,10 +88,11 @@ void T_ScriptManager::loadScript( ) noexcept // Load SRD data T_SRDMemoryTarget srdOut; srdOut.clearComments( true ).clearFlushToken( true ); + const auto fn{ path_.makeRelative( Common::Project( ).basePath( ) ) }; try { T_SRDTextReader srdReader{ srdOut }; T_FileInputStream fis{ input }; - srdReader.read( path_.toString( ) , fis ); + srdReader.read( fn.toString( ) , fis ); } catch ( X_StreamError const& e ) { T_StringBuilder sb; sb << "could not load: " << e.what( ); @@ -115,11 +116,24 @@ void T_ScriptManager::loadScript( ) noexcept } // Parse the fuck - if ( !parser_.parse( path_ , srdOut.list( ) ) ) { + const bool parsed{ parser_.parse( path_ , srdOut.list( ) ) }; + auto pOut{ parser_.result( ) }; + const auto nf{ pOut->files.size( ) }; + if ( nf ) { + watcher_.clear( ); + for ( auto i = 0u ; i < nf ; i ++ ) { + watcher_.watch( pOut->files[ i ] ); + } + } + if ( !parsed ) { errors_.addAll( parser_.errors( ) ); DumpSRDErrors( "Parse errors" , errors_ ); return; } - output_ = compiler_.compile( *parser_.result( ) ); + + output_ = compiler_.compile( *pOut ); + // FIXME - errors from compiler + + printf( "Script loaded & compiled\n" ); } diff --git a/c-opparser.cc b/c-opparser.cc index 3fddb5f..185e9e7 100644 --- a/c-opparser.cc +++ b/c-opparser.cc @@ -342,6 +342,7 @@ void T_ParserImpl_::main( assert( file.isAbsolute( ) ); curFile = file.canonical( ); baseDir = file.parent( ); + output->files.add( file ); parseTopLevel( input ) && checkRequiredBlocks( input ) && checkCalls( ) @@ -1082,6 +1083,7 @@ void T_ParserImpl_::handleInclude( // Parse included file inclStack.add( curFile ); curFile = inclPath; + output->files.add( inclPath ); parseTLList( srdOut.list( ) ); curFile = inclStack.last( ); inclStack.removeLast( );