Skip to content

Commit 799d459

Browse files
committed
Repair compound type weaving
This fixes issue https://forge.ispras.ru/issues/11369. The fix includes: - Update of Aspectator fixing the raw issue. - Enabling the appropriate test case (it was slightly extended and line directives were added to the expected output). - Describing one more related example in the tutorial.
1 parent bbff9ce commit 799d459

File tree

7 files changed

+114
-25
lines changed

7 files changed

+114
-25
lines changed

docs/samples/weave-struct-rectangle.aspect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ before: introduce(struct rectangle)
44
unsigned int perimeter;
55
}
66

7-
around: call(unsigned int calculate_rectangle_square(struct rectangle *r))
7+
before: call(unsigned int calculate_rectangle_square(struct rectangle *r))
88
{
99
/* Calculate, store and print rectangle perimeter in addition to square. */
1010
r->perimeter = r->height + r->width;

docs/tutorial.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ To test this aspect you can run the following commands::
111111
$ ./calculate-max-rectangle-square 2 5 7 3 4 4 8 9
112112
Maximum rectangle square is 21
113113

114+
Weaving compound types
115+
----------------------
116+
117+
CIF suggests means to modify compound types such as structures, unions and enumerations.
118+
For instance, you can find an example of an appropriate aspect in :numref:`weave-struct-rectangle-aspect`
119+
(:file:`weave-struct-rectangle.aspect` in :file:`docs/samples`).
120+
121+
.. literalinclude:: samples/weave-struct-rectangle.aspect
122+
:caption: Aspect file intended for weaving structure **rectangle**
123+
:name: weave-struct-rectangle-aspect
124+
:language: c
125+
126+
This aspect adds extra field *perimeter* to the definition of structure *rectangle*.
127+
Besides, through weaving of function *calculate_rectangle_square()* it calculates, stores and prints out perimeters for
128+
all rectangles.
129+
130+
To test this aspect you can run the following commands::
131+
132+
$ ../../inst/bin/cif --in calculate-max-rectangle-square.c --aspect weave-struct-rectangle.aspect --out calculate-max-rectangle-square --back-end bin
133+
$ ./calculate-max-rectangle-square 2 5 7 3 4 4 8 9
134+
Calculated rectangle perimeter is 7 (2 * 5)
135+
Calculated rectangle perimeter is 10 (7 * 3)
136+
Calculated rectangle perimeter is 8 (4 * 4)
137+
Calculated rectangle perimeter is 17 (8 * 9)
138+
Maximum rectangle square is 72
139+
114140
Querying source code
115141
--------------------
116142

tests/aspect/legacy_type.aspect

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,28 @@ before: introduce (struct b35)
5454
{
5555
int z;
5656
}
57+
after: introduce (struct b36)
58+
{
59+
int z;
60+
}
61+
5762
before: introduce (union b41)
5863
{
5964
int z;
6065
}
66+
after: introduce (union b42)
67+
{
68+
int z;
69+
}
70+
6171
before: introduce (enum b51)
6272
{
6373
C,
6474
D,
6575
}
6676
after: introduce (enum b52)
6777
{
68-
,
78+
,
6979
G,
7080
H
7181
}

tests/input/legacy_type.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,22 @@ struct b35
6060
int x;
6161
struct b35 *y;
6262
};
63+
struct b36
64+
{
65+
int x;
66+
struct b36 *y;
67+
};
6368

6469
union b41
6570
{
6671
int x:1;
6772
int y:2;
6873
};
74+
union b42
75+
{
76+
int x:1;
77+
int y:2;
78+
};
6979

