Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'private/issue/239' into 0.4-develop

  • Loading branch information...
commit 448decac76e01a94b65423e9effef38a5f7dfcaf 2 parents 4a79cc5 + 0338112
@akirakw akirakw authored
View
44 dmdl-project/asakusa-dmdl-core/src/main/java/com/asakusafw/dmdl/analyzer/DmdlAnalyzer.java
@@ -15,7 +15,9 @@
*/
package com.asakusafw.dmdl.analyzer;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -524,27 +526,30 @@ private PropertyMappingKind resolveAggregateFunction(AstName aggregator) {
}
boolean green = true;
- List<PropertySymbol> first = iter.next().getGrouping();
+ ReduceTerm<T> first = iter.next();
+ List<PropertyDeclaration> firstSources = resolveGroupingSources(first);
while (iter.hasNext()) {
- ReduceTerm<T> term = iter.next();
- List<PropertySymbol> next = term.getGrouping();
- if (first.size() != next.size()) {
+ ReduceTerm<T> next = iter.next();
+ if (first.getGrouping().size() != next.getGrouping().size()) {
report(new Diagnostic(
Level.ERROR,
- term.getOriginalAst(),
+ next.getOriginalAst(),
"Each term in model \"{0}\" must have the same number of grouping properties",
model.getName()));
return false;
}
- for (int i = 0, n = first.size(); i < n; i++) {
- PropertySymbol left = first.get(i);
- PropertySymbol right = next.get(i);
- if (left.findDeclaration().getType().isSame(right.findDeclaration().getType()) == false) {
+ List<PropertyDeclaration> nextSources = resolveGroupingSources(next);
+ assert firstSources.size() == nextSources.size();
+ for (int i = 0, n = firstSources.size(); i < n; i++) {
+ PropertyDeclaration left = firstSources.get(i);
+ PropertyDeclaration right = nextSources.get(i);
+ if (left.getType().isSame(right.getType()) == false) {
+ PropertySymbol rightSymbol = next.getGrouping().get(i);
report(new Diagnostic(
Level.ERROR,
- right.getOriginalAst(),
+ rightSymbol.getOriginalAst(),
"Type mismatch in grouping property \"{0}\"",
- right.getName()));
+ rightSymbol.getName()));
green = false;
}
}
@@ -552,6 +557,23 @@ private PropertyMappingKind resolveAggregateFunction(AstName aggregator) {
return green;
}
+ private List<PropertyDeclaration> resolveGroupingSources(ReduceTerm<?> term) {
+ assert term != null;
+ Map<PropertySymbol, PropertySymbol> rmap = new HashMap<PropertySymbol, PropertySymbol>();
+ for (MappingFactor entry : term.getMappings()) {
+ rmap.put(entry.getTarget(), entry.getSource());
+ }
+ List<PropertyDeclaration> results = new ArrayList<PropertyDeclaration>();
+ for (PropertySymbol prop : term.getGrouping()) {
+ PropertySymbol source = rmap.get(prop);
+ if (source == null) {
+ source = prop;
+ }
+ results.add(source.findDeclaration());
+ }
+ return results;
+ }
+
private void resolveAttributes() {
for (ModelDeclaration model : context.getWorld().getDeclaredModels()) {
LOG.debug("Resolving attributes: {}", model.getName());
View
8 dmdl-project/asakusa-dmdl-core/src/test/java/com/asakusafw/dmdl/analyzer/DmdlAnalyzerTest.java
@@ -306,6 +306,14 @@ public void invalid_inconsistent_group_type() {
}
/**
+ * grouping properties in each term has inconsistent type but both are unified.
+ */
+ @Test
+ public void invalid_inconsistent_group_type_unified() {
+ shouldSemanticError();
+ }
+
+ /**
* duplicate joined property in same term.
*/
@Test
View
3  ...usa-dmdl-core/src/test/resources/com/asakusafw/dmdl/analyzer/invalid_inconsistent_group_type_unified.txt
@@ -0,0 +1,3 @@
+a = { a : INT; b : INT; };
+b = { c : TEXT; d : LONG; };
+joined simple = a % a + b -> { c -> a; } % a;
Please sign in to comment.
Something went wrong with that request. Please try again.