diff options
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.viatra2logic')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend index 8d234fe9..95ba9219 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend | |||
@@ -37,6 +37,7 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyNormaliz | |||
37 | import org.eclipse.xtend.lib.annotations.Data | 37 | import org.eclipse.xtend.lib.annotations.Data |
38 | 38 | ||
39 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 39 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.TypeJudgement | ||
40 | 41 | ||
41 | @Data class ViatraQuerySetDescriptor { | 42 | @Data class ViatraQuerySetDescriptor { |
42 | val List<? extends IQuerySpecification<?>> patterns | 43 | val List<? extends IQuerySpecification<?>> patterns |
@@ -75,14 +76,18 @@ class Viatra2Logic { | |||
75 | try { | 76 | try { |
76 | this.transformQueryHeader(query,ecore2LogicTrace,viatra2LogicTrace,config) | 77 | this.transformQueryHeader(query,ecore2LogicTrace,viatra2LogicTrace,config) |
77 | } catch(IllegalArgumentException e) { | 78 | } catch(IllegalArgumentException e) { |
78 | throw new IllegalArgumentException('''Unable to translate query "«query.fullyQualifiedName»".''',e) | 79 | throw new IllegalArgumentException(''' |
80 | Unable to translate query "«query.fullyQualifiedName»". | ||
81 | Reason: «e.class.simpleName», «e.message»''',e) | ||
79 | } | 82 | } |
80 | } | 83 | } |
81 | for(query: queries.patterns) { | 84 | for(query: queries.patterns) { |
82 | try { | 85 | try { |
83 | this.transformQuerySpecification(query,ecore2LogicTrace,viatra2LogicTrace,config) | 86 | this.transformQuerySpecification(query,ecore2LogicTrace,viatra2LogicTrace,config) |
84 | } catch (IllegalArgumentException e){ | 87 | } catch (IllegalArgumentException e){ |
85 | throw new IllegalArgumentException('''Unable to translate query: "«query.fullyQualifiedName»".''',e) | 88 | throw new IllegalArgumentException(''' |
89 | Unable to translate query "«query.fullyQualifiedName»". | ||
90 | Reason: «e.class.simpleName», «e.message»''',e) | ||
86 | } | 91 | } |
87 | } | 92 | } |
88 | /*for(d : viatra2LogicTrace.query2Relation.values) { | 93 | /*for(d : viatra2LogicTrace.query2Relation.values) { |
@@ -252,39 +257,45 @@ class Viatra2Logic { | |||
252 | return variableName.replaceAll("[\\W]|_", "") | 257 | return variableName.replaceAll("[\\W]|_", "") |
253 | } | 258 | } |
254 | 259 | ||
255 | def TypeDescriptor getType(PVariable v, PBody body, TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) { | 260 | def TypeDescriptor getType(PVariable v, PBody body, TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) { |
256 | if(v.isPositiveVariable) { | 261 | var Map<PVariable, Set<TypeJudgement>> unaryTypeRestrictions = null; |
257 | val allTypes = v.lookup( | 262 | if (v.isPositiveVariable) { |
258 | body.getAllUnaryTypeRestrictions(EMFQueryMetaContext.DEFAULT)) | 263 | unaryTypeRestrictions = body.getAllUnaryTypeRestrictions(EMFQueryMetaContext.DEFAULT) |
264 | if (!unaryTypeRestrictions.containsKey(v)) { | ||
265 | throw new IllegalArgumentException('''No positive constraints on variable: «v.name»''') | ||
266 | } | ||
267 | val allTypes = v.lookup(unaryTypeRestrictions) | ||
268 | |||
259 | val types = allTypes.filter[it.inputKey instanceof BaseEMFTypeKey<?>].toSet | 269 | val types = allTypes.filter[it.inputKey instanceof BaseEMFTypeKey<?>].toSet |
260 | 270 | ||
261 | if(types.size == 0) { | 271 | if (types.size == 0) { |
262 | throw new AssertionError(''' | 272 | throw new AssertionError(''' |
263 | No EMF type for «v.name». | 273 | No EMF type for «v.name». |
264 | Non-EMF types: [«FOR t : allTypes.filter[!types.contains(it)].map[inputKey.prettyPrintableName] SEPARATOR ','»«t»«ENDFOR»]''') | 274 | Non-EMF types: [«FOR t : allTypes.filter[!types.contains(it)].map[inputKey.prettyPrintableName] SEPARATOR ','»«t»«ENDFOR»]''') |
265 | } else if(types.size == 1){ | 275 | } else if (types.size == 1) { |
266 | return (types.head.inputKey as BaseEMFTypeKey<? extends EClassifier>).transformTypeReference(ecore2LogicTrace) | 276 | return (types.head.inputKey as BaseEMFTypeKey<? extends EClassifier>). |
277 | transformTypeReference(ecore2LogicTrace) | ||
267 | } else { | 278 | } else { |
268 | // println(''' | 279 | // println(''' |
269 | // Type Judgements of «v.name» | 280 | // Type Judgements of «v.name» |
270 | // «types.map[inputKey.prettyPrintableName]» | 281 | // «types.map[inputKey.prettyPrintableName]» |
271 | // ''') | 282 | // ''') |
272 | return this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace, | 283 | return this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace, calculateCommonSubtype(types.map [ |
273 | calculateCommonSubtype(types.map[ | 284 | (it.inputKey as BaseEMFTypeKey<EClass>).emfKey as EClass |
274 | (it.inputKey as BaseEMFTypeKey<EClass>).emfKey as EClass | 285 | ], ecore2LogicTrace)) |
275 | ],ecore2LogicTrace)) | ||
276 | } | 286 | } |
277 | } else { | 287 | } else { |
278 | val onlyConstraint = v.referringConstraints.head as NegativePatternCall | 288 | val onlyConstraint = v.referringConstraints.head as NegativePatternCall |
279 | val indexOfVariable = v.lookup(onlyConstraint.actualParametersTuple.invertIndex) | 289 | val indexOfVariable = v.lookup(onlyConstraint.actualParametersTuple.invertIndex) |
280 | val parameter = onlyConstraint.referredQuery.parameters.get(indexOfVariable) | 290 | val parameter = onlyConstraint.referredQuery.parameters.get(indexOfVariable) |
281 | val declaredUnaryType = parameter.declaredUnaryType as BaseEMFTypeKey<? extends EClassifier> | 291 | val declaredUnaryType = parameter.declaredUnaryType as BaseEMFTypeKey<? extends EClassifier> |
282 | if(declaredUnaryType === null) { | 292 | if (declaredUnaryType === null) { |
283 | throw new UnsupportedOperationException( | 293 | throw new UnsupportedOperationException( |
284 | '''parameter «parameter.name» in pattern « | 294 | '''parameter «parameter.name» in pattern «onlyConstraint.referredQuery.fullyQualifiedName» does not have type!''') |
285 | onlyConstraint.referredQuery.fullyQualifiedName» does not have type!''') | 295 | } else |
286 | } else return declaredUnaryType.transformTypeReference(ecore2LogicTrace) | 296 | return declaredUnaryType.transformTypeReference(ecore2LogicTrace) |
287 | } | 297 | } |
298 | |||
288 | } | 299 | } |
289 | 300 | ||
290 | def calculateCommonSubtype(Iterable<EClass> allsuperClasses,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) { | 301 | def calculateCommonSubtype(Iterable<EClass> allsuperClasses,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) { |