X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcompilation%2FElaboration.java;h=621c97684b86348be9d5bd11f331c0185e0635df;hp=26bd31ec26cb96beebcac814e8dbce8c49b05212;hb=HEAD;hpb=db54e4ca935111cfe3574a01bb9be3cf083258cc diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index 26bd31ec2..621c97684 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -12,11 +12,12 @@ import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.constants.JavaTypeInstanceConstructor; import org.simantics.scl.compiler.constants.SCLConstructor; import org.simantics.scl.compiler.constants.StringConstant; +import org.simantics.scl.compiler.constants.componentaccess.ComponentAccess; +import org.simantics.scl.compiler.constants.componentaccess.FieldComponentAccess; import org.simantics.scl.compiler.constants.generic.CallJava; import org.simantics.scl.compiler.constants.generic.ClassRef; import org.simantics.scl.compiler.constants.generic.ConvertToListFilter; import org.simantics.scl.compiler.constants.generic.MethodRef; -import org.simantics.scl.compiler.constants.generic.MethodRef.FieldRef; import org.simantics.scl.compiler.constants.generic.OutputFilter; import org.simantics.scl.compiler.constants.generic.ParameterStackItem; import org.simantics.scl.compiler.constants.generic.Pop2OutputFilter; @@ -104,6 +105,7 @@ import org.simantics.scl.compiler.module.ConcreteModule; import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.InvalidModulePathException; import org.simantics.scl.compiler.module.ModuleUtils; +import org.simantics.scl.compiler.module.debug.ModuleDebugInfo; import org.simantics.scl.compiler.module.repository.ImportFailure; import org.simantics.scl.compiler.module.repository.ImportFailureException; import org.simantics.scl.compiler.types.TCon; @@ -146,6 +148,8 @@ public class Elaboration { ArrayList dataTypes = new ArrayList(); THashMap classRefs = new THashMap(); THashMap branchPoints; + + THashMap exportMap = null; public Elaboration(CompilationContext compilationContext, CompilationTimer timer, EnvironmentFactory localEnvironmentFactory, String moduleName, ModuleHeader moduleHeader, ArrayList importsAst, @@ -156,7 +160,8 @@ public class Elaboration { this.errorLog = compilationContext.errorLog; this.moduleName = moduleName; this.moduleHeader = moduleHeader; - importsAst = processRelativeImports(importsAst); + if(moduleName != null) + importsAst = processRelativeImports(compilationContext.errorLog, moduleName, importsAst); this.importsAst = importsAst; this.jrvFactory = jrvFactory; this.javaReferenceValidator = moduleHeader == null || moduleHeader.classLoader == null @@ -187,7 +192,8 @@ public class Elaboration { compilationContext.environment = new EnvironmentOfModule(importedEnvironment, module); } catch (ImportFailureException e) { for(ImportFailure failure : e.failures) - errorLog.log(new CompilationError(failure.location, failure.toString(), ErrorSeverity.IMPORT_ERROR)); + errorLog.log(new CompilationError(failure.location, failure.toString(), + failure.reason == ImportFailure.MODULE_DOES_NOT_EXIST_REASON ? ErrorSeverity.ERROR : ErrorSeverity.IMPORT_ERROR)); return; } for(ImportDeclaration importAst : importsAst) @@ -200,7 +206,7 @@ public class Elaboration { compilationContext.namingPolicy = new JavaNamingPolicy(moduleName); } - private ArrayList processRelativeImports(ArrayList relativeImports) { + public static ArrayList processRelativeImports(ErrorLog errorLog, String moduleName, ArrayList relativeImports) { ArrayList absoluteImports = new ArrayList(relativeImports.size()); for(ImportDeclaration relativeImport : relativeImports) { if(relativeImport.moduleName.startsWith(".")) { @@ -212,7 +218,8 @@ public class Elaboration { relativeImport.reexport, relativeImport.spec); absoluteImports.add(absoluteImport); } catch (InvalidModulePathException e) { - errorLog.log(relativeImport.location, e.getMessage()); + if(errorLog != null) + errorLog.log(relativeImport.location, e.getMessage()); } } else @@ -367,7 +374,8 @@ public class Elaboration { } boolean trivialDataType = dataTypeAst.constructors.length == 1 && - dataTypeAst.constructors[0].parameters.length == 1; + dataTypeAst.constructors[0].parameters.length == 1 && + !external; if(className == null && !trivialDataType) className = compilationContext.namingPolicy.getDataTypeClassName(dataTypeAst.name); @@ -390,7 +398,7 @@ public class Elaboration { parameterTypes[i] = context.toType(constructor.parameters[i]); String javaName = constructors.length == 1 ? className : compilationContext.namingPolicy.getConstructorClassName(name); - String[] fieldNames = null; + ComponentAccess[] componentAccesses = null; for(DAnnotationAst annotation : constructor.annotations) if(annotation.id.text.equals("@JavaType")) { try { @@ -403,24 +411,24 @@ public class Elaboration { else if(annotation.id.text.equals("@FieldNames")) { try { EListLiteral literal = (EListLiteral)annotation.parameters[0]; - fieldNames = new String[literal.getComponents().length]; - for(int i=0;iemptyList()));*/ - supplementedTypeAnnotations.add(new SupplementedValueType(defs.get(0).location, fullName, method.getType())); + supplementedTypeAnnotations.add(new SupplementedValueType(defs.get(0).location, fullName, method.getType())); + valueDefinitionsAst.setDerived(fullName); } module.addTypeClass(classAst.name, typeClass); @@ -708,6 +718,8 @@ public class Elaboration { isPrivate = true; } } + if(exportMap != null) + isPrivate = exportMap.remove(name) == null; Type type = createTypeTranslationContext().toType(javaMethod.type); @@ -1074,7 +1086,7 @@ public class Elaboration { final THashMap sections = new THashMap(); - final TranslationContext context = createTranslationContext(); + final TranslationContext context = createTranslationContext(ruleName); if(length > 0) { THashMap variables = context.getVariables(); for(TransformationRule extendsRule : extendsRules) { @@ -1121,6 +1133,7 @@ public class Elaboration { int constructorTag = 0; for(Constructor constructor : dataType.constructors) { SCLValue value = new SCLValue(constructor.name); + value.parameterNames = constructor.recordFieldNames; value.definitionLocation = constructor.loc; SCLConstructor sclConstructor = new SCLConstructor( @@ -1129,10 +1142,9 @@ public class Elaboration { constructor.getTypeVariables(), constructorTag++, constructor.getReturnType(), - constructor.fieldNames == null + constructor.componentAccesses == null ? SCLConstructor.DEFAULT_FIELD_NAMES[constructor.getParameterTypes().length] - : constructor.fieldNames, - constructor.recordFieldNames, + : constructor.componentAccesses, constructor.getParameterTypes()); if(dataType.constructors.length == 1 && ( dataType.getTypeDesc() == null || @@ -1211,21 +1223,13 @@ public class Elaboration { typeMap.put(name.name, valueTypeAst); } - THashMap exportMap = null; - if(moduleHeader != null && moduleHeader.export != null) { - exportMap = new THashMap(); - for(EVar export : moduleHeader.export) - if(exportMap.put(export.name, export) != null) - errorLog.log(export.location, "The symbol " + export.name + " is exported multiple times."); - } - for(String name : valueDefinitionsAst.getValueNames()) { ArrayList defs = valueDefinitionsAst.getDefinition(name); if(defs.size() != 1 || !(defs.get(0).value instanceof EPreCHRRulesetConstructor)) continue; try { SCLValue value = module.getValue(name); - TranslationContext context = createTranslationContext(); + TranslationContext context = createTranslationContext(name); Expression expression = context.translateCases2(defs); value.setExpression(expression); @@ -1242,7 +1246,7 @@ public class Elaboration { continue; try { SCLValue value = module.getValue(name); - TranslationContext context = createTranslationContext(); + TranslationContext context = createTranslationContext(name); Expression expression = context.translateCases2(defs); value.setExpression(expression); @@ -1262,9 +1266,6 @@ public class Elaboration { throw e; } } - if(exportMap != null) - for(EVar export : exportMap.values()) - errorLog.log(export.location, "The symbol " + export.name + " is not defined in the module."); for(String name : relationDefinitionsAst.getRelationNames()) { ArrayList definitions = relationDefinitionsAst.getDefinition(name); if(definitions.size() > 1) { @@ -1276,13 +1277,13 @@ public class Elaboration { DRelationAst definition = definitions.get(0); ConcreteRelation relation = (ConcreteRelation)module.getRelation(name); relation.location = definition.location; - TranslationContext context = createTranslationContext(); + TranslationContext context = createTranslationContext(name); definition.translateTo(context, relation); } } - private TranslationContext createTranslationContext() { - return new TranslationContext(compilationContext, null); + private TranslationContext createTranslationContext(String definitionName) { + return new TranslationContext(compilationContext, null, definitionName); } private void handleAnnotation(SCLValue value, ArrayList defs, DAnnotationAst annotation) { @@ -1364,4 +1365,23 @@ public class Elaboration { branchPoints.put(valueName, injector.getAndClearBranchPoints()); } } + + public void collectDebugInfo() { + module.moduleDebugInfo = compilationContext.moduleDebugInfo = new ModuleDebugInfo(); + } + + public void prepareExports() { + if(moduleHeader != null && moduleHeader.export != null) { + exportMap = new THashMap(); + for(EVar export : moduleHeader.export) + if(exportMap.put(export.name, export) != null) + errorLog.log(export.location, "The symbol " + export.name + " is exported multiple times."); + } + } + + public void checkExports() { + if(exportMap != null) + for(EVar export : exportMap.values()) + errorLog.log(export.location, "The symbol " + export.name + " is not defined in the module."); + } }