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) { }
85 std::string identifier;
97 void SetProperty(const std::string &name, Value *value) {
102 std::map<std::string, Value *> props;
110 Declaration(const std::string &typeName, const std::string &identifier)
111 : typeName(typeName), identifier(identifier) { }
112 virtual ~Declaration() { }
115 const std::string &TypeName() const { return typeName; }
116 const std::string &Identifier() const { return identifier; }
119 std::string typeName;
120 std::string identifier;
126 : public Declaration {
129 Definition(const std::string &typeName, const std::string &identifier)
130 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
133 void SetValue(Literal *);
134 void SetValue(PropertyList *);
136 bool HasLiteralValue() const { return isLiteral && value; }
137 bool HasProperties() const { return !isLiteral && value; }
138 Literal *GetLiteral();
139 const Literal *GetLiteral() const;
140 PropertyList *GetProperties();
141 const PropertyList *GetProperties() const;
157 void AddDeclaration(Declaration *);
158 void AddDefinition(Definition *);
159 void ExportDeclaration(Declaration *);
160 void ExportIdentifier(const std::string &);
162 bool IsDeclared(const std::string &) const;
163 Declaration &GetDeclaration(const std::string &);
164 const Declaration &GetDeclaration(const std::string &) const;
165 bool IsDefined(const std::string &) const;
166 Definition &GetDefinition(const std::string &);
167 const Definition &GetDefinition(const std::string &) const;
169 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
170 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
171 const std::set<std::string> &Exports() const { return exports; }
174 std::map<std::string, Declaration *> declarations;
175 std::map<std::string, Definition *> definitions;
176 std::set<std::string> exports;
185 ostream &operator <<(ostream &, const loader::ParsedSource &);
186 ostream &operator <<(ostream &, const loader::Literal &);
190 #endif /* LOADER_PARSEDSOURCE_H_ */