4 * Created on: Aug 26, 2012
8 #ifndef LOADER_PARSEDSOURCE_H_
9 #define LOADER_PARSEDSOURCE_H_
37 explicit Literal(const std::vector<Value *> &);
38 explicit Literal(const std::vector<PropertyList *> &);
39 explicit Literal(bool);
40 Literal(int r, int g, int b, int a = 255);
41 explicit Literal(int number);
42 Literal(const std::string &);
43 Literal(int x, int y);
44 Literal(const std::string &typeName, PropertyList *properties);
47 Literal(const Literal &);
48 Literal &operator =(const Literal &);
51 Type GetType() const { return type; }
53 const std::vector<Value *> &GetValues() const;
54 const std::vector<PropertyList *> &GetPropertyLists() const;
55 bool GetBoolean() const;
60 int GetNumber() const;
61 const std::string &GetString() const;
64 const std::string &GetTypeName() const;
65 const PropertyList *GetProperties() const;
70 std::vector<Value *> values;
71 std::vector<PropertyList *> propertyLists;
82 explicit Value(const std::string &identifier)
83 : literal(0), identifier(identifier), isLiteral(false) { }
84 explicit Value(Literal *literal)
85 : literal(literal), isLiteral(true) { }
89 Value &operator =(const Value &);
92 bool IsLiteral() const { return isLiteral; }
93 const Literal &GetLiteral() const;
94 const std::string &GetIdentifier() const;
98 std::string identifier;
110 PropertyList(const PropertyList &);
111 PropertyList &operator =(const PropertyList &);
114 void SetProperty(const std::string &name, Value *value) {
118 typedef std::map<std::string, Value *>::iterator Iterator;
119 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
120 Iterator Begin() { return props.begin(); }
121 ConstIterator Begin() const { return props.begin(); }
122 Iterator End() { return props.end(); }
123 ConstIterator End() const { return props.end(); }
126 std::map<std::string, Value *> props;
134 Declaration(const std::string &typeName, const std::string &identifier)
135 : typeName(typeName), identifier(identifier) { }
136 virtual ~Declaration() { }
138 Declaration(const Declaration &);
139 Declaration &operator =(const Declaration &);
142 const std::string &TypeName() const { return typeName; }
143 const std::string &Identifier() const { return identifier; }
146 std::string typeName;
147 std::string identifier;
153 : public Declaration {
156 Definition(const std::string &typeName, const std::string &identifier)
157 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
158 virtual ~Definition();
160 Definition(const Definition &);
161 Definition &operator =(const Definition &);
164 void SetValue(Literal *);
165 void SetValue(PropertyList *);
167 bool HasLiteralValue() const { return isLiteral && value; }
168 bool HasProperties() const { return !isLiteral && value; }
169 Literal *GetLiteral();
170 const Literal *GetLiteral() const;
171 PropertyList *GetProperties();
172 const PropertyList *GetProperties() const;
187 ParsedSource(const ParsedSource &);
188 ParsedSource &operator =(const ParsedSource &);
191 void AddDeclaration(Declaration *);
192 void AddDefinition(Definition *);
193 void ExportDeclaration(Declaration *);
194 void ExportIdentifier(const std::string &);
196 bool IsDeclared(const std::string &) const;
197 Declaration &GetDeclaration(const std::string &);
198 const Declaration &GetDeclaration(const std::string &) const;
199 bool IsDefined(const std::string &) const;
200 Definition &GetDefinition(const std::string &);
201 const Definition &GetDefinition(const std::string &) const;
203 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
204 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
205 const std::set<std::string> &Exports() const { return exports; }
208 std::map<std::string, Declaration *> declarations;
209 std::map<std::string, Definition *> definitions;
210 std::set<std::string> exports;
219 ostream &operator <<(ostream &, const loader::ParsedSource &);
220 ostream &operator <<(ostream &, const loader::Literal &);
224 #endif /* LOADER_PARSEDSOURCE_H_ */