C:/Projets/hexamonkey/core/interpreter/fromfilemodule.h
Go to the documentation of this file.
00001 //This file is part of the HexaMonkey project, a multimedia analyser
00002 //Copyright (C) 2013  Sevan Drapeau-Martin, Nicolas Fleury
00003 
00004 //This program is free software; you can redistribute it and/or
00005 //modify it under the terms of the GNU General Public License
00006 //as published by the Free Software Foundation; either version 2
00007 //of the License, or (at your option) any later version.
00008 
00009 //This program is distributed in the hope that it will be useful,
00010 //but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //GNU General Public License for more details.
00013 
00014 //You should have received a copy of the GNU General Public License
00015 //along with this program; if not, write to the Free Software
00016 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 
00018 #ifndef FROMFILEMODULE_H
00019 #define FROMFILEMODULE_H
00020 
00021 #include <memory>
00022 
00023 #include "core/mapmodule.h"
00024 #include "core/interpreter/program.h"
00025 #include "core/interpreter/evaluator.h"
00026 
00032 class FromFileModule : public Module
00033 {
00034 public:
00038     FromFileModule(Program program);
00039 
00040 private:
00041     virtual void addFormatDetection(StandardFormatDetector::Adder& formatAdder) final;
00042     virtual void requestImportations(std::vector<std::string>& formatRequested) final;
00043     virtual bool doLoad() final;
00044 
00045     virtual Parser* getParser(const ObjectType &type, Object& object, const Module& fromModule) const final;
00046     virtual bool hasParser(const ObjectType &type) const final;
00047     virtual int64_t doGetFixedSize(const ObjectType &type, const Module &module) const final;
00048 
00049     virtual bool doCanHandleFunction(const std::string& name) const final;
00050     virtual Variable doExecuteFunction(const std::string& name, const ScopePtr &params, const Module &fromModule) const final;
00051     virtual const std::vector<std::string>& doGetFunctionParameterNames(const std::string& name) const final;
00052     virtual const std::vector<bool>& doGetFunctionParameterModifiables(const std::string& name) const final;
00053     virtual const std::vector<Variant>& doGetFunctionParameterDefaults(const std::string& name) const final;
00054 
00055     typedef std::tuple<std::vector<std::string>, std::vector<bool>, std::vector<Variant>, Program> FunctionDescriptor;
00056     typedef std::unordered_map<std::string, FunctionDescriptor> FunctionDescriptorMap;
00057     bool loadProgram(const std::string path);
00058 
00059     void loadFormatDetections(Program& formatDetections, StandardFormatDetector::Adder& formatAdder);
00060     void loadImports(Program& imports, std::vector<std::string>& formatRequested);
00061 
00062     void nameScan(Program &classDeclarations);
00063     void loadExtensions(Program &classDeclarations);
00064     void loadSpecifications(Program &classDeclarations);
00065     bool sizeDependency(const std::string& name) const;
00066 
00067     int64_t guessSize(const Program& instructions) const;
00068 
00069     static std::set<VariablePath> variableDependencies(const Program& instructions, bool modificationOnly);
00070     static void buildDependencies(const Program& instructions, bool modificationOnly, std::set<VariablePath>& descriptors, bool areVariablesModified = false);
00071 
00072     Program::const_iterator headerEnd(const std::string& name) const;
00073     FunctionDescriptorMap::iterator functionDescriptor(const std::string& name) const;
00074 
00075     const Program& program() const;
00076 
00077     Program _program;
00078 
00079     std::unordered_map<std::string, Program> _definitions;
00080     std::unordered_map<std::string, Program> _functions;
00081     mutable FunctionDescriptorMap _functionDescriptors;
00082 
00083     mutable std::map<std::string, int64_t> _fixedSizes;
00084     mutable std::map<std::string, bool> _sizeDependency;
00085     mutable std::map<std::string, Program::const_iterator> _headerEnd;
00086 
00087     Evaluator eval;
00088 
00089 };
00090 
00091 #endif // FROMFILEMODULE_H