diff options
author | 2018-05-22 14:35:55 +0200 | |
---|---|---|
committer | 2018-05-22 14:35:55 +0200 | |
commit | 9bff761c6bd20e152e74f463b5383b1d1a941733 (patch) | |
tree | 143551b760d48344e5e2e3fb0e3c3206314f27c0 /Solvers/VIATRA-Solver | |
parent | Missing src-gen folders are supposed to be solved (diff) | |
download | VIATRA-Generator-9bff761c6bd20e152e74f463b5383b1d1a941733.tar.gz VIATRA-Generator-9bff761c6bd20e152e74f463b5383b1d1a941733.tar.zst VIATRA-Generator-9bff761c6bd20e152e74f463b5383b1d1a941733.zip |
Improved parser performance by removing metamodel loading and validation
It significantly improves the performance
Diffstat (limited to 'Solvers/VIATRA-Solver')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend | 111 |
1 files changed, 62 insertions, 49 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend index 00342d8b..abb52060 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend | |||
@@ -11,6 +11,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage | |||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | 11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage |
12 | import java.io.ByteArrayInputStream | 12 | import java.io.ByteArrayInputStream |
13 | import java.io.InputStream | 13 | import java.io.InputStream |
14 | import java.util.Collections | ||
14 | import java.util.LinkedHashMap | 15 | import java.util.LinkedHashMap |
15 | import java.util.LinkedList | 16 | import java.util.LinkedList |
16 | import java.util.List | 17 | import java.util.List |
@@ -23,63 +24,61 @@ import org.eclipse.emf.ecore.resource.ResourceSet | |||
23 | import org.eclipse.emf.ecore.util.EcoreUtil | 24 | import org.eclipse.emf.ecore.util.EcoreUtil |
24 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | 25 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup |
25 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup.StandaloneParserWithSeparateModules | 26 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup.StandaloneParserWithSeparateModules |
26 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.BaseMetamodelProviderService | ||
27 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.EMFPatternLanguageImportNamespaceProvider | 27 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.EMFPatternLanguageImportNamespaceProvider |
28 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | 28 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider |
29 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProviderInstance | 29 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProviderInstance |
30 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder | 30 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder |
31 | import org.eclipse.viatra.query.patternlanguage.emf.vql.Pattern | ||
31 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel | 32 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel |
33 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
34 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | ||
35 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | ||
36 | import org.eclipse.xtext.resource.EObjectDescription | ||
32 | import org.eclipse.xtext.resource.IResourceFactory | 37 | import org.eclipse.xtext.resource.IResourceFactory |
33 | import org.eclipse.xtext.resource.IResourceServiceProvider | 38 | import org.eclipse.xtext.resource.IResourceServiceProvider |
34 | import org.eclipse.xtext.resource.XtextResourceSet | 39 | import org.eclipse.xtext.resource.XtextResourceSet |
40 | import org.eclipse.xtext.scoping.IScope | ||
35 | import org.eclipse.xtext.scoping.IScopeProvider | 41 | import org.eclipse.xtext.scoping.IScopeProvider |
36 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider | 42 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider |
43 | import org.eclipse.xtext.scoping.impl.SimpleScope | ||
44 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.MetamodelProviderService | ||
45 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.ResourceSetMetamodelProviderService | ||
37 | 46 | ||
38 | class MyModule extends StandaloneParserWithSeparateModules implements Module{ | 47 | class MyModule extends StandaloneParserWithSeparateModules implements Module{ |
39 | // def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { | ||
40 | // return typeof(ExtensionBasedAnnotationValidatorLoader); | ||
41 | // } | ||
42 | // def public Class<? extends IGenmodelMappingLoader> bindGenmodelMappingLoader() { | ||
43 | // return typeof(GenmodelExtensionLoader); | ||
44 | // } | ||
45 | 48 | ||
49 | /** | ||
50 | * Overrided binder | ||
51 | * <code>Multibinder</code>IMetamodelProviderInstance.class); | ||
52 | metamodelProviderBinder.addBinding().to(MetamodelProviderService.class); | ||
53 | metamodelProviderBinder.addBinding().to(ResourceSetMetamodelProviderService.class); | ||
54 | * </code> | ||
55 | */ | ||
46 | override configureIScopeProviderDelegate(Binder binder) { | 56 | override configureIScopeProviderDelegate(Binder binder) { |
47 | binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) | 57 | binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) |
48 | .to(EMFPatternLanguageImportNamespaceProvider); | 58 | .to(EMFPatternLanguageImportNamespaceProvider); |
49 | // .to(XImportSectionNamespaceScopeProvider.class); | ||
50 | //val Multibinder<IMetamodelProviderInstance> metamodelProviderBinder = | ||
51 | Multibinder::newSetBinder(binder, IMetamodelProviderInstance); | 59 | Multibinder::newSetBinder(binder, IMetamodelProviderInstance); |
52 | // metamodelProviderBinder.addBinding().to(MetamodelProviderService.class); | ||
53 | // metamodelProviderBinder.addBinding().to(ResourceSetMetamodelProviderService.class); | ||
54 | } | 60 | } |
55 | 61 | ||
56 | override Class<? extends IMetamodelProvider> bindIMetamodelProvider() { | 62 | override Class<? extends IMetamodelProvider> bindIMetamodelProvider() { |
57 | MetamodelProviderForModelGeneration | 63 | FixedMetamodelProvider |
58 | } | 64 | } |
59 | // def configureFixedMetamodelProviderService(FixedMetamodelProviderService s) { | ||
60 | // println('''Configured «s.class.simpleName» with «s.packages.toList»''') | ||
61 | // s.packages += PartialinterpretationPackage.eINSTANCE | ||
62 | // s.packages += LogicproblemPackage.eINSTANCE | ||
63 | // s.packages += LogiclanguagePackage.eINSTANCE | ||
64 | // println('''Configured «s.class.simpleName» with «s.packages.toList»''') | ||
65 | // } | ||
66 | } | 65 | } |
67 | 66 | ||
68 | class ParseUtil { | 67 | class ParseUtil { |
68 | public static val SIMPLIFIED_PARSER_EXTENSION = "vql_deactivated" | ||
69 | |||
69 | val Injector injector; | 70 | val Injector injector; |
70 | new() { | 71 | new() { |
71 | //EMFPatternLanguageStandaloneSetup.doSetup; | ||
72 | PartialinterpretationPackage.eINSTANCE.class; | 72 | PartialinterpretationPackage.eINSTANCE.class; |
73 | LogicproblemPackage.eINSTANCE.class; | 73 | LogicproblemPackage.eINSTANCE.class; |
74 | LogiclanguagePackage.eINSTANCE.class; | 74 | LogiclanguagePackage.eINSTANCE.class; |
75 | 75 | ||
76 | injector = internalCreateInjector//(new EMFPatternLanguageStandaloneSetup()).createInjectorAndDoEMFRegistration(); | 76 | injector = internalCreateInjector |
77 | 77 | ||
78 | val IResourceFactory resourceFactory = injector.getInstance(IResourceFactory); | 78 | val IResourceFactory resourceFactory = injector.getInstance(IResourceFactory); |
79 | val IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider); | 79 | val IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider); |
80 | 80 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(SIMPLIFIED_PARSER_EXTENSION, resourceFactory); | |
81 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("vql_deactivated", resourceFactory); | 81 | IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put(SIMPLIFIED_PARSER_EXTENSION, serviceProvider); |
82 | IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("vql_deactivated", serviceProvider); | ||
83 | } | 82 | } |
84 | 83 | ||
85 | def protected Injector internalCreateInjector() { | 84 | def protected Injector internalCreateInjector() { |
@@ -89,30 +88,37 @@ class ParseUtil { | |||
89 | return newInjector; | 88 | return newInjector; |
90 | } | 89 | } |
91 | 90 | ||
92 | // @Inject | 91 | val builder = new SpecificationBuilder |
93 | // var ParseHelper<PatternModel> parseHelper; | ||
94 | val builder = new SpecificationBuilder | ||
95 | 92 | ||
96 | public def parse(CharSequence vqlFileContent) { | 93 | public def parse(CharSequence vqlFileContent) { |
97 | //val patternModel = this.parseHelper.parse(vqlFileContent) | ||
98 | val XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet); | 94 | val XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet); |
99 | val Resource resource = resourceSet.createResource(URI.createURI("dummy:/example.vql_deactivated")); | 95 | val Resource resource = resourceSet.createResource(URI.createURI("dummy:/example."+SIMPLIFIED_PARSER_EXTENSION)); |
100 | val InputStream in = new ByteArrayInputStream(vqlFileContent.toString.getBytes()); | 96 | val InputStream in = new ByteArrayInputStream(vqlFileContent.toString.getBytes()); |
101 | resource.load(in, resourceSet.getLoadOptions()); | 97 | resource.load(in, resourceSet.getLoadOptions()); |
98 | println("Loaded") | ||
102 | val patternModel = resource.getContents().get(0) as PatternModel; | 99 | val patternModel = resource.getContents().get(0) as PatternModel; |
100 | println("PatternModel") | ||
103 | 101 | ||
104 | EcoreUtil.resolveAll(resource) | 102 | EcoreUtil.resolveAll(resource) |
105 | resource.validate | 103 | //resource.validate |
106 | val res = new LinkedHashMap | 104 | val res = new LinkedHashMap<String,IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> |
105 | val patterns = new LinkedList<IQuerySpecification<?>> | ||
107 | for(pattern : patternModel.patterns) { | 106 | for(pattern : patternModel.patterns) { |
108 | val querySpecification = builder.getOrCreateSpecification(pattern) | 107 | val querySpecification = createSpecification(pattern,patterns) |
109 | res.put(querySpecification.fullyQualifiedName,querySpecification) | 108 | res.put(querySpecification.fullyQualifiedName,querySpecification) |
110 | //println('''«querySpecification.fullyQualifiedName» -> «querySpecification»''') | 109 | patterns += querySpecification |
111 | } | 110 | } |
112 | resource.validate | 111 | //resource.validate |
112 | |||
113 | return res | 113 | return res |
114 | } | 114 | } |
115 | 115 | ||
116 | def IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> createSpecification( | ||
117 | Pattern pattern,List<IQuerySpecification<?>> createdPatternList) | ||
118 | { | ||
119 | builder.getOrCreateSpecification(pattern,createdPatternList,true) | ||
120 | } | ||
121 | |||
116 | def private validate(Resource resource) { | 122 | def private validate(Resource resource) { |
117 | val errors = resource.errors | 123 | val errors = resource.errors |
118 | if(!errors.isEmpty) { | 124 | if(!errors.isEmpty) { |
@@ -123,26 +129,33 @@ class ParseUtil { | |||
123 | } | 129 | } |
124 | } | 130 | } |
125 | 131 | ||
126 | abstract class FixedMetamodelProviderService extends BaseMetamodelProviderService { | 132 | class FixedMetamodelProvider implements IMetamodelProvider { |
127 | 133 | ||
128 | protected val List<EPackage> packages = new LinkedList | 134 | protected val List<EPackage> packages = new LinkedList |
129 | |||
130 | override protected doGetQualifiedClassName(EClassifier classifier, EObject context) { | ||
131 | classifier.name | ||
132 | } | ||
133 | |||
134 | override protected getProvidedMetamodels() { | ||
135 | return packages.map[it.nsURI] | ||
136 | } | ||
137 | |||
138 | override loadEPackage(String uri, ResourceSet resourceSet) { | ||
139 | packages.filter[it.nsURI.equals(uri)].head | ||
140 | } | ||
141 | } | ||
142 | class MetamodelProviderForModelGeneration extends FixedMetamodelProviderService { | ||
143 | new() { | 135 | new() { |
144 | packages += PartialinterpretationPackage.eINSTANCE | 136 | packages += PartialinterpretationPackage.eINSTANCE |
145 | packages += LogicproblemPackage.eINSTANCE | 137 | packages += LogicproblemPackage.eINSTANCE |
146 | packages += LogiclanguagePackage.eINSTANCE | 138 | packages += LogiclanguagePackage.eINSTANCE |
147 | } | 139 | } |
140 | |||
141 | override getAllMetamodelObjects(IScope delegateScope, EObject context) { | ||
142 | val metamodels = packages.map[EObjectDescription.create(it.nsURI, it, Collections.singletonMap("nsURI", "true"))] | ||
143 | return new SimpleScope(delegateScope, metamodels); | ||
144 | } | ||
145 | |||
146 | override boolean isGeneratedCodeAvailable(EPackage ePackage, ResourceSet set) { | ||
147 | true | ||
148 | } | ||
149 | |||
150 | override String getModelPluginId(EPackage ePackage, ResourceSet set) { | ||
151 | return "hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage" | ||
152 | } | ||
153 | |||
154 | override String getQualifiedClassName(EClassifier classifier, EObject context) { | ||
155 | classifier.name | ||
156 | } | ||
157 | |||
158 | override loadEPackage(String uri, ResourceSet resourceSet) { | ||
159 | return packages.filter[it.nsURI.equals(uri)].head | ||
160 | } | ||
148 | } \ No newline at end of file | 161 | } \ No newline at end of file |