1 # RUN: %PYTHON %s | FileCheck %s
8 print("\nTEST:", f
.__name
__)
11 assert Context
._get
_live
_count
() == 0
14 # CHECK-LABEL: TEST: testUnknown
16 with
Context() as ctx
:
17 loc
= Location
.unknown()
18 assert loc
.context
is ctx
21 # CHECK: unknown str: loc(unknown)
22 print("unknown str:", str(loc
))
23 # CHECK: unknown repr: loc(unknown)
24 print("unknown repr:", repr(loc
))
30 # CHECK-LABEL: TEST: testLocationAttr
31 def testLocationAttr():
32 with
Context() as ctxt
:
33 loc
= Location
.unknown()
35 clone
= Location
.from_attr(attr
)
37 # CHECK: loc: loc(unknown)
38 print("loc:", str(loc
))
39 # CHECK: clone: loc(unknown)
40 print("clone:", str(clone
))
46 # CHECK-LABEL: TEST: testFileLineCol
47 def testFileLineCol():
48 with
Context() as ctx
:
49 loc
= Location
.file("foo.txt", 123, 56)
52 # CHECK: file str: loc("foo.txt":123:56)
53 print("file str:", str(loc
))
54 # CHECK: file repr: loc("foo.txt":123:56)
55 print("file repr:", repr(loc
))
61 # CHECK-LABEL: TEST: testName
63 with
Context() as ctx
:
64 loc
= Location
.name("nombre")
65 locWithChildLoc
= Location
.name("naam", loc
)
68 # CHECK: file str: loc("nombre")
69 print("file str:", str(loc
))
70 # CHECK: file repr: loc("nombre")
71 print("file repr:", repr(loc
))
72 # CHECK: file str: loc("naam"("nombre"))
73 print("file str:", str(locWithChildLoc
))
74 # CHECK: file repr: loc("naam"("nombre"))
75 print("file repr:", repr(locWithChildLoc
))
81 # CHECK-LABEL: TEST: testCallSite
83 with
Context() as ctx
:
84 loc
= Location
.callsite(
85 Location
.file("foo.text", 123, 45),
86 [Location
.file("util.foo", 379, 21), Location
.file("main.foo", 100, 63)],
89 # CHECK: file str: loc(callsite("foo.text":123:45 at callsite("util.foo":379:21 at "main.foo":100:63))
90 print("file str:", str(loc
))
91 # CHECK: file repr: loc(callsite("foo.text":123:45 at callsite("util.foo":379:21 at "main.foo":100:63))
92 print("file repr:", repr(loc
))
98 # CHECK-LABEL: TEST: testFused
100 with
Context() as ctx
:
101 loc_single
= Location
.fused([Location
.name("apple")])
102 loc
= Location
.fused([Location
.name("apple"), Location
.name("banana")])
103 attr
= Attribute
.parse('"sauteed"')
104 loc_attr
= Location
.fused(
105 [Location
.name("carrot"), Location
.name("potatoes")], attr
107 loc_empty
= Location
.fused([])
108 loc_empty_attr
= Location
.fused([], attr
)
109 loc_single_attr
= Location
.fused([Location
.name("apple")], attr
)
111 # CHECK: file str: loc("apple")
112 print("file str:", str(loc_single
))
113 # CHECK: file repr: loc("apple")
114 print("file repr:", repr(loc_single
))
115 # CHECK: file str: loc(fused["apple", "banana"])
116 print("file str:", str(loc
))
117 # CHECK: file repr: loc(fused["apple", "banana"])
118 print("file repr:", repr(loc
))
119 # CHECK: file str: loc(fused<"sauteed">["carrot", "potatoes"])
120 print("file str:", str(loc_attr
))
121 # CHECK: file repr: loc(fused<"sauteed">["carrot", "potatoes"])
122 print("file repr:", repr(loc_attr
))
123 # CHECK: file str: loc(unknown)
124 print("file str:", str(loc_empty
))
125 # CHECK: file repr: loc(unknown)
126 print("file repr:", repr(loc_empty
))
127 # CHECK: file str: loc(fused<"sauteed">[unknown])
128 print("file str:", str(loc_empty_attr
))
129 # CHECK: file repr: loc(fused<"sauteed">[unknown])
130 print("file repr:", repr(loc_empty_attr
))
131 # CHECK: file str: loc(fused<"sauteed">["apple"])
132 print("file str:", str(loc_single_attr
))
133 # CHECK: file repr: loc(fused<"sauteed">["apple"])
134 print("file repr:", repr(loc_single_attr
))
140 # CHECK-LABEL: TEST: testLocationCapsule
141 def testLocationCapsule():
142 with
Context() as ctx
:
143 loc1
= Location
.file("foo.txt", 123, 56)
144 # CHECK: mlir.ir.Location._CAPIPtr
145 loc_capsule
= loc1
._CAPIPtr
147 loc2
= Location
._CAPICreate
(loc_capsule
)
149 assert loc2
.context
is ctx
152 run(testLocationCapsule
)