4 * Created on: Aug 26, 2012
8 #ifndef LOADER_PARSEDSOURCE_H_
9 #define LOADER_PARSEDSOURCE_H_
32 ScriptToken(const std::string &, Type);
33 explicit ScriptToken(Literal *);
36 ScriptToken(const ScriptToken &);
37 ScriptToken &operator =(const ScriptToken &);
40 Type GetType() const { return type; }
41 const std::string &RegisterName() const;
42 const std::string &CommandName() const;
43 const std::string &Identifier() const;
44 const std::string &Label() const;
45 const Literal *GetLiteral() const;
72 explicit Literal(const std::vector<Value *> &);
73 Literal(const std::string &, const std::vector<PropertyList *> &);
74 explicit Literal(bool);
75 Literal(int r, int g, int b, int a = 255);
76 explicit Literal(int number);
77 Literal(const std::string &dir, const std::string &path);
78 Literal(const std::string &);
79 Literal(int x, int y);
80 Literal(const std::string &typeName, PropertyList *properties);
81 explicit Literal(const std::vector<ScriptToken *> &);
84 Literal(const Literal &);
85 Literal &operator =(const Literal &);
88 Type GetType() const { return type; }
89 bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS; }
90 bool IsObject() const { return GetType() == OBJECT; }
91 int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size() : GetPropertyLists().size(); }
93 const std::vector<Value *> &GetValues() const;
94 const std::vector<PropertyList *> &GetPropertyLists() const;
95 bool GetBoolean() const;
100 int GetNumber() const;
101 const std::string &GetString() const;
104 const std::string &GetTypeName() const;
105 const PropertyList *GetProperties() const;
106 const std::vector<ScriptToken *> &GetScript() const;
110 std::string typeName, str;
111 std::vector<Value *> values;
112 std::vector<PropertyList *> propertyLists;
113 std::vector<ScriptToken *> script;
124 explicit Value(const std::string &identifier)
125 : literal(0), identifier(identifier), isLiteral(false) { }
126 explicit Value(Literal *literal)
127 : literal(literal), isLiteral(true) { }
130 Value(const Value &);
131 Value &operator =(const Value &);
134 bool IsLiteral() const { return isLiteral; }
135 const Literal &GetLiteral() const;
136 const std::string &GetIdentifier() const;
140 std::string identifier;
152 PropertyList(const PropertyList &);
153 PropertyList &operator =(const PropertyList &);
156 void SetProperty(const std::string &name, Value *value) {
160 typedef std::map<std::string, Value *>::iterator Iterator;
161 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
162 Iterator Begin() { return props.begin(); }
163 ConstIterator Begin() const { return props.begin(); }
164 Iterator End() { return props.end(); }
165 ConstIterator End() const { return props.end(); }
168 std::map<std::string, Value *> props;
176 Declaration(const std::string &typeName, const std::string &identifier)
177 : typeName(typeName), identifier(identifier) { }
178 virtual ~Declaration() { }
180 Declaration(const Declaration &);
181 Declaration &operator =(const Declaration &);
184 const std::string &TypeName() const { return typeName; }
185 const std::string &Identifier() const { return identifier; }
188 std::string typeName;
189 std::string identifier;
195 : public Declaration {
198 Definition(const std::string &typeName, const std::string &identifier)
199 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
200 virtual ~Definition();
202 Definition(const Definition &);
203 Definition &operator =(const Definition &);
206 void SetValue(Literal *);
207 void SetValue(PropertyList *);
209 bool HasLiteralValue() const { return isLiteral && value; }
210 bool HasProperties() const { return !isLiteral && value; }
211 Literal *GetLiteral();
212 const Literal *GetLiteral() const;
213 PropertyList *GetProperties();
214 const PropertyList *GetProperties() const;
229 ParsedSource(const ParsedSource &);
230 ParsedSource &operator =(const ParsedSource &);
233 void AddDeclaration(Declaration *);
234 void AddDefinition(Definition *);
235 void ExportDeclaration(Declaration *);
236 void ExportIdentifier(const std::string &);
238 bool IsDeclared(const std::string &) const;
239 Declaration &GetDeclaration(const std::string &);
240 const Declaration &GetDeclaration(const std::string &) const;
241 bool IsDefined(const std::string &) const;
242 Definition &GetDefinition(const std::string &);
243 const Definition &GetDefinition(const std::string &) const;
245 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
246 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
247 const std::set<std::string> &Exports() const { return exports; }
250 void WriteHeader(std::ostream &) const;
253 std::map<std::string, Declaration *> declarations;
254 std::map<std::string, Definition *> definitions;
255 std::set<std::string> exports;
264 ostream &operator <<(ostream &, const loader::ParsedSource &);
265 ostream &operator <<(ostream &, const loader::Literal &);
269 #endif /* LOADER_PARSEDSOURCE_H_ */