1 #ifndef LOADER_PARSEDSOURCE_H_
2 #define LOADER_PARSEDSOURCE_H_
29 ScriptToken(const std::string &, Type);
30 explicit ScriptToken(Literal *);
33 ScriptToken(const ScriptToken &);
34 ScriptToken &operator =(const ScriptToken &);
37 Type GetType() const { return type; }
38 const std::string &RegisterName() const;
39 const std::string &CommandName() const;
40 const std::string &Identifier() const;
41 const std::string &Label() const;
42 const Literal *GetLiteral() const;
71 explicit Literal(const std::vector<Value *> &);
73 Literal(const std::string &, const std::vector<PropertyList *> &);
74 /// array of identifiers
75 Literal(const std::string &, const std::vector<std::string> &);
77 explicit Literal(bool);
79 Literal(int r, int g, int b, int a = 255);
81 explicit Literal(int number);
83 Literal(const std::string &dir, const std::string &path);
85 Literal(const std::string &);
87 Literal(int x, int y);
89 Literal(const std::string &typeName, PropertyList *properties);
91 explicit Literal(const std::vector<ScriptToken *> &);
94 Literal(const Literal &);
95 Literal &operator =(const Literal &);
98 Type GetType() const { return type; }
99 bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS || GetType() == ARRAY_IDENTS; }
100 bool IsObject() const { return GetType() == OBJECT; }
101 int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size()
102 : (GetType() == ARRAY_PROPS ? GetPropertyLists().size() : GetIdentifiers().size()); }
104 const std::vector<Value *> &GetValues() const;
105 const std::vector<PropertyList *> &GetPropertyLists() const;
106 const std::vector<std::string> &GetIdentifiers() const;
107 bool GetBoolean() const;
109 int GetGreen() const;
111 int GetAlpha() const;
112 int GetNumber() const;
113 const std::string &GetString() const;
116 const std::string &GetTypeName() const;
117 const PropertyList *GetProperties() const;
118 const std::vector<ScriptToken *> &GetScript() const;
122 std::string typeName, str;
123 std::vector<Value *> values;
124 std::vector<PropertyList *> propertyLists;
125 std::vector<std::string> identifiers;
126 std::vector<ScriptToken *> script;
137 explicit Value(const std::string &identifier)
138 : literal(0), identifier(identifier), isLiteral(false) { }
139 explicit Value(Literal *literal)
140 : literal(literal), isLiteral(true) { }
143 Value(const Value &);
144 Value &operator =(const Value &);
147 bool IsLiteral() const { return isLiteral; }
148 const Literal &GetLiteral() const;
149 const std::string &GetIdentifier() const;
153 std::string identifier;
165 PropertyList(const PropertyList &);
166 PropertyList &operator =(const PropertyList &);
169 void SetProperty(const std::string &name, Value *value) {
173 typedef std::map<std::string, Value *>::iterator Iterator;
174 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
175 Iterator Begin() { return props.begin(); }
176 ConstIterator Begin() const { return props.begin(); }
177 Iterator End() { return props.end(); }
178 ConstIterator End() const { return props.end(); }
181 std::map<std::string, Value *> props;
189 Declaration(const std::string &typeName, const std::string &identifier)
190 : typeName(typeName), identifier(identifier) { }
191 virtual ~Declaration() { }
193 Declaration(const Declaration &);
194 Declaration &operator =(const Declaration &);
197 const std::string &TypeName() const { return typeName; }
198 const std::string &Identifier() const { return identifier; }
201 std::string typeName;
202 std::string identifier;
208 : public Declaration {
211 Definition(const std::string &typeName, const std::string &identifier)
212 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
213 virtual ~Definition();
215 Definition(const Definition &);
216 Definition &operator =(const Definition &);
219 void SetValue(Literal *);
220 void SetValue(PropertyList *);
222 bool HasLiteralValue() const { return isLiteral && value; }
223 bool HasProperties() const { return !isLiteral && value; }
224 Literal *GetLiteral();
225 const Literal *GetLiteral() const;
226 PropertyList *GetProperties();
227 const PropertyList *GetProperties() const;
242 ParsedSource(const ParsedSource &);
243 ParsedSource &operator =(const ParsedSource &);
246 void AddDeclaration(Declaration *);
247 void AddDefinition(Definition *);
248 void ExportDeclaration(Declaration *);
249 void ExportIdentifier(const std::string &);
251 bool IsDeclared(const std::string &) const;
252 Declaration &GetDeclaration(const std::string &);
253 const Declaration &GetDeclaration(const std::string &) const;
254 bool IsDefined(const std::string &) const;
255 Definition &GetDefinition(const std::string &);
256 const Definition &GetDefinition(const std::string &) const;
258 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
259 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
260 const std::set<std::string> &Exports() const { return exports; }
263 void WriteHeader(std::ostream &) const;
266 std::map<std::string, Declaration *> declarations;
267 std::map<std::string, Definition *> definitions;
268 std::set<std::string> exports;
277 ostream &operator <<(ostream &, const loader::ParsedSource &);
278 ostream &operator <<(ostream &, const loader::Literal &);