package org.simantics.scl.compiler.elaboration.contexts;
-import gnu.trove.list.array.TIntArrayList;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Arrays;
import org.simantics.scl.compiler.common.precedence.Associativity;
import org.simantics.scl.compiler.common.precedence.Precedence;
import org.simantics.scl.compiler.elaboration.expressions.Case;
+import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
import org.simantics.scl.compiler.elaboration.expressions.EEntityTypeAnnotation;
import org.simantics.scl.compiler.elaboration.expressions.EError;
import org.simantics.scl.compiler.errors.ErrorLog;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.parsing.declarations.DValueAst;
+import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
+import org.simantics.scl.compiler.types.Type;
+
+import gnu.trove.list.array.TIntArrayList;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
public class TranslationContext extends TypeTranslationContext implements EnvironmentalContext {
}
private Expression resolveIn(long location, Namespace namespace, String name) {
- SCLValue value = resolveValueIn(location, namespace, name);
+ SCLValue value;
+ try {
+ value = resolveValueIn(location, namespace, name);
+ } catch (AmbiguousNameException e) {
+ if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
+ EAmbiguous.Alternative[] alternatives = new EAmbiguous.Alternative[e.conflictingModules.length];
+ //System.out.println("Overloading:");
+ for(int i=0;i<e.conflictingModules.length;++i) {
+ Name altName = Name.create(e.conflictingModules[i], e.name);
+ //System.out.println(" " + altName);
+ SCLValue altValue = environment.getValue(altName);
+ alternatives[i] = new EAmbiguous.Alternative() {
+ @Override
+ public Type getType() {
+ return altValue.getType();
+ }
+
+ @Override
+ public Expression realize() {
+ EConstant expression = new EConstant(altValue);
+ expression.location = location;
+ return expression;
+ }
+
+ @Override
+ public String toString() {
+ return altValue.getName().toString().replace('/', '.');
+ }
+ };
+ }
+ EAmbiguous expression = new EAmbiguous(alternatives);
+ expression.location = location;
+ return expression;
+ }
+ else {
+ errorLog.log(location, e.getMessage());
+ value = null;
+ }
+ }
if(value == null)
return new EError(location);
return new EConstant(location, value);
return prec;
}
- private SCLValue resolveValueIn(long location, Namespace namespace, final String name) {
- try {
+ private SCLValue resolveValueIn(long location, Namespace namespace, final String name) throws AmbiguousNameException {
SCLValue value = namespace.getValue(name);
if(value == null) {
StringBuilder message = new StringBuilder();
return null;
}
return value;
- } catch (AmbiguousNameException e) {
- errorLog.log(location, e.getMessage());
- return null;
- }
}
public Case translateCase(Expression lhs, Expression rhs) {