Class: ActiveFacts::CQL::Compiler::Operation
- Inherits:
-
Object
- Object
- ActiveFacts::CQL::Compiler::Operation
show all
- Defined in:
- lib/activefacts/cql/compiler/expression.rb
Overview
An Operation is a binary or ternary fact type involving an operator, a result, and one or two operands. Viewed as a result, it behaves like a Reference with a nested Clause. Viewed as a fact type, it behaves like a Clause.
The only exception here is an equality comparison, where it may turn out that the equality is merely a projection. In this case the Operation is dropped from the clauses and is replaced by the projected operand.
Each operand may be a Literal, a Reference, or another Operation, so we need to recurse down the tree to build the query.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Operation.
51
52
53
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 51
def initialize
@certainty = true end
|
Instance Attribute Details
#binding ⇒ Object
What Binding for that ObjectType
33
34
35
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 33
def binding
@binding
end
|
#certainty ⇒ Object
nil, true, false -> maybe, definitely, not
37
38
39
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 37
def certainty
@certainty
end
|
#clause ⇒ Object
What clause does the result participate in?
34
35
36
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 34
def clause
@clause
end
|
#fact_type ⇒ Object
Returns the value of attribute fact_type.
48
49
50
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 48
def fact_type
@fact_type
end
|
#player ⇒ Object
What ObjectType does the Binding denote
32
33
34
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 32
def player
@player
end
|
#role ⇒ Object
Which Role of this ObjectType
35
36
37
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 35
def role
@role
end
|
#role_ref ⇒ Object
Which RoleRef to that Role
36
37
38
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 36
def role_ref
@role_ref
end
|
Instance Method Details
#bind(context) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 76
def bind context
refs.each do |o|
o.bind context
end
name = result_type_name(context)
@player = result_value_type(context, name)
key = "#{name} #{object_id}" @binding = (context.bindings[key] ||= Binding.new(@player))
@binding.refs << self
@binding
end
|
#conjunction ⇒ Object
47
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 47
def conjunction; nil; end
|
#identify_other_players(context) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 68
def identify_other_players context
refs.each { |o|
o.identify_other_players(context)
}
identify_player context
end
|
#identify_players_with_role_name(context) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 59
def identify_players_with_role_name context
refs.each { |o|
o.identify_players_with_role_name(context)
}
end
|
#is_equality_comparison ⇒ Object
140
141
142
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 140
def is_equality_comparison
false
end
|
#is_naked_object_type ⇒ Object
99
100
101
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 99
def is_naked_object_type
false end
|
#leading_adjective ⇒ Object
27
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 27
def leading_adjective; nil; end
|
#literal ⇒ Object
30
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 30
def literal; nil; end
|
#match_existing_fact_type(context) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 103
def match_existing_fact_type context
opnds = refs
result_ref = Reference.new(@binding.player.name)
result_ref.player = @binding.player
result_ref.binding = @binding
@binding.refs << result_ref
clause_ast = Clause.new(
[result_ref, '='] +
(opnds.size > 1 ? [opnds[0]] : []) +
[operator, opnds[-1]]
)
@fact_type = clause_ast.match_existing_fact_type(context, :exact_type => true)
if clause.certainty == false
raise "Negated fact types in expressions are not yet supported: #{clause.inspect}"
end
return @fact_type if @fact_type
@fact_type = clause_ast.make_fact_type context.vocabulary
reading = clause_ast.make_reading context.vocabulary, @fact_type
rrs = reading.role_sequence.all_role_ref_in_order
opnds[0].role_ref = rrs[0]
opnds[-1].role_ref = rrs[-1]
opnds.each do |opnd|
next unless opnd.is_a?(Operation)
opnd.match_existing_fact_type context
if opnd.certainty == false
raise "Negated fact types in expressions are not yet supported: #{opnd.inspect}"
end
end
@fact_type
end
|
#nested_clauses ⇒ Object
38
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 38
def nested_clauses; @nested_clauses ||= [self]; end
|
#objectification_of ⇒ Object
40
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 40
def objectification_of; @fact_type; end
|
#objectified_as ⇒ Object
The Reference which objectified this fact type
49
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 49
def objectified_as; self; end
|
#operands(context = nil) ⇒ Object
55
56
57
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 55
def operands context = nil
raise "REVISIT: Implement operand enumeration in the operator subclass #{self.class.name}"
end
|
#operator ⇒ Object
144
145
146
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 144
def operator
raise "REVISIT: Implement operator access in the operator subclass #{self.class.name}"
end
|
#result_type_name(context) ⇒ Object
88
89
90
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 88
def result_type_name(context)
raise "REVISIT: Implement result_type_name in the #{self.class.name} subclass"
end
|
#result_value_type(context, name) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 92
def result_value_type(context, name)
vocabulary = context.vocabulary
constellation = vocabulary.constellation
vocabulary.valid_value_type_name(name) ||
constellation.ValueType(vocabulary, name, :concept => :new)
end
|
#role_name ⇒ Object
26
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 26
def role_name; nil; end
|
#side_effects ⇒ Object
31
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 31
def side_effects; nil; end
|
#trailing_adjective ⇒ Object
28
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 28
def trailing_adjective; nil; end
|
#value_constraint ⇒ Object
29
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 29
def value_constraint; nil; end
|