Skip to content

Commit

Permalink
Merge branch 'topic/1080' into 'master'
Browse files Browse the repository at this point in the history
Qualified expressions as code statements

Closes #1080

See merge request eng/libadalang/libadalang!1417
  • Loading branch information
thvnx committed Oct 2, 2023
2 parents c25c531 + a2f4930 commit 9804cab
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -19286,7 +19286,21 @@ def xref_equation():
& Bind(Self.prefix.ref_var, typ)
& Bind(Self.suffix.expected_type_var, typ)
& Entity.suffix.matches_expected_type
& Bind(Self.type_var, typ)
& Bind(
Self.type_var,
If(
# A qualified expression that appears as a statement
# denotes a machine code insertion, in GNAT, it is parsed
# as a parameterless procedure call. In that case,
# Self.type_var shouldn't denote any type. Note that we are
# more flexible than Ada since we allow any type to be code
# statements whereas Ada restricts that to types defined in
# package `System.Machine_Code` (see :rmlink:`13.8`).
Entity.parent.is_a(T.CallStmt),
No(AdaNode.entity),
typ
)
)
)

# TODO: once we manage to turn prefix into a subtype indication, remove
Expand Down
11 changes: 11 additions & 0 deletions testsuite/tests/name_resolution/qual_expr_stmt/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
with Machine_Code; use Machine_Code;

procedure Test is
procedure Code is
begin
Asm_Insn'(Asm ("nop"));
pragma Test_Statement;
end Code;
begin
Code;
end Test;
32 changes: 32 additions & 0 deletions testsuite/tests/name_resolution/qual_expr_stmt/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Analyzing test.adb
##################

Resolving xrefs for node <CallStmt test.adb:6:7-6:30>
*****************************************************

Expr: <QualExpr test.adb:6:7-6:29>
references: <DefiningName "Asm_Insn" s-maccod.ads:60:9-60:17>
type: None
expected type: None
Expr: <Id "Asm_Insn" test.adb:6:7-6:15>
references: <DefiningName "Asm_Insn" s-maccod.ads:60:9-60:17>
type: None
expected type: None
Expr: <ParenExpr test.adb:6:16-6:29>
type: <ConcreteTypeDecl ["Asm_Insn"] s-maccod.ads:60:4-60:29>
expected type: <ConcreteTypeDecl ["Asm_Insn"] s-maccod.ads:60:4-60:29>
Expr: <CallExpr test.adb:6:17-6:28>
references: <DefiningName "Asm" s-maccod.ads:113:13-113:16>
type: <ConcreteTypeDecl ["Asm_Insn"] s-maccod.ads:60:4-60:29>
expected type: <ConcreteTypeDecl ["Asm_Insn"] s-maccod.ads:60:4-60:29>
Expr: <Id "Asm" test.adb:6:17-6:20>
references: <DefiningName "Asm" s-maccod.ads:113:13-113:16>
type: <ConcreteTypeDecl ["Asm_Insn"] s-maccod.ads:60:4-60:29>
expected type: None
Expr: <Str ""nop"" test.adb:6:22-6:27>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>


Done.
2 changes: 2 additions & 0 deletions testsuite/tests/name_resolution/qual_expr_stmt/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: name-resolution
input_sources: [test.adb]

0 comments on commit 9804cab

Please sign in to comment.