-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
=
committed
Aug 19, 2018
1 parent
6c77abb
commit 4707702
Showing
33 changed files
with
146 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
snap-core/src/main/java/org/snapscript/core/constraint/transform/AttributeRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.snapscript.core.constraint.transform; | ||
|
||
import java.util.List; | ||
|
||
import org.snapscript.core.Bug; | ||
import org.snapscript.core.attribute.Attribute; | ||
import org.snapscript.core.constraint.Constraint; | ||
import org.snapscript.core.convert.InstanceOfChecker; | ||
import org.snapscript.core.error.InternalStateException; | ||
import org.snapscript.core.scope.Scope; | ||
import org.snapscript.core.scope.State; | ||
import org.snapscript.core.scope.index.Table; | ||
import org.snapscript.core.type.Type; | ||
|
||
public class AttributeRule implements ConstraintRule { | ||
|
||
private final InstanceOfChecker checker; | ||
private final Attribute attribute; | ||
private final ConstraintRule rule; | ||
|
||
public AttributeRule(ConstraintRule rule, Attribute attribute) { | ||
this.checker = new InstanceOfChecker(); | ||
this.attribute = attribute; | ||
this.rule = rule; | ||
} | ||
|
||
@Bug | ||
@Override | ||
public Constraint getResult(Scope scope, Constraint returns) { | ||
List<Constraint> defaults = attribute.getGenerics(); | ||
int count = defaults.size(); | ||
|
||
if(count > 0) { | ||
Table table = scope.getTable(); | ||
State state = scope.getState(); | ||
Constraint first = table.getConstraint(0); | ||
|
||
for(int i = 0; i < count; i++) { | ||
Constraint parameter = table.getConstraint(i); | ||
Constraint constraint = defaults.get(i); | ||
String name = constraint.getName(scope); | ||
|
||
if(parameter != null) { | ||
Type require = constraint.getType(scope); | ||
Type actual = parameter.getType(scope); | ||
|
||
if(!checker.isInstanceOf(scope, actual, require)) { | ||
throw new InternalStateException("Generic parameter '" + name +"' is does not match '" + constraint + "'"); | ||
} | ||
state.addConstraint(name, parameter); | ||
} else { | ||
if(first != null) { | ||
throw new InternalStateException("Generic parameter '" + name +"' not specified"); | ||
} | ||
state.addConstraint(name, constraint); | ||
} | ||
} | ||
} | ||
return rule.getResult(scope, returns); | ||
} | ||
|
||
@Override | ||
public Constraint getSource() { | ||
return rule.getSource(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.