8 #include <boost/foreach.hpp>
9 #include <boost/lexical_cast.hpp>
10 #include <boost/format.hpp>
11 #include <boost/shared_ptr.hpp>
26 namespace gp = Gaudi::Parsers;
30 gp::IncludedFiles* included, gp::Messages* messages) {
31 gp::Node include_root;
32 bool status =
gp::Parse(node->position, node->value, search_path, included,
33 messages, &include_root);
35 node->value = include_root.value;
36 BOOST_FOREACH(
const gp::Node& child, include_root.children) {
37 node->children.push_back(child);
47 gp::IncludedFiles* included, gp::Messages* messages) {
49 bool status =
gp::ParseUnits(node->position, node->value, search_path,
50 included, messages, &units_root);
52 node->value = units_root.value;
53 BOOST_FOREACH(
const gp::Node& child, units_root.children) {
54 node->children.push_back(child);
63 gp::PropertyName::ScopedPtr& property_name) {
64 if (node->children.size() == 1) {
65 property_name.reset(
new gp::PropertyName(node->children[0].value,
70 for(
unsigned int i=0;
i < (node->children.size() - 1);
i++) {
71 client += delim+node->children[
i].value;
74 property_name.reset(
new gp::PropertyName(client,
75 node->children[node->children.size() - 1].value, node->position));
80 gp::PropertyValue::ScopedPtr& value, gp::Catalog* catalog,
84 case gp::Node::kReal: {
90 if (node->children.size() == 1) {
93 double unit_value = 0;
94 if (units->Find(unit_name, unit_value)) {
96 double val = boost::lexical_cast<
double>(node->value);
99 value.reset(
new gp::PropertyValue(store));
103 gp::PositionalPropertyValueException::CouldNotFindUnit(
104 node->children[0].position, unit_name);
107 value.reset(
new gp::PropertyValue(node->value));
112 case gp::Node::kString: {
113 value.reset(
new gp::PropertyValue(
'"'+node->value+
'"'));
117 case gp::Node::kBool: {
118 value.reset(
new gp::PropertyValue(node->value));
122 case gp::Node::kVector: {
124 BOOST_FOREACH(
const gp::Node& child, node->children) {
125 gp::PropertyValue::ScopedPtr vvalue;
129 value.reset(
new gp::PropertyValue(result));
133 case gp::Node::kMap: {
135 BOOST_FOREACH(
const gp::Node& child, node->children) {
136 gp::PropertyValue::ScopedPtr kvalue;
137 gp::PropertyValue::ScopedPtr vvalue;
143 vvalue->ToString()));
145 value.reset(
new gp::PropertyValue(result));
149 case gp::Node::kProperty: {
150 gp::PropertyName::ScopedPtr property;
152 gp::Property* exists = NULL;
153 if (NULL != (exists = catalog->Find(property->client(),
154 property->property()))) {
155 value.reset(
new gp::PropertyValue(exists->property_value()));
158 gp::PositionalPropertyValueException::CouldNotFindProperty(
159 node->position,property->ToString());
163 case gp::Node::kPropertyRef: {
164 gp::PropertyName::ScopedPtr property;
169 reference.
push_back(property->property());
171 value.reset(
new gp::PropertyValue(reference,property->position(),
186 case gp::Node::kEqual : {
190 case gp::Node::kPlusEqual : {
194 case gp::Node::kMinusEqual : {
207 gp::Messages* messages, gp::Catalog* catalog, gp::Units* units,
210 gp::PropertyName::ScopedPtr property;
211 gp::PropertyValue::ScopedPtr value;
216 }
catch(
const gp::PositionalPropertyValueException& ex){
217 messages->AddError(ex.position(), ex.what());
221 gp::Property* exists = NULL;
222 bool reassign =
false;
224 if (NULL != (exists = catalog->Find(property->client(),
225 property->property()))) {
230 if (node->children[1].type == gp::Node::kEqual) {
232 % property->FullName());
233 if (exists->HasDefinedPosition()) {
234 message +=
" Previously defined at " +
235 exists->DefinedPosition().ToString() +
".";
240 }
else if (node->children[1].type == gp::Node::kPlusEqual) {
242 }
else if (node->children[1].type == gp::Node::kMinusEqual) {
245 }
catch(
const gp::PropertyValueException& ex) {
247 if (exists->HasDefinedPosition()) {
248 message +=
" Previously defined at "+exists->DefinedPosition().
251 messages->AddError(node->position, message);
257 if ( (NULL == exists) || reassign) {
258 result = catalog->Add(
new gp::Property(*property, *value));
261 if (result && is_print) {
263 % property->FullName()
265 % value->ToString());
266 messages->AddInfo(node->position, message);
272 gp::Messages* messages, gp::Units* units,
bool is_print) {
274 double left = boost::lexical_cast<
double>(node->children[0].value);
276 double right = boost::lexical_cast<
double>(node->children[2].value);
278 gp::Units::Container::mapped_type exists;
279 if (units->Find(name, exists)) {
282 if (exists.second.Exists()) {
283 message +=
" at "+exists.second.ToString();
285 messages->AddError(node->children[1].position, message);
289 bool result = units->Add(name, right / left, node->children[1].position);
290 if (result && is_print) {
295 messages->AddInfo(node->position, message);
301 gp::Catalog* catalog, gp::Node** next) {
303 gp::PropertyName::ScopedPtr property_name;
306 bool is_defined = (NULL != catalog->Find(property_name->client(),
307 property_name->property()));
309 if ((is_defined && (node->children[1].type == gp::Node::kIfdef))
310 || (!is_defined && (node->children[1].type == gp::Node::kIfndef))
312 *next = &node->children[1];
313 }
else if (node->children.size()>2){
314 *next = &node->children[2];
322 const std::string& search_path, gp::IncludedFiles* included,
323 gp::Messages* messages, gp::Catalog* catalog, gp::Units* units,
324 gp::PragmaOptions* pragma) {
327 bool local_result =
true;
328 bool skip_childs =
true;
329 gp::Node* next_root = node;
331 switch (node->type) {
333 case gp::Node::kRoot: {
338 case gp::Node::kInclude: {
339 local_result =
IncludeNode(node, search_path, included, messages);
344 case gp::Node::kUnits: {
345 local_result =
UnitsNode(node, search_path, included, messages);
350 case gp::Node::kAssign: {
351 local_result =
AssignNode(node, messages, catalog, units,
356 case gp::Node::kUnit: {
357 local_result =
UnitNode(node, messages, units, pragma->is_print());
361 case gp::Node::kCondition: {
367 case gp::Node::kPrintOptions: {
368 pragma->setIsPrintOptions(
true);
372 case gp::Node::kPrintOn : {
373 pragma->setIsPrint(
true);
377 case gp::Node::kPrintOff : {
378 pragma->setIsPrint(
false);
382 case gp::Node::kPrintTree : {
383 pragma->setIsPrintTree(
true);
387 case gp::Node::kDumpFile : {
390 pragma->setDumpFile(file);
392 pragma->setDumpFile(node->value);
401 if (result) result = local_result;
403 if (!skip_childs && (next_root!=NULL)) {
404 BOOST_FOREACH(gp::Node& child, next_root->children) {
406 Analyze(&child, search_path, included, messages, catalog, units,
408 if (result) result = local_result;
415 bool unreference_result =
true;
416 BOOST_FOREACH(gp::Catalog::value_type& client, catalog) {
417 for (gp::Catalog::CatalogSet::mapped_type::iterator current
418 = client.second.begin(); current != client.second.end();
420 if (current->IsReference()) {
421 gp::PropertyValue& value = current->property_value();
424 gp::Property*
property = catalog.Find(names[0], names[1]);
425 if (NULL == property) {
426 messages->AddError(value.position(),
427 "Could not unreference " + current->ValueAsString());
428 unreference_result =
false;
430 value =
property->property_value();
435 return unreference_result;
444 bool result =
Parse(filename, search_path, &included, messages, root);
445 if (!result)
return false;
447 bool result1 =
Analyze(root, search_path, &included, messages, catalog, units,
450 return result1 && result2;