import java.util.function.Consumer;
import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.compilation.CompilationContext;
+import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
-import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
import org.simantics.scl.compiler.elaboration.modules.TypeClass;
-import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
+import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
import org.simantics.scl.compiler.elaboration.relations.SCLEntityType;
import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
-import org.simantics.scl.compiler.errors.ErrorLog;
import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException;
import org.simantics.scl.compiler.internal.parsing.parser.SCLParserImpl;
* @return A TypeConstructor instance, or null if not found.
* @throws AmbiguousNameException if the same name is found in multiple imported modules.
*/
- public static TypeConstructor getTypeConstructor(Environment environment, String localName) throws AmbiguousNameException {
- return getEnvironmentEntry(environment, localName, getTypeConstructor);
+ public static TypeDescriptor getTypeDescriptor(Environment environment, String localName) throws AmbiguousNameException {
+ return getEnvironmentEntry(environment, localName, getTypeDescriptor);
}
/**
public static TypeClass getTypeClass(Environment environment, String localName) throws AmbiguousNameException {
return getEnvironmentEntry(environment, localName, getTypeClass);
}
-
- /**
- * Get the TypeAlias object representing a type alias defined in a given environment.
- * The name can be a local name or a fully scoped name with modules separated by periods.
- * @param environment the environment
- * @param localName the name to be searched for
- * @return A TypeAlias instance, or null if not found.
- * @throws AmbiguousNameException if the same name is found in multiple imported modules.
- */
- public static TypeAlias getTypeAlias(Environment environment, String localName) throws AmbiguousNameException {
- return getEnvironmentEntry(environment, localName, getTypeAlias);
- }
+ public static CHRRuleset getRuleset(Environment environment, String localName) throws AmbiguousNameException {
+ return getEnvironmentEntry(environment, localName, getRuleset);
+ }
+
/**
* Get the Name object representing an SCL value defined in a given environment.
* The name can be a local name or a fully scoped name with modules separated by periods.
* @return A TCon instance, or null if not found.
* @throws AmbiguousNameException if the same name is used in multiple imported modules.
*/
- public static TCon getTypeConstructorName(Environment environment, String localName) throws AmbiguousNameException {
- TypeConstructor typeConstructor = getTypeConstructor(environment, localName);
- if(typeConstructor == null)
+ public static TCon getTypeDescriptorName(Environment environment, String localName) throws AmbiguousNameException {
+ TypeDescriptor typeDescriptor = getTypeDescriptor(environment, localName);
+ if(typeDescriptor == null)
return null;
else
- return typeConstructor.name;
+ return typeDescriptor.name;
}
/**
*/
public static Type getType(Environment environment, String typeText) throws SCLExpressionCompilationException {
SCLParserImpl parser = new SCLParserImpl(new StringReader(typeText));
- ErrorLog errorLog = new ErrorLog();
+ CompilationContext compilationContext = new CompilationContext();
+ compilationContext.environment = environment;
try {
TypeAst typeAst = (TypeAst)parser.parseType();
- TypeTranslationContext context = new TypeTranslationContext(errorLog, environment);
+ TypeTranslationContext context = new TypeTranslationContext(compilationContext);
Type type = context.toType(typeAst);
- if(errorLog.isEmpty())
+ if(compilationContext.errorLog.hasNoErrors())
return type;
} catch(SCLSyntaxErrorException e) {
- errorLog.log(e.location, e.getMessage());
+ compilationContext.errorLog.log(e.location, e.getMessage());
} catch(Exception e) {
- errorLog.log(e);
+ compilationContext.errorLog.log(e);
}
- throw new SCLExpressionCompilationException(errorLog.getErrors());
+ throw new SCLExpressionCompilationException(compilationContext.errorLog.getErrors());
}
/**
Namespace childNamespace = namespace.getNamespace(prefix.substring(0, p));
if(childNamespace != null)
findValuesForPrefix(childNamespace, prefix.substring(p+1), proc);
+ else
+ namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
}
else
namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
}
};
- private static final NamespaceValueAccessor<TypeConstructor> getTypeConstructor = new NamespaceValueAccessor<TypeConstructor>() {
+ private static final NamespaceValueAccessor<TypeDescriptor> getTypeDescriptor = new NamespaceValueAccessor<TypeDescriptor>() {
@Override
- public TypeConstructor get(Namespace ns, String name) throws AmbiguousNameException {
- return ns.getTypeConstructor(name);
+ public TypeDescriptor get(Namespace ns, String name) throws AmbiguousNameException {
+ return ns.getTypeDescriptor(name);
}
};
return ns.getTypeClass(name);
}
};
-
- private static final NamespaceValueAccessor<TypeAlias> getTypeAlias = new NamespaceValueAccessor<TypeAlias>() {
- @Override
- public TypeAlias get(Namespace ns, String name) throws AmbiguousNameException {
- return ns.getTypeAlias(name);
- }
- };
+
+ private static final NamespaceValueAccessor<CHRRuleset> getRuleset = new NamespaceValueAccessor<CHRRuleset>() {
+ @Override
+ public CHRRuleset get(Namespace ns, String name) throws AmbiguousNameException {
+ return ns.getRuleset(name);
+ }
+ };
private static <T> T getEnvironmentEntry(Environment environment, String localName, NamespaceValueAccessor<T> accessor) throws AmbiguousNameException {
Namespace namespace = environment.getLocalNamespace();
int pos = localName.indexOf('.', curPos);
if(pos < 0)
return accessor.get(namespace, localName.substring(curPos));
- namespace = namespace.getNamespace(localName.substring(curPos, pos));
- if(namespace == null)
- return null;
+ Namespace newNamespace = namespace.getNamespace(localName.substring(curPos, pos));
+ if(newNamespace == null)
+ return accessor.get(namespace, localName.substring(curPos));
+ namespace = newNamespace;
curPos = pos + 1;
}
}