00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef FLC_MODLOADER_H
00017 #define FLC_MODLOADER_H
00018
00019 #include <falcon/common.h>
00020 #include <falcon/error.h>
00021 #include <falcon/string.h>
00022 #include <falcon/basealloc.h>
00023 #include <falcon/compiler.h>
00024
00025 namespace Falcon {
00026
00027 class Module;
00028 class Stream;
00029 class URI;
00030 class FileStat;
00031 class VFSProvider;
00032
00040 class FALCON_DYN_CLASS ModuleLoader: public BaseAlloc
00041 {
00042 public:
00048 typedef enum
00049 {
00051 t_none,
00053 t_source,
00055 t_ftd,
00057 t_vmmod,
00059 t_binmod,
00064 t_defaultSource
00065 } t_filetype;
00066
00067
00068 protected:
00069 Module *loadModule_ver_1_0( Stream *in );
00070
00071 bool m_alwaysRecomp;
00072 bool m_compMemory;
00073 bool m_saveModule;
00074 bool m_saveMandatory;
00075 bool m_detectTemplate;
00076 bool m_forceTemplate;
00077 bool m_delayRaise;
00078 bool m_ignoreSources;
00079 bool m_saveRemote;
00080 uint32 m_compileErrors;
00081
00082 Compiler m_compiler;
00083 String m_srcEncoding;
00084 bool m_bSaveIntTemplate;
00085
00086 Module *compile( const String &path );
00087 t_filetype searchForModule( String &final_name );
00088 t_filetype checkForModuleAlreadyThere( String &final_name );
00089
00090
00092 String m_language;
00093
00094 Module *loadModule_select_ver( Stream *in );
00095
00100 static void getModuleName( const String &path, String &modName );
00101
00105 List m_path;
00106
00125 virtual Stream *openResource( const String &path, t_filetype type = t_none );
00126
00141 bool scanForFile( URI &origUri, VFSProvider*, t_filetype &type, FileStat &fs );
00142
00156 virtual t_filetype fileType( const String &path );
00157
00159 bool applyLangTable( Module *mod, const String &file_path );
00160
00161 public:
00162
00167 ModuleLoader();
00168 ModuleLoader( const ModuleLoader &other );
00169
00184 ModuleLoader( const String &path );
00185
00186 virtual ~ModuleLoader();
00187
00188 virtual ModuleLoader *clone() const;
00189
00190
00209 void setSearchPath( const String &path );
00210
00224 void addFalconPath();
00225
00244 void addSearchPath( const String &path );
00245
00255 void addDirectoryFront( const String &directory )
00256 {
00257 if ( directory != "" )
00258 m_path.pushFront( new String( directory ) );
00259 }
00260
00269 void addDirectoryBack( const String &directory )
00270 {
00271 if ( directory != "" )
00272 m_path.pushBack( new String( directory ) );
00273 }
00274
00300 virtual Module *loadName( const String &module_name, const String &parent_module = "" );
00301
00348 virtual Module *loadFile( const String &module_path, t_filetype type=t_none, bool scan=false );
00349
00358 virtual Module *loadFile( const URI &module_URI, t_filetype type=t_none, bool scan=false );
00359
00378 virtual Module *loadModule( Stream *input );
00379
00394 Module *loadModule( const String &file );
00395
00411 virtual Module *loadSource( const String &file );
00412
00431 virtual Module *loadSource( Stream *in, const String &uri, const String &modname );
00432
00457 virtual Module *loadBinaryModule( const String &module_path );
00458
00459 void raiseError( int code, const String &expl, int fsError=0 );
00460
00464 void getSearchPath( String &target ) const;
00465
00470 String getSearchPath() const
00471 {
00472 String temp;
00473 getSearchPath( temp );
00474 return temp;
00475 }
00476
00482 void saveIntTemplates( bool mode )
00483 {
00484 m_bSaveIntTemplate = mode;
00485 }
00486
00505 void setLanguage( const String &langname ) { m_language = langname; }
00506
00509 const String &getLanguage() const { return m_language; }
00510
00516 bool loadLanguageTable( Module *module, const String &language );
00517
00521 bool ignoreSources() const { return m_ignoreSources; }
00522
00526 bool alwaysRecomp() const { return m_alwaysRecomp;}
00527
00528 void ignoreSources( bool mode ) { m_ignoreSources = mode; }
00529 void alwaysRecomp( bool mode ) { m_alwaysRecomp = mode; }
00530
00531 void compileInMemory( bool ci ) { m_compMemory = ci; }
00532 bool compileInMemory() const { return m_compMemory; }
00533
00534 void saveModules( bool t ) { m_saveModule = t; }
00535 bool saveModules() const { return m_saveModule; }
00536
00537 void sourceEncoding( const String &name ) { m_srcEncoding = name; }
00538 const String &sourceEncoding() const { return m_srcEncoding; }
00539
00540 void delayRaise( bool setting ) { m_delayRaise = setting; }
00541 bool delayRaise() const { return m_delayRaise; }
00542
00543 void saveMandatory( bool setting ) { m_saveMandatory = setting; }
00544 bool saveMandatory() const { return m_saveMandatory; }
00545
00546 void detectTemplate( bool bDetect ) { m_detectTemplate = bDetect; }
00547 bool detectTemplate() const { return m_detectTemplate; }
00548
00549 void compileTemplate( bool bCompTemplate ) { m_forceTemplate = bCompTemplate; }
00550 bool compileTemplate() const { return m_forceTemplate; }
00551
00561 void saveRemote( bool brem ) { m_saveRemote = brem; }
00562
00566 bool saveRemote() const { return m_saveRemote; }
00567
00569 uint32 compileErrors() const { return m_compileErrors; }
00570
00575 const Compiler &compiler() const { return m_compiler; }
00576
00581 Compiler &compiler() { return m_compiler; }
00582 };
00583
00584 }
00585
00586 #endif
00587