diff --git a/src/analysis/typepal/Collector.rsc b/src/analysis/typepal/Collector.rsc index a5fae44..09ec8cb 100644 --- a/src/analysis/typepal/Collector.rsc +++ b/src/analysis/typepal/Collector.rsc @@ -29,6 +29,7 @@ import String; import analysis::typepal::Version; import analysis::typepal::Messenger; import analysis::typepal::LocationChecks; +import analysis::typepal::GetLoc; extend analysis::typepal::ConfigurableScopeGraph; extend analysis::typepal::ICollector; @@ -268,8 +269,7 @@ Collector newCollector(str modelName, map[str,Tree] namedTrees, TypePalConfig co else if(loc ldef := def) l = ldef; else throw TypePalUsage("Argument `def` of `define` should be `Tree` or `loc`, found "); nname = normalizeName(orgId); - Define newDef = ; - logL = buildLogical2physical(newDef); + Define newDef = buildLogicalDefine(); if(info is defTypeLub){ // Look for an outer variable declaration of id that overrules the defTypeLub for(Define def <- defines + definesPerLubScope[currentLubScope]){ @@ -347,8 +347,7 @@ Collector newCollector(str modelName, map[str,Tree] namedTrees, TypePalConfig co else throw TypePalUsage("Argument `def` of `defineInScope` should be `Tree` or `loc`, found "); nname = normalizeName(orgId); - Define newDef = ; - logL = buildLogical2physical(newDef); + Define newDef = buildLogicalDefine(); if(info is defTypeLub){ throw TypePalUsage("`defLub` cannot be used in combination with `defineInScope`"); } else { @@ -961,23 +960,24 @@ Collector newCollector(str modelName, map[str,Tree] namedTrees, TypePalConfig co return l; } - loc buildLogical2physical(Define def){ - if(def.defined in logical2physical) return logical2physical[def.defined]; + Define buildLogicalDefine(Define def){ + if(def.defined in logical2physical) return def; loc logicalLoc = physical2logical[def.defined] ? config.createLogicalLoc(def, modelName, config.typepalPathConfig); - if(logicalLoc != def.defined){ - if(logicalLoc in logical2physical){ - if(logical2physical[logicalLoc] != def.defined){ - causes = [ info("First declaration of ``", logical2physical[logicalLoc]), - info("Second declaration of ``", def.defined) - ]; - // restrict clone location to first line for readability - messages += error("Duplicate declaration of ``", limitLocToFirstLine(def.defined), causes=causes); - } + + if(logicalLoc in logical2physical){ + if(logical2physical[logicalLoc] != def.defined){ + causes = [ info("First declaration of ``", logical2physical[logicalLoc]), + info("Second declaration of ``", def.defined) + ]; + // restrict clone location to first line for readability + messages += error("Duplicate declaration of ``", limitLocToFirstLine(def.defined), causes=causes); } - logical2physical[logicalLoc] = def.defined; - physical2logical[def.defined] = logicalLoc; } - return logicalLoc; + logical2physical[logicalLoc] = def.defined; + physical2logical[def.defined] = logicalLoc; + def.defined = logicalLoc; + + return def; } &T toLogicalLocs(&T v){ diff --git a/src/analysis/typepal/Messenger.rsc b/src/analysis/typepal/Messenger.rsc index f67dc6f..625864a 100644 --- a/src/analysis/typepal/Messenger.rsc +++ b/src/analysis/typepal/Messenger.rsc @@ -26,6 +26,7 @@ import util::IDEServices; extend analysis::typepal::AType; extend analysis::typepal::Exception; +import analysis::typepal::GetLoc; // ---- Message utilities -----------------------------------------------------