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 Type GetType() const { return type; }
49 const std::vector<Value *> &GetValues() const;
50 const std::vector<PropertyList *> &GetPropertyLists() const;
51 bool GetBoolean() const;
56 int GetNumber() const;
57 const std::string &GetString() const;
60 const std::string &GetTypeName() const;
61 const PropertyList *GetProperties() const;
66 std::vector<Value *> values;
67 std::vector<PropertyList *> propertyLists;
78 explicit Value(const std::string &identifier)
79 : literal(0), identifier(identifier), isLiteral(false) { }
80 explicit Value(Literal *literal)
81 : literal(literal), isLiteral(false) { }
84 bool IsLiteral() const { return isLiteral; }
85 const Literal &GetLiteral() const;
86 const std::string &GetIdentifier() const;
90 std::string identifier;
102 void SetProperty(const std::string &name, Value *value) {
106 typedef std::map<std::string, Value *>::iterator Iterator;
107 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
108 Iterator Begin() { return props.begin(); }
109 ConstIterator Begin() const { return props.begin(); }
110 Iterator End() { return props.end(); }
111 ConstIterator End() const { return props.end(); }
114 std::map<std::string, Value *> props;
122 Declaration(const std::string &typeName, const std::string &identifier)
123 : typeName(typeName), identifier(identifier) { }
124 virtual ~Declaration() { }
127 const std::string &TypeName() const { return typeName; }
128 const std::string &Identifier() const { return identifier; }
131 std::string typeName;
132 std::string identifier;
138 : public Declaration {
141 Definition(const std::string &typeName, const std::string &identifier)
142 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
145 void SetValue(Literal *);
146 void SetValue(PropertyList *);
148 bool HasLiteralValue() const { return isLiteral && value; }
149 bool HasProperties() const { return !isLiteral && value; }
150 Literal *GetLiteral();
151 const Literal *GetLiteral() const;
152 PropertyList *GetProperties();
153 const PropertyList *GetProperties() const;
169 void AddDeclaration(Declaration *);
170 void AddDefinition(Definition *);
171 void ExportDeclaration(Declaration *);
172 void ExportIdentifier(const std::string &);
174 bool IsDeclared(const std::string &) const;
175 Declaration &GetDeclaration(const std::string &);
176 const Declaration &GetDeclaration(const std::string &) const;
177 bool IsDefined(const std::string &) const;
178 Definition &GetDefinition(const std::string &);
179 const Definition &GetDefinition(const std::string &) const;
181 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
182 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
183 const std::set<std::string> &Exports() const { return exports; }
186 std::map<std::string, Declaration *> declarations;
187 std::map<std::string, Definition *> definitions;
188 std::set<std::string> exports;
197 ostream &operator <<(ostream &, const loader::ParsedSource &);
198 ostream &operator <<(ostream &, const loader::Literal &);
202 #endif /* LOADER_PARSEDSOURCE_H_ */