4 * Created on: Aug 26, 2012
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
12 #include "ParsedSource.h"
13 #include "TypeDescription.h"
14 #include "../battle/fwd.h"
15 #include "../common/fwd.h"
16 #include "../geometry/Vector.h"
17 #include "../graphics/Color.h"
18 #include "../graphics/ComplexAnimation.h"
19 #include "../graphics/fwd.h"
33 class Error: public std::runtime_error {
35 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
39 explicit Interpreter(const ParsedSource &source) : source(source) { }
42 Interpreter(const Interpreter &);
43 Interpreter &operator =(const Interpreter &);
47 void *GetObject(int typeId, const std::string &name);
49 static void CreateTypeDescriptions();
50 struct ParsedDefinition {
51 ParsedDefinition(const Definition *dfn, int type, int id)
52 : dfn(dfn), type(type), id(id) { }
53 const Definition *dfn;
57 struct PostponedDefinition {
58 PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType, bool inlined)
59 : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType), inlined(inlined) { }
62 std::ptrdiff_t offset;
63 const char *identifier;
68 const std::set<std::string> &ExportedIdentifiers() const { return source.Exports(); }
69 const ParsedDefinition &GetDefinition(const std::string &identifier) const;
70 const std::map<std::string, SDL_Surface *> &Images() const { return imageCache; }
71 const std::vector<PostponedDefinition> &PostponedDefinitions() const { return postponedDefinitions; }
72 const std::map<int, std::vector<void *> > &Values() const { return values; }
75 void ReadDefinition(const Definition &);
76 void ReadLiteral(const Definition &);
77 void ReadObject(const Definition &);
79 void ReadLiteral(int typeId, int id, char *dest, const Literal &);
80 void *GetObject(int typeId, const Value &value);
81 void ReadObject(int typeId, int id, char *dest, const PropertyList &);
83 SDL_Surface *GetImage(const std::string &);
85 bool CanLink(const Value &) const;
86 void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined);
89 const ParsedSource &source;
91 std::map<std::string, ParsedDefinition> parsedDefinitions;
92 std::vector<PostponedDefinition> postponedDefinitions;
93 std::map<std::string, SDL_Surface *> imageCache;
94 std::map<int, std::vector<void *> > values;
100 #endif /* LOADER_INTERPRETER_H_ */