Skip to content

Commit 9fffdd0

Browse files
committed
Merge branch 'topic/implication_operator' into 'master'
Add an implication construction in LKQL Closes #4 See merge request eng/libadalang/langkit-query-language!275
2 parents 14497d9 + 39a8652 commit 9fffdd0

File tree

27 files changed

+161
-95
lines changed

27 files changed

+161
-95
lines changed

lkql/build/railroad-diagrams/if_then_else.svg

Lines changed: 12 additions & 9 deletions
Loading

lkql/language/lexer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Token(LexerToken):
6666
Pipe = WithText()
6767
LArrow = WithText()
6868
BigRArrow = WithText()
69+
BigLongRArrow = WithText()
6970
Box = WithText()
7071
SubBlockLiteral = WithText()
7172

lkql/language/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class Op(LkqlNode):
7474
"""
7575
enum_node = True
7676
alternatives = [
77-
'plus', 'minus', 'mul', 'div', 'and', 'or', 'eq', 'neq', 'concat',
78-
'lt', 'leq', 'gt', 'geq', 'not'
77+
'plus', 'minus', 'mul', 'div', 'and', 'or', 'eq', 'neq',
78+
'concat', 'lt', 'leq', 'gt', 'geq', 'not'
7979
]
8080

8181

@@ -159,7 +159,7 @@ class SubBlockLiteral(LkqlNode):
159159
pass
160160

161161

162-
class IfThenElse(Expr):
162+
class CondExpr(Expr):
163163
"""
164164
Expression of the form: ``if CONDITION then EXPR1 else EXPR2``
165165
"""
@@ -1326,7 +1326,7 @@ class Tuple(Expr):
13261326

13271327
match_arm=MatchArm("|", G.pattern, "=>", G.expr),
13281328

1329-
if_then_else=IfThenElse("if", G.expr, "then", G.expr, "else", G.expr),
1329+
if_then_else=CondExpr("if", G.expr, "then", G.expr, Opt("else", G.expr)),
13301330

13311331
id=Identifier(Token.Identifier),
13321332
upper_id=Identifier(Token.UpperIdentifier),

lkql_checker/share/lkql/identifier_prefixes.lkql

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ fun identifier_prefixes(unit,
165165
when p is not SingleTaskTypeDecl and concurrent != "-"
166166
=>
167167
p.p_previous_part() is (null | IncompleteTypeDecl) and
168-
((not node.f_name.text.starts_with(concurrent)) or
169-
check_exclusive(node.f_name.text,
170-
exclusive=exclusive,
171-
concurrent_exclusive=false))
168+
(if node.f_name.text.starts_with(concurrent)
169+
then check_exclusive(node.f_name.text,
170+
exclusive=exclusive,
171+
concurrent_exclusive=false))
172172

173173
# 'Class access
174174
| (p@TypeDecl(f_type_def: TypeAccessDef(f_subtype_indication: *(f_name:
@@ -179,10 +179,10 @@ fun identifier_prefixes(unit,
179179
when class_access != "-"
180180
=>
181181
p?.p_previous_part() is (null | IncompleteTypeDecl) and
182-
((not node.f_name.text.starts_with(class_access)) or
183-
check_exclusive(node.f_name.text,
184-
exclusive=exclusive,
185-
class_access_exclusive=false))
182+
(if node.f_name.text.starts_with(class_access)
183+
then check_exclusive(node.f_name.text,
184+
exclusive=exclusive,
185+
class_access_exclusive=false))
186186

187187
# Subprogram access
188188
| (p@TypeDecl(f_type_def: AccessToSubpDef) |
@@ -191,26 +191,26 @@ fun identifier_prefixes(unit,
191191
when subprogram_access != "-"
192192
=>
193193
p?.p_previous_part() is (null | IncompleteTypeDecl) and
194-
((not node.f_name.text.starts_with(subprogram_access)) or
195-
check_exclusive(node.f_name.text,
196-
exclusive=exclusive,
197-
subprogram_access_exclusive=false))
194+
(if node.f_name.text.starts_with(subprogram_access)
195+
then check_exclusive(node.f_name.text,
196+
exclusive=exclusive,
197+
subprogram_access_exclusive=false))
198198

199199
# Other access types
200200
| (p@TypeDecl(f_type_def: AccessDef) |
201201
p@SubtypeDecl(p_canonical_type(): TypeDecl(f_type_def: AccessDef)))
202202
when access != "-"
203203
=>
204204
p?.p_previous_part() is (null | IncompleteTypeDecl) and
205-
((not node.f_name.text.starts_with(access)) or
206-
check_exclusive(node.f_name.text,
207-
exclusive=exclusive,
208-
access_exclusive=false,
209-
# If both an Access prefix and a Type prefix are
210-
# set and the type prefix is a prefix of the access
211-
# prefix, we don't want to flag this access because
212-
# it broke the exclusivity of the type prefix.
213-
type_exclusive=false))
205+
(if node.f_name.text.starts_with(access)
206+
then check_exclusive(node.f_name.text,
207+
exclusive=exclusive,
208+
access_exclusive=false,
209+
# If both an Access prefix and a Type prefix are
210+
# set and the type prefix is a prefix of the access
211+
# prefix, we don't want to flag this access because
212+
# it broke the exclusivity of the type prefix.
213+
type_exclusive=false))
214214

215215
# (Sub)Types derived from `derived`
216216
| p@(TypeDecl(f_type_def: DerivedTypeDef) | SubtypeDecl)
@@ -265,7 +265,7 @@ fun identifier_prefixes(unit,
265265
# Check all other defining names for exclusion except for completions
266266
# and renaming-as-body
267267
| p2 =>
268-
(not p2 is (BodyNode | SubpRenamingDecl) or not p2.p_previous_part()) and
269-
(not p2 is ObjectDecl or not node.p_previous_part()) and
268+
(if p2 is (BodyNode | SubpRenamingDecl) then not p2.p_previous_part()) and
269+
(if p2 is ObjectDecl then not node.p_previous_part()) and
270270
check_exclusive(node.f_name.text, exclusive=exclusive)]
271271
}

lkql_checker/share/lkql/incomplete_representation_specifications.lkql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
fun incomplete_representation_specifications(node) =
77
node is TypeDecl
88
when node.p_get_record_representation_clause()
9-
and ((not node.p_has_aspect("Size")) or not node.p_get_aspect("Pack").exists)
9+
and (if node.p_has_aspect("Size") then not node.p_get_aspect("Pack").exists)

lkql_checker/share/lkql/kp/KP-UA12-036.lkql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fun check_type(node, alignment) = {
2424

2525
fun message(n, alignment) = {
2626
val params = n.f_params;
27-
val type = (if not params[1].f_designator or
27+
val type = (if (not params[1].f_designator) or
2828
params[1].f_designator.p_name_is("object")
2929
then params[1] else params[2]).f_r_expr.p_referenced_decl();
3030
val res = if stdlib.is_classwide_type(type) then
@@ -42,7 +42,7 @@ fun kp_ua12_036(unit, alignment: int = 16) = [
4242
when stdlib.is_unchecked_deallocation(node)
4343
and node.f_params is params@AssocList
4444
when params.children_count == 2
45-
and if not params[1].f_designator or
45+
and if (not params[1].f_designator) or
4646
params[1].f_designator.p_name_is("object")
4747
then check_type(params[1], alignment)
4848
else check_type(params[2], alignment)]

lkql_checker/share/lkql/membership_tests.lkql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import stdlib
1414
@check(message="membership test", category="Feature")
1515
fun membership_tests(node, multi_alternative_only=false, float_types_only=false, except_assertions=false) =
1616
node is MembershipExpr
17-
and (not multi_alternative_only or node.f_membership_exprs[2])
17+
and (if multi_alternative_only then node.f_membership_exprs[2])
1818
and (not float_types_only
1919
or (node.f_expr.p_expression_type() is decl@BaseTypeDecl when
2020
decl.p_full_view().p_is_float_type()))

lkql_checker/share/lkql/misnamed_controlling_parameters.lkql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fun misnamed_controlling_parameters(node) =
2222
params and not
2323
(params[1].f_ids[1].f_name.p_name_is("this") and
2424
stdlib.is_controlling_param_type(params[1].f_type_expr, spec)) and
25-
(not stdlib.is_controlling_param_type(spec.p_returns(), spec) or
26-
[p for p in params
27-
if stdlib.is_controlling_param_type(p.f_type_expr, spec)])
25+
(if stdlib.is_controlling_param_type(spec.p_returns(), spec)
26+
then [p for p in params
27+
if stdlib.is_controlling_param_type(p.f_type_expr, spec)])
2828
}

lkql_checker/share/lkql/misplaced_representation_items.lkql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ fun misplaced_node(n, decl) =
4343
misplaced_node(r, decl)
4444
| a@AtClause => a.f_name.p_referenced_decl() != decl or
4545
misplaced_node(a, decl)
46-
| p@PragmaNode => (not is_rep_pragma(p.f_id)) or
47-
associated_decl(p) != decl or
48-
misplaced_node(p, decl)
46+
| p@PragmaNode => if is_rep_pragma(p.f_id)
47+
then associated_decl(p) != decl or
48+
misplaced_node(p, decl)
4949
| * => true
5050

5151
@check(message="misplaced representation item",

lkql_checker/share/lkql/no_others_in_exception_handlers.lkql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fun no_others_in_exception_handlers(unit,
2222
loc: n.f_exceptions.token_start().previous()})
2323
for n in from unit.root select
2424
((node@((TaskBody when task) | (SubpBody when subprogram))
25-
when not node.f_stmts.f_exceptions[1] or check_others(node.f_stmts))
25+
when if node.f_stmts.f_exceptions[1] then check_others(node.f_stmts))
2626
| node@HandledStmts
2727
when all_handlers and node.f_exceptions[1] and
2828
check_others(node))

0 commit comments

Comments
 (0)