diff options
author | 2019-02-06 18:28:18 +0100 | |
---|---|---|
committer | 2019-02-19 19:18:25 +0100 | |
commit | 615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7 (patch) | |
tree | 1c9fe0f4ae152d84152c8ff1cfb6366ec8b277e9 /Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu | |
parent | [Stochastic] Fault tree transformation langauge (diff) | |
download | VIATRA-Generator-615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7.tar.gz VIATRA-Generator-615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7.tar.zst VIATRA-Generator-615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7.zip |
Extract component fault tree model
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu')
7 files changed, 105 insertions, 30 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguage.xtext b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguage.xtext index 3d82413f..61ab3359 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguage.xtext +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguage.xtext | |||
@@ -2,7 +2,8 @@ grammar hu.bme.mit.inf.dslreasoner.faulttree.components.CftLanguage with org.ecl | |||
2 | 2 | ||
3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore | 3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore |
4 | import "http://www.eclipse.org/viatra/query/patternlanguage/emf/PatternLanguage" as vql | 4 | import "http://www.eclipse.org/viatra/query/patternlanguage/emf/PatternLanguage" as vql |
5 | 5 | import "http://www.bme.hu/mit/inf/dslreasoner/faulttree/model/ft" as ft | |
6 | import "http://www.bme.hu/mit/inf/dslreasoner/faulttree/model/cft" as cft | ||
6 | generate cftLanguage "http://www.bme.hu/mit/inf/dslreasoner/faulttree/components/CftLanguage" | 7 | generate cftLanguage "http://www.bme.hu/mit/inf/dslreasoner/faulttree/components/CftLanguage" |
7 | 8 | ||
8 | CftModel: | 9 | CftModel: |
@@ -13,35 +14,44 @@ CftModel: | |||
13 | ImportDeclaration: | 14 | ImportDeclaration: |
14 | "import" importedNamespace=QualifiedNameWithWildcard ";"?; | 15 | "import" importedNamespace=QualifiedNameWithWildcard ";"?; |
15 | 16 | ||
16 | ComponentDefinition: | 17 | ComponentDefinition returns cft::ComponentDefinition: |
17 | "cft" name=ID "{" | 18 | "cft" name=ValidId "{" |
18 | (("in" inputEvents+=InputEvent* ";")? & ("out" outputEvents+=[EventDeclaration]* ";")?) | 19 | (("in" inputEvents+=InputEvent* ";")? & ("out" outputEvents+=[cft::EventDeclaration|ValidId]* ";")?) |
19 | (eventDefinitions+=EventDefinition ";")* | 20 | (eventDefinitions+=EventDefinition ";")* |
20 | "}"; | 21 | "}"; |
21 | 22 | ||
22 | EventDeclaration: | 23 | InputEvent returns cft::IntputEvent: |
23 | InputEvent | EventDefinition; | 24 | name=ValidId multiple?="[]"?; |
24 | |||
25 | InputEvent: | ||
26 | name=ID multiple?="[]"?; | ||
27 | 25 | ||
28 | EventDefinition: | 26 | EventDefinition returns cft::EventDefinition: |
29 | BasicEventDefinition | GateDefinition; | 27 | BasicEventDefinition | GateDefinition; |
30 | 28 | ||
31 | BasicEventDefinition: | 29 | BasicEventDefinition returns cft::BasicEventDefinition: |
32 | name=ID "lambda" "=" rate=DOULBE; | 30 | name=ValidId distribution=Distribution; |
31 | |||
32 | Distribution returns ft::Distribution: | ||
33 | ConstantDistribution | ExponentialDistribution; | ||
34 | |||
35 | ConstantDistribution returns ft::ConstantDistribution: | ||
36 | "p" "=" p=Double; | ||
37 | |||
38 | ExponentialDistribution returns ft::ExponentialDistribution: | ||
39 | "lambda" "=" lambda=Double; | ||
33 | 40 | ||
34 | GateDefinition: | 41 | GateDefinition returns cft::GateDefinition: |
35 | AndGate | OrGate; | 42 | AndGateDefinition | OrGateDefinition | KOfMGateDefinition; |
36 | 43 | ||
37 | AndGate: | 44 | AndGateDefinition returns cft::AndGateDefinition: |
38 | name=ID "and" inputEvents+=[EventDeclaration]*; | 45 | name=ValidId "and" inputEvents+=[cft::EventDeclaration|ValidId]*; |
39 | 46 | ||
40 | OrGate: | 47 | OrGateDefinition returns cft::OrGateDefinition: |
41 | name=ID "or" inputEvents+=[EventDeclaration]*; | 48 | name=ValidId "or" inputEvents+=[cft::EventDeclaration|ValidId]*; |
49 | |||
50 | KOfMGateDefinition returns cft::KOfMGateDefinition: | ||
51 | name=ValidId k=INT ("of" m=INT | m=OF_INT) inputEvents+=[cft::EventDeclaration|ValidId]*; | ||
42 | 52 | ||
43 | TransformationDefinition: | 53 | TransformationDefinition: |
44 | "transformation" name=ID "{" | 54 | "transformation" name=ValidId "{" |
45 | mappingDefinitions+=MappingDefinition* | 55 | mappingDefinitions+=MappingDefinition* |
46 | "}"; | 56 | "}"; |
47 | 57 | ||
@@ -49,16 +59,16 @@ MappingDefinition: | |||
49 | topLevel?="toplevel"? "mapping" pattern=[vql::Pattern|QualifiedName] | 59 | topLevel?="toplevel"? "mapping" pattern=[vql::Pattern|QualifiedName] |
50 | "(" parameters+=MappingParameter ("," parameters+=MappingParameter)* ")" | 60 | "(" parameters+=MappingParameter ("," parameters+=MappingParameter)* ")" |
51 | (componentInstance=ComponentInstance)? ("{" | 61 | (componentInstance=ComponentInstance)? ("{" |
52 | ((lookupDefinitions+=LookupDefinition | assignments+=Assignment) ";")* | 62 | ((lookupDefinitions+=LookupDefinition | assignments+=Assignment) ";")* |
53 | "}")?; | 63 | "}")?; |
54 | 64 | ||
55 | MappingParameter: | 65 | MappingParameter: |
56 | name=ID; | 66 | name=ValidId; |
57 | 67 | ||
58 | LookupDefinition: | 68 | LookupDefinition: |
59 | "lookup" mapping=[MappingDefinition] | 69 | "lookup" mapping=[MappingDefinition|QualifiedName] |
60 | "(" arguments+=[MappingParameter] ("," arguments+=[MappingParameter])* ")" | 70 | "(" arguments+=[MappingParameter|ValidId] ("," arguments+=[MappingParameter|ValidId])* ")" |
61 | "as" name=ID; | 71 | "as" name=ValidId; |
62 | 72 | ||
63 | Variable: | 73 | Variable: |
64 | ComponentInstance | LookupDefinition; | 74 | ComponentInstance | LookupDefinition; |
@@ -67,16 +77,25 @@ Assignment: | |||
67 | input=EventReference (multiple?="+=" | ":=") output=EventReference; | 77 | input=EventReference (multiple?="+=" | ":=") output=EventReference; |
68 | 78 | ||
69 | EventReference: | 79 | EventReference: |
70 | component=[Variable] "." event=[EventDeclaration]; | 80 | component=[Variable|ValidId] "." event=[cft::EventDeclaration|ValidId]; |
71 | 81 | ||
72 | ComponentInstance: | 82 | ComponentInstance: |
73 | "=>" componentType=[ComponentDefinition|QualifiedName] name=ID?; | 83 | "=>" componentType=[cft::ComponentDefinition|QualifiedName] name=ID?; |
74 | 84 | ||
75 | QualifiedName returns ecore::EString: | 85 | QualifiedName returns ecore::EString: |
76 | ID ("." ID)*; | 86 | ValidId ("." ValidId)*; |
77 | 87 | ||
78 | QualifiedNameWithWildcard returns ecore::EString: | 88 | QualifiedNameWithWildcard returns ecore::EString: |
79 | QualifiedName ("." "*")?; | 89 | QualifiedName ("." "*")?; |
80 | 90 | ||
81 | terminal DOULBE returns ecore::EDouble: | 91 | ValidId: |
92 | ID | OF_INT; | ||
93 | |||
94 | Double returns ecore::EDouble: | ||
95 | INT | T_DOUBLE; | ||
96 | |||
97 | terminal OF_INT returns ecore::EInt: | ||
98 | "o" "f" ('0'..'9')+; | ||
99 | |||
100 | terminal T_DOUBLE: | ||
82 | ('0'..'9')+ ("." ('0'..'9')+ | ("." ('0'..'9')+)? ("e" | "E") ("+" | "-")? ('0'..'9')+); | 101 | ('0'..'9')+ ("." ('0'..'9')+ | ("." ('0'..'9')+)? ("e" | "E") ("+" | "-")? ('0'..'9')+); |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageRuntimeModule.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageRuntimeModule.xtend index f780591d..fe5965fa 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageRuntimeModule.xtend +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageRuntimeModule.xtend | |||
@@ -5,6 +5,7 @@ package hu.bme.mit.inf.dslreasoner.faulttree.components | |||
5 | 5 | ||
6 | import com.google.inject.Binder | 6 | import com.google.inject.Binder |
7 | import com.google.inject.name.Names | 7 | import com.google.inject.name.Names |
8 | import hu.bme.mit.inf.dslreasoner.faulttree.components.conversion.CftLanguageValueConverterService | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.components.naming.CftLanguageQualifiedNameProvider | 9 | import hu.bme.mit.inf.dslreasoner.faulttree.components.naming.CftLanguageQualifiedNameProvider |
9 | import hu.bme.mit.inf.dslreasoner.faulttree.components.scoping.CftLanguageImportedNamespaceAwareLocalScopeProvider | 10 | import hu.bme.mit.inf.dslreasoner.faulttree.components.scoping.CftLanguageImportedNamespaceAwareLocalScopeProvider |
10 | import org.eclipse.xtext.scoping.IScopeProvider | 11 | import org.eclipse.xtext.scoping.IScopeProvider |
@@ -30,4 +31,7 @@ class CftLanguageRuntimeModule extends AbstractCftLanguageRuntimeModule { | |||
30 | CftLanguageQualifiedNameProvider | 31 | CftLanguageQualifiedNameProvider |
31 | } | 32 | } |
32 | 33 | ||
34 | override bindIValueConverterService() { | ||
35 | CftLanguageValueConverterService | ||
36 | } | ||
33 | } | 37 | } |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/GenerateCftLanguage.mwe2 b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/GenerateCftLanguage.mwe2 index fa383404..89efbb05 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/GenerateCftLanguage.mwe2 +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/GenerateCftLanguage.mwe2 | |||
@@ -29,6 +29,8 @@ Workflow { | |||
29 | 29 | ||
30 | referencedResource = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel" | 30 | referencedResource = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel" |
31 | referencedResource = "platform:/resource/org.eclipse.viatra.query.patternlanguage.emf/model/PatternLanguage.genmodel" | 31 | referencedResource = "platform:/resource/org.eclipse.viatra.query.patternlanguage.emf/model/PatternLanguage.genmodel" |
32 | referencedResource = "platform:/resource/hu.bme.mit.inf.dslreasoner.faulttree.model/model/ft.genmodel" | ||
33 | referencedResource = "platform:/resource/hu.bme.mit.inf.dslreasoner.faulttree.model/model/cft.genmodel" | ||
32 | 34 | ||
33 | serializer = { | 35 | serializer = { |
34 | generateStub = false | 36 | generateStub = false |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/CftLanguageValueConverterService.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/CftLanguageValueConverterService.xtend new file mode 100644 index 00000000..974e0df4 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/CftLanguageValueConverterService.xtend | |||
@@ -0,0 +1,15 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.conversion | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import org.eclipse.xtext.common.services.DefaultTerminalConverters | ||
5 | import org.eclipse.xtext.conversion.IValueConverter | ||
6 | import org.eclipse.xtext.conversion.ValueConverter | ||
7 | |||
8 | class CftLanguageValueConverterService extends DefaultTerminalConverters { | ||
9 | @Inject OF_INTValueConverter ofIntValueConverter | ||
10 | |||
11 | @ValueConverter(rule="OF_INT") | ||
12 | def IValueConverter<Integer> OF_INT() { | ||
13 | ofIntValueConverter | ||
14 | } | ||
15 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/OF_INTValueConverter.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/OF_INTValueConverter.xtend new file mode 100644 index 00000000..ba3d39e6 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/OF_INTValueConverter.xtend | |||
@@ -0,0 +1,35 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.conversion | ||
2 | |||
3 | import org.eclipse.xtext.conversion.ValueConverterException | ||
4 | import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter | ||
5 | import org.eclipse.xtext.nodemodel.INode | ||
6 | |||
7 | class OF_INTValueConverter extends AbstractLexerBasedConverter<Integer> { | ||
8 | static val PREFIX = "of" | ||
9 | |||
10 | override toValue(String string, INode node) throws ValueConverterException { | ||
11 | if (string === null) { | ||
12 | return null | ||
13 | } | ||
14 | if (string.length < PREFIX.length || string.substring(0, PREFIX.length) != PREFIX) { | ||
15 | throw new ValueConverterException("'" + string + "' must start with the characters 'of'.", node, null); | ||
16 | } | ||
17 | try { | ||
18 | val intValue = Integer.parseInt(string.substring(PREFIX.length), 10) | ||
19 | Integer.valueOf(intValue) | ||
20 | } catch (NumberFormatException e) { | ||
21 | throw new ValueConverterException("Couldn't convert '" + string + "' to an int value.", node, e); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | override protected toEscapedString(Integer value) { | ||
26 | PREFIX + value | ||
27 | } | ||
28 | |||
29 | override protected assertValidValue(Integer value) { | ||
30 | super.assertValidValue(value) | ||
31 | if (value < 0) { | ||
32 | throw new ValueConverterException(getRuleName() + " may not be negative.", null, null); | ||
33 | } | ||
34 | } | ||
35 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/CftLanguageQualifiedNameProvider.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/CftLanguageQualifiedNameProvider.xtend index eb96901c..db89ebf9 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/CftLanguageQualifiedNameProvider.xtend +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/CftLanguageQualifiedNameProvider.xtend | |||
@@ -1,8 +1,8 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.naming | 1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.naming |
2 | 2 | ||
3 | import com.google.inject.Inject | 3 | import com.google.inject.Inject |
4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentDefinition | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition | 4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition |
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentDefinition | ||
6 | import org.eclipse.emf.ecore.EObject | 6 | import org.eclipse.emf.ecore.EObject |
7 | import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider | 7 | import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider |
8 | 8 | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend index ab708087..e95d8c91 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend | |||
@@ -5,13 +5,13 @@ package hu.bme.mit.inf.dslreasoner.faulttree.components.scoping | |||
5 | 5 | ||
6 | import com.google.common.collect.Lists | 6 | import com.google.common.collect.Lists |
7 | import com.google.inject.Inject | 7 | import com.google.inject.Inject |
8 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentDefinition | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentInstance | 8 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentInstance |
10 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.EventReference | 9 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.EventReference |
11 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.LookupDefinition | 10 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.LookupDefinition |
12 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.MappingDefinition | 11 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.MappingDefinition |
13 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition | 12 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition |
14 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.Variable | 13 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.Variable |
14 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentDefinition | ||
15 | import org.eclipse.emf.common.notify.Notifier | 15 | import org.eclipse.emf.common.notify.Notifier |
16 | import org.eclipse.emf.ecore.EObject | 16 | import org.eclipse.emf.ecore.EObject |
17 | import org.eclipse.emf.ecore.EReference | 17 | import org.eclipse.emf.ecore.EReference |