String stateName = null;
boolean stateError = false;
for (Module m2 : g.modules) {
// Process stateful attribute.
if (m2.hasAttribute(Constants.ATT_STATEFUL.getName())) {
Attribute state =
Attribute.get(Constants.ATT_STATEFUL.getName(), m2.attributes);
Object value = state.getValue();
if ((null != value) &&
(value instanceof String) &&
(! ((String)value).startsWith("\""))) {
if (null == stateName) {
attributes.add(state);
stateName = (String)state.getValue();
}
if (! stateName.equals(state.getValue())) {
stateError = true;
}
}
}
// Process set and flag attributes.
if (m2.hasAttribute(Constants.NAME_STRING_SET) ||
m2.hasAttribute(Constants.NAME_FLAG)) {
for (Attribute att : m2.attributes) {
String name = att.getName();
if ((Constants.NAME_STRING_SET.equals(name) ||
Constants.NAME_FLAG.equals(name)) &&
(! attributes.contains(att))) {
attributes.add(att);
}
}
}
}
// Now, do the actual well-formedness checking.
Set<ModuleName> visited = new HashSet<ModuleName>();
boolean hasTopLevel = false;
for (Module m2 : g.modules) {
analyzer.process(m2);
hasState = false;
isMofunctor = (null != m2.modification);
if (null != m2.attributes) {
final int length = m2.attributes.size();
for (int i=0; i<length; i++) {
Attribute att = m2.attributes.get(i);
String name = att.getName();
Object value = att.getValue();
if ((! Constants.ATT_WITH_LOCATION.equals(att)) &&
(! Constants.ATT_CONSTANT.equals(att)) &&
(! Constants.ATT_RAW_TYPES.equals(att)) &&
(! Constants.ATT_VERBOSE.equals(att)) &&
(! Constants.ATT_NO_WARNINGS.equals(att)) &&
(! Constants.ATT_IGNORING_CASE.equals(att)) &&
(! Constants.ATT_STATEFUL.getName().equals(name)) &&
(! Constants.NAME_PARSER.equals(name)) &&
(! Constants.NAME_MAIN.equals(name)) &&
(! Constants.NAME_PRINTER.equals(name)) &&
(! Constants.NAME_VISIBILITY.equals(name)) &&
(! Constants.NAME_STRING_SET.equals(name)) &&
(! Constants.NAME_FLAG.equals(name)) &&
(! Constants.NAME_FACTORY.equals(name)) &&
(! Constants.ATT_FLATTEN.equals(att)) &&
(! Constants.ATT_GENERIC_AS_VOID.equals(att)) &&
(! Constants.ATT_PARSE_TREE.equals(att)) &&
(! Constants.ATT_PROFILE.equals(att)) &&
(! Constants.ATT_DUMP.equals(att))) {
runtime.error("unrecognized grammar-wide attribute '"+att+"'", att);
} else {
for (int j=0; j<i; j++) {
Attribute att2 = m2.attributes.get(j);
if (name.equals(Constants.NAME_STRING_SET) ||
name.equals(Constants.NAME_FLAG)) {
if (att.equals(att2)) {
runtime.error("duplicate attribute '"+att+"'", att);
break;
} else if ((null != value) && value.equals(att2.getValue())) {
runtime.error("duplicate field name '" + att + "'", att);
}
} else if (name.equals(att2.getName())) {
runtime.error("duplicate attribute '" + name + "'", att);
break;
}
}
}