7080
enum b51
7181
{

tests/output/legacy_type.c

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,144 @@ struct b11
22
{
33
int z;
44
};
5+
#line 4 "/home/novikov/work/cif/tests/input/legacy_type.c"
56
struct b12
67
{
78
int z;
8-
int x;
9+
int
10+
#line 6 "/home/novikov/work/cif/tests/input/legacy_type.c"
11+
x;
912
};
1013
struct b13
1114
{
1215
int z;
13-
int x;
16+
int
17+
#line 10 "/home/novikov/work/cif/tests/input/legacy_type.c"
18+
x;
1419
int y;
1520
};
1621
struct b14
1722
{
1823
int z;
19-
int x;
24+
int
25+
#line 15 "/home/novikov/work/cif/tests/input/legacy_type.c"
26+
x;
2027
int
2128
#line 15 "/home/novikov/work/cif/tests/input/legacy_type.c"
2229
y;
2330
};
2431
struct b15
2532
{
2633
int z;
27-
int x;
34+
int
35+
#line 19 "/home/novikov/work/cif/tests/input/legacy_type.c"
36+
x;
2837
double y;
2938
};
3039
struct b21
3140
{
3241
int z;
33-
int x;
42+
int
43+
#line 24 "/home/novikov/work/cif/tests/input/legacy_type.c"
44+
x;
3445
};
3546
struct b22
3647
{
3748
int z;
38-
struct b21 x;
49+
struct b21
50+
#line 28 "/home/novikov/work/cif/tests/input/legacy_type.c"
51+
x;
3952
};
4053
struct b23
4154
{
4255
int z;
43-
struct b21 x;
56+
struct b21
57+
#line 32 "/home/novikov/work/cif/tests/input/legacy_type.c"
58+
x;
4459
int y;
4560
};
4661
struct b24
4762
{
4863
int z;
49-
int x;
64+
int
65+
#line 37 "/home/novikov/work/cif/tests/input/legacy_type.c"
66+
x;
5067
struct b21 y;
5168
};
5269
struct b31
5370
{
5471
int z;
55-
int x;
72+
int
73+
#line 42 "/home/novikov/work/cif/tests/input/legacy_type.c"
74+
x;
5675
};
5776
struct b32
5877
{
5978
int z;
60-
struct b31 *x;
79+
struct b31
80+
#line 46 "/home/novikov/work/cif/tests/input/legacy_type.c"
81+
*x;
6182
};
6283
struct b33
6384
{
6485
int z;
65-
struct b31 *x;
86+
struct b31
87+
#line 50 "/home/novikov/work/cif/tests/input/legacy_type.c"
88+
*x;
6689
int y;
6790
};
6891
struct b34
6992
{
7093
int z;
71-
int x;
94+
int
95+
#line 55 "/home/novikov/work/cif/tests/input/legacy_type.c"
96+
x;
7297
struct b31 *y;
7398
};
7499
struct b35
75100
{
76101
int z;
77-
int x;
102+
int
103+
#line 60 "/home/novikov/work/cif/tests/input/legacy_type.c"
104+
x;
78105
struct b35 *y;
79106
};
80-
#line 64 "/home/novikov/work/cif/tests/input/legacy_type.c"
107+
struct b36
108+
{
109+
int x;
110+
struct b36 *y;
111+
int
112+
#line 68 "/home/novikov/work/cif/tests/input/legacy_type.c"
113+
z;
114+
};
115+
#line 69 "/home/novikov/work/cif/tests/input/legacy_type.c"
81116
union b41
82117
{
83118
int z;
119+
int
120+
#line 71 "/home/novikov/work/cif/tests/input/legacy_type.c"
121+
x : 1U;
122+
int y : 2U;
123+
};
124+
union b42
125+
{
84126
int x : 1U;
85127
int y : 2U;
128+
int
129+
#line 79 "/home/novikov/work/cif/tests/input/legacy_type.c"
130+
z;
86131
};
87132
enum b51
88133
{
89-
C,
90-
D,
91-
A = 0,
92-
B = 1
134+
C = 0,
135+
D = 1,
136+
A = 2,
137+
B = 3
93138
};
94139
enum b52
95140
{
96141
E = 0,
97142
F = 1,
98-
G,
99-
H
143+
G = 2,
144+
H = 3
100145
};

tests/test_legacy.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ def test_macro(self):
1111
self.cif.run(cif_input='input/legacy_macro.c', aspect='aspect/legacy_macro.aspect', cif_output='work/legacy_macro.c')
1212
self.compare(output='work/legacy_macro.c', expected='output/legacy_macro.c')
1313

14-
# Indeed, weaving complex types does not work at all (this is not the case for querying them).
15-
@pytest.mark.xfail
1614
def test_type(self):
1715
self.cif.run(cif_input='input/legacy_type.c', aspect='aspect/legacy_type.aspect', cif_output='work/legacy_type.c')
1816
self.compare(output='work/legacy_type.c', expected='output/legacy_type.c')

0 commit comments

Comments
 (0)