1 #ifndef LOADER_PARSEDSOURCE_H_
2 #define LOADER_PARSEDSOURCE_H_
25 ScriptToken(const std::string &, Type);
26 explicit ScriptToken(Literal *);
29 ScriptToken(const ScriptToken &);
30 ScriptToken &operator =(const ScriptToken &);
33 Type GetType() const { return type; }
34 const std::string &RegisterName() const;
35 const std::string &CommandName() const;
36 const std::string &Identifier() const;
37 const std::string &Label() const;
38 const Literal *GetLiteral() const;
67 explicit Literal(const std::vector<Value *> &);
69 Literal(const std::string &, const std::vector<PropertyList *> &);
70 /// array of identifiers
71 Literal(const std::string &, const std::vector<std::string> &);
73 explicit Literal(bool);
75 Literal(int r, int g, int b, int a = 255);
77 explicit Literal(int number);
79 Literal(const std::string &dir, const std::string &path);
81 Literal(const std::string &);
83 Literal(int x, int y);
85 Literal(const std::string &typeName, PropertyList *properties);
87 explicit Literal(const std::vector<ScriptToken *> &);
90 Literal(const Literal &);
91 Literal &operator =(const Literal &);
94 Type GetType() const { return type; }
95 bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS || GetType() == ARRAY_IDENTS; }
96 bool IsObject() const { return GetType() == OBJECT; }
97 int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size()
98 : (GetType() == ARRAY_PROPS ? GetPropertyLists().size() : GetIdentifiers().size()); }
100 const std::vector<Value *> &GetValues() const;
101 const std::vector<PropertyList *> &GetPropertyLists() const;
102 const std::vector<std::string> &GetIdentifiers() const;
103 bool GetBoolean() const;
105 int GetGreen() const;
107 int GetAlpha() const;
108 int GetNumber() const;
109 const std::string &GetString() const;
112 const std::string &GetTypeName() const;
113 const PropertyList *GetProperties() const;
114 const std::vector<ScriptToken *> &GetScript() const;
118 std::string typeName, str;
119 std::vector<Value *> values;
120 std::vector<PropertyList *> propertyLists;
121 std::vector<std::string> identifiers;
122 std::vector<ScriptToken *> script;
133 explicit Value(const std::string &identifier)
134 : literal(0), identifier(identifier), isLiteral(false) { }
135 explicit Value(Literal *literal)
136 : literal(literal), isLiteral(true) { }
139 Value(const Value &);
140 Value &operator =(const Value &);
143 bool IsLiteral() const { return isLiteral; }
144 const Literal &GetLiteral() const;
145 const std::string &GetIdentifier() const;
149 std::string identifier;
161 PropertyList(const PropertyList &);
162 PropertyList &operator =(const PropertyList &);
165 void SetProperty(const std::string &name, Value *value) {
169 typedef std::map<std::string, Value *>::iterator Iterator;
170 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
171 Iterator Begin() { return props.begin(); }
172 ConstIterator Begin() const { return props.begin(); }
173 Iterator End() { return props.end(); }
174 ConstIterator End() const { return props.end(); }
177 std::map<std::string, Value *> props;
185 Declaration(const std::string &typeName, const std::string &identifier)
186 : typeName(typeName), identifier(identifier) { }
187 virtual ~Declaration() { }
189 Declaration(const Declaration &);
190 Declaration &operator =(const Declaration &);
193 const std::string &TypeName() const { return typeName; }
194 const std::string &Identifier() const { return identifier; }
197 std::string typeName;
198 std::string identifier;
204 : public Declaration {
207 Definition(const std::string &typeName, const std::string &identifier)
208 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
209 virtual ~Definition();
211 Definition(const Definition &);
212 Definition &operator =(const Definition &);
215 void SetValue(Literal *);
216 void SetValue(PropertyList *);
218 bool HasLiteralValue() const { return isLiteral && value; }
219 bool HasProperties() const { return !isLiteral && value; }
220 Literal *GetLiteral();
221 const Literal *GetLiteral() const;
222 PropertyList *GetProperties();
223 const PropertyList *GetProperties() const;
238 ParsedSource(const ParsedSource &);
239 ParsedSource &operator =(const ParsedSource &);
242 void AddDeclaration(Declaration *);
243 void AddDefinition(Definition *);
244 void ExportDeclaration(Declaration *);
245 void ExportIdentifier(const std::string &);
247 bool IsDeclared(const std::string &) const;
248 Declaration &GetDeclaration(const std::string &);
249 const Declaration &GetDeclaration(const std::string &) const;
250 bool IsDefined(const std::string &) const;
251 Definition &GetDefinition(const std::string &);
252 const Definition &GetDefinition(const std::string &) const;
254 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
255 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
256 const std::set<std::string> &Exports() const { return exports; }
259 void WriteHeader(std::ostream &) const;
262 std::map<std::string, Declaration *> declarations;
263 std::map<std::string, Definition *> definitions;
264 std::set<std::string> exports;
273 ostream &operator <<(ostream &, const loader::ParsedSource &);
274 ostream &operator <<(ostream &, const loader::Literal &);
278 #endif /* LOADER_PARSEDSOURCE_H_ */