cshape 0.1.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cshape
3
- Version: 0.1.0
3
+ Version: 0.2.2
4
4
  Summary: A dependency-free C AST + printer: build a tree in Python, get C11 source back
5
5
  Author-email: Alex Balan <outsiders.b@gmail.com>
6
6
  License-Expression: MIT
@@ -38,14 +38,14 @@ pip install cshape
38
38
  from cshape import *
39
39
 
40
40
  func = CStmtDefFunc(
41
- id_str="add",
42
- type=CTypeFunc(
43
- params=[CField(id_str="a", type=CTypeNamed("int")),
44
- CField(id_str="b", type=CTypeNamed("int"))],
45
- to=CTypeNamed("int"),
41
+ id="add",
42
+ type=CTypeFunction(
43
+ params=[CField(id="a", type=CTypeIdentifier("int")),
44
+ CField(id="b", type=CTypeIdentifier("int"))],
45
+ to=CTypeIdentifier("int"),
46
46
  ),
47
47
  block=CStmtBlock([
48
- CStmtReturn(CValueAdd(CValueNamed("a"), CValueNamed("b"))),
48
+ CStmtReturn(CValueAdd(CValueIdentifier("a"), CValueIdentifier("b"))),
49
49
  ]),
50
50
  )
51
51
 
@@ -62,6 +62,12 @@ int add(int a, int b) {
62
62
  starts with a blank line by default, so `.strip()` if you're printing a
63
63
  single node standalone rather than concatenating several.)
64
64
 
65
+ ## Documentation
66
+
67
+ - [docs/api.md](docs/api.md) - documentation index
68
+ - [docs/quickstart.md](docs/quickstart.md) - getting started and first example
69
+ - [docs/reference.md](docs/reference.md) - current API reference
70
+
65
71
  ## What it covers
66
72
 
67
73
  - Types: named types, pointers, arrays, function types, structs/unions, enums
@@ -77,6 +83,9 @@ single node standalone rather than concatenating several.)
77
83
  - A `.mark` field on every node: set it to any string and it shows up as a
78
84
  `/*mark*/` comment right before that node in the output — useful for
79
85
  tracing which part of your own compiler/generator produced which bit of C
86
+ - A `.note` field on every value, printed as a `/* note */` comment *after*
87
+ the value — for saying where a value came from once it no longer shows:
88
+ `3.125 /* totalVolume / elementVolume */`
80
89
 
81
90
  ## What it doesn't do
82
91
 
@@ -20,14 +20,14 @@ pip install cshape
20
20
  from cshape import *
21
21
 
22
22
  func = CStmtDefFunc(
23
- id_str="add",
24
- type=CTypeFunc(
25
- params=[CField(id_str="a", type=CTypeNamed("int")),
26
- CField(id_str="b", type=CTypeNamed("int"))],
27
- to=CTypeNamed("int"),
23
+ id="add",
24
+ type=CTypeFunction(
25
+ params=[CField(id="a", type=CTypeIdentifier("int")),
26
+ CField(id="b", type=CTypeIdentifier("int"))],
27
+ to=CTypeIdentifier("int"),
28
28
  ),
29
29
  block=CStmtBlock([
30
- CStmtReturn(CValueAdd(CValueNamed("a"), CValueNamed("b"))),
30
+ CStmtReturn(CValueAdd(CValueIdentifier("a"), CValueIdentifier("b"))),
31
31
  ]),
32
32
  )
33
33
 
@@ -44,6 +44,12 @@ int add(int a, int b) {
44
44
  starts with a blank line by default, so `.strip()` if you're printing a
45
45
  single node standalone rather than concatenating several.)
46
46
 
47
+ ## Documentation
48
+
49
+ - [docs/api.md](docs/api.md) - documentation index
50
+ - [docs/quickstart.md](docs/quickstart.md) - getting started and first example
51
+ - [docs/reference.md](docs/reference.md) - current API reference
52
+
47
53
  ## What it covers
48
54
 
49
55
  - Types: named types, pointers, arrays, function types, structs/unions, enums
@@ -59,6 +65,9 @@ single node standalone rather than concatenating several.)
59
65
  - A `.mark` field on every node: set it to any string and it shows up as a
60
66
  `/*mark*/` comment right before that node in the output — useful for
61
67
  tracing which part of your own compiler/generator produced which bit of C
68
+ - A `.note` field on every value, printed as a `/* note */` comment *after*
69
+ the value — for saying where a value came from once it no longer shows:
70
+ `3.125 /* totalVolume / elementVolume */`
62
71
 
63
72
  ## What it doesn't do
64
73
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cshape
3
- Version: 0.1.0
3
+ Version: 0.2.2
4
4
  Summary: A dependency-free C AST + printer: build a tree in Python, get C11 source back
5
5
  Author-email: Alex Balan <outsiders.b@gmail.com>
6
6
  License-Expression: MIT
@@ -38,14 +38,14 @@ pip install cshape
38
38
  from cshape import *
39
39
 
40
40
  func = CStmtDefFunc(
41
- id_str="add",
42
- type=CTypeFunc(
43
- params=[CField(id_str="a", type=CTypeNamed("int")),
44
- CField(id_str="b", type=CTypeNamed("int"))],
45
- to=CTypeNamed("int"),
41
+ id="add",
42
+ type=CTypeFunction(
43
+ params=[CField(id="a", type=CTypeIdentifier("int")),
44
+ CField(id="b", type=CTypeIdentifier("int"))],
45
+ to=CTypeIdentifier("int"),
46
46
  ),
47
47
  block=CStmtBlock([
48
- CStmtReturn(CValueAdd(CValueNamed("a"), CValueNamed("b"))),
48
+ CStmtReturn(CValueAdd(CValueIdentifier("a"), CValueIdentifier("b"))),
49
49
  ]),
50
50
  )
51
51
 
@@ -62,6 +62,12 @@ int add(int a, int b) {
62
62
  starts with a blank line by default, so `.strip()` if you're printing a
63
63
  single node standalone rather than concatenating several.)
64
64
 
65
+ ## Documentation
66
+
67
+ - [docs/api.md](docs/api.md) - documentation index
68
+ - [docs/quickstart.md](docs/quickstart.md) - getting started and first example
69
+ - [docs/reference.md](docs/reference.md) - current API reference
70
+
65
71
  ## What it covers
66
72
 
67
73
  - Types: named types, pointers, arrays, function types, structs/unions, enums
@@ -77,6 +83,9 @@ single node standalone rather than concatenating several.)
77
83
  - A `.mark` field on every node: set it to any string and it shows up as a
78
84
  `/*mark*/` comment right before that node in the output — useful for
79
85
  tracing which part of your own compiler/generator produced which bit of C
86
+ - A `.note` field on every value, printed as a `/* note */` comment *after*
87
+ the value — for saying where a value came from once it no longer shows:
88
+ `3.125 /* totalVolume / elementVolume */`
80
89
 
81
90
  ## What it doesn't do
82
91
 
@@ -1,11 +1,31 @@
1
1
 
2
+
2
3
  nl_symbol = "\n"
3
4
  indent_symbol = "\t"
4
-
5
5
  indent_level = 0
6
6
 
7
7
 
8
8
 
9
+ legacy_style = {
10
+ 'LINE_BREAK_BEFORE_STRUCT_BRACE': False,
11
+ 'LINE_BREAK_BEFORE_FUNC_BRACE': False,
12
+ 'LINE_BREAK_BEFORE_BLOCK_BRACE': False,
13
+ }
14
+
15
+ modern_style = {
16
+ 'LINE_BREAK_BEFORE_STRUCT_BRACE': True,
17
+ 'LINE_BREAK_BEFORE_FUNC_BRACE': True,
18
+ 'LINE_BREAK_BEFORE_BLOCK_BRACE': True,
19
+ }
20
+
21
+ styles = {
22
+ 'legacy': legacy_style,
23
+ 'modern': modern_style,
24
+ }
25
+
26
+
27
+ styleguide = legacy_style
28
+
9
29
 
10
30
  def indent_up():
11
31
  global indent_level
@@ -17,13 +37,11 @@ def indent_down():
17
37
  indent_level = indent_level - 1
18
38
 
19
39
 
20
-
21
40
  def set_nl_symbol(x):
22
41
  global nl_symbol
23
42
  nl_symbol = x
24
43
 
25
44
 
26
-
27
45
  def str_indent():
28
46
  global indent_level
29
47
  global indent_symbol
@@ -37,41 +55,12 @@ def str_nl_indent(nl=1):
37
55
  return s
38
56
 
39
57
 
40
-
41
-
42
-
43
-
44
-
45
-
46
- legacy_style = {
47
- 'LINE_BREAK_BEFORE_STRUCT_BRACE': False,
48
- 'LINE_BREAK_BEFORE_FUNC_BRACE': False,
49
- 'LINE_BREAK_BEFORE_BLOCK_BRACE': False,
50
- }
51
-
52
- modern_style = {
53
- 'LINE_BREAK_BEFORE_STRUCT_BRACE': True,
54
- 'LINE_BREAK_BEFORE_FUNC_BRACE': True,
55
- 'LINE_BREAK_BEFORE_BLOCK_BRACE': True,
56
- }
57
-
58
- styles = {
59
- 'legacy': legacy_style,
60
- 'modern': modern_style,
61
- }
62
-
63
-
64
- # default style is legacy
65
- styleguide = legacy_style
66
-
67
-
68
- def render(node, style='legacy', indent='\t', newline='\n'):
58
+ def render(node, style='legacy', indent='\t'):
69
59
  global indent_level, styleguide, nl_symbol, indent_symbol
70
60
 
71
61
  saved = (indent_level, styleguide, nl_symbol, indent_symbol)
72
62
  indent_level = 0
73
63
  styleguide = styles[style]
74
- nl_symbol = newline
75
64
  indent_symbol = indent
76
65
 
77
66
  try:
@@ -94,9 +83,9 @@ def wrap_if(x, cond):
94
83
  return "(%s)" % x if cond else x
95
84
 
96
85
 
97
- def str_specs(specs):
86
+ def str_specs(specifiers):
98
87
  s = ''
99
- for opt in specs:
88
+ for opt in specifiers:
100
89
  s += opt + ' '
101
90
  return s
102
91
 
@@ -107,8 +96,6 @@ def with_space(s):
107
96
  return ''
108
97
 
109
98
 
110
-
111
-
112
99
  def str_gcc_attributes(attributes):
113
100
  if attributes == None:
114
101
  return ''
@@ -153,17 +140,12 @@ def str_gcc_attributes(attributes):
153
140
 
154
141
 
155
142
 
156
-
157
-
158
-
159
-
160
-
161
143
  class CField():
162
- def __init__(self, id_str, type, specs=None, nl=0):
144
+ def __init__(self, id, type, specifiers=None, nl=0):
163
145
  #assert(isinstance(type, CType))
164
- self.id_str = id_str
146
+ self.id = id
165
147
  self.type = type
166
- self.specs = specs if specs != None else []
148
+ self.specifiers = specifiers if specifiers != None else []
167
149
  self.nl = nl
168
150
 
169
151
 
@@ -177,12 +159,12 @@ class CType():
177
159
  return "<type> " + text
178
160
 
179
161
 
180
- class CTypeNamed(CType):
181
- def __init__(self, id_str, specs=None):
182
- assert(isinstance(id_str, str))
162
+ class CTypeIdentifier(CType):
163
+ def __init__(self, id, specifiers=None):
164
+ assert(isinstance(id, str))
183
165
  super().__init__()
184
- self.id_str = id_str
185
- self.specs = specs if specs != None else []
166
+ self.id = id
167
+ self.specifiers = specifiers if specifiers != None else []
186
168
  self.precedence = 0
187
169
 
188
170
  def to_str(self, text='', with_qualifiers=True):
@@ -190,22 +172,22 @@ class CTypeNamed(CType):
190
172
  sstr = ''
191
173
  if with_qualifiers:
192
174
  # for: const, volatile, restrict
193
- sstr += str_specs(self.specs)
194
- return sstr + self.id_str + with_space(text)
175
+ sstr += str_specs(self.specifiers)
176
+ return sstr + self.id + with_space(text)
195
177
 
196
178
 
197
179
  class CTypePointer(CType):
198
- def __init__(self, to, specs=None):
180
+ def __init__(self, to, specifiers=None):
199
181
  super().__init__()
200
182
  self.to = to
201
- self.specs = specs if specs != None else []
183
+ self.specifiers = specifiers if specifiers != None else []
202
184
  self.precedence = 1
203
185
 
204
186
  def to_str(self, text='', with_qualifiers=True):
205
187
  # "*volatile p"
206
188
  sstr = '*'
207
189
  if with_qualifiers:
208
- sstr += str_specs(self.specs)
190
+ sstr += str_specs(self.specifiers)
209
191
  sstr += text
210
192
  sstr = wrap_if(sstr, self.to.precedence > self.precedence)
211
193
  sstr = str_ctype(self.to, sstr)
@@ -213,31 +195,31 @@ class CTypePointer(CType):
213
195
 
214
196
 
215
197
  class CTypeArray(CType):
216
- def __init__(self, of, volume=None, specs=[]):
198
+ def __init__(self, item_type, size=None, specifiers=[]):
217
199
  super().__init__()
218
- of.specs = specs # array specs is array item specs (!)
219
- self.of = of
220
- self.volume = volume
221
- self.specs = specs if specs != None else []
200
+ item_type.specifiers = specifiers # array specs is array item specs (!)
201
+ self.item_type = item_type
202
+ self.size = size
203
+ self.specifiers = specifiers if specifiers != None else []
222
204
  self.precedence = 2
223
205
 
224
206
  def to_str(self, text='', with_qualifiers=True):
225
207
  text = text + '['
226
- if self.volume != None:
227
- text += str_cvalue(self.volume)
208
+ if self.size != None:
209
+ text += str_cvalue(self.size)
228
210
  text += ']'
229
- text = wrap_if(text, self.of.precedence > self.precedence)
230
- text = str_ctype(self.of, text)
211
+ text = wrap_if(text, self.item_type.precedence > self.precedence)
212
+ text = str_ctype(self.item_type, text)
231
213
  return text
232
214
 
233
215
 
234
- class CTypeFunc(CType):
235
- def __init__(self, params, to, volume=None, extra_args=False, specs=None):
216
+ class CTypeFunction(CType):
217
+ def __init__(self, params, to, size=None, extra_args=False, specifiers=None):
236
218
  super().__init__()
237
219
  self.params = params
238
220
  self.to = to
239
221
  self.extra_args = extra_args
240
- self.specs = specs if specs != None else []
222
+ self.specifiers = specifiers if specifiers != None else []
241
223
  self.precedence = 3
242
224
 
243
225
  def to_str(self, text='', with_qualifiers=True):
@@ -246,7 +228,7 @@ class CTypeFunc(CType):
246
228
  params = self.params
247
229
  while i < len(params):
248
230
  param = params[i]
249
- p = str_ctype(param.type, text=param.id_str)
231
+ p = str_ctype(param.type, text=param.id)
250
232
  if i > 0:
251
233
  params_text += ', ' + p
252
234
  else:
@@ -265,11 +247,11 @@ class CTypeFunc(CType):
265
247
 
266
248
 
267
249
  class CTypeStruct(CType):
268
- def __init__(self, fields, tag, specs=None):
250
+ def __init__(self, fields, tag, specifiers=None):
269
251
  super().__init__()
270
252
  self.fields = fields
271
253
  self.tag = tag
272
- self.specs = specs if specs != None else []
254
+ self.specifiers = specifiers if specifiers != None else []
273
255
  self.precedence = 0
274
256
 
275
257
  def to_str(self, text='', with_qualifiers=True):
@@ -295,7 +277,7 @@ class CTypeStruct(CType):
295
277
  sstr += ' '
296
278
 
297
279
  sstr += str_nl_indent(field.nl)
298
- sstr += str_ctype(field.type, text=field.id_str) + ';'
280
+ sstr += str_ctype(field.type, text=field.id) + ';'
299
281
  i = i + 1
300
282
  else:
301
283
  sstr += 'uint8_t __placeholder;'
@@ -305,7 +287,8 @@ class CTypeStruct(CType):
305
287
 
306
288
 
307
289
 
308
- class CTypeEnumItem():
290
+
291
+ class CEnumItem():
309
292
  def __init__(self, id, value=None):
310
293
  assert(isinstance(id, str))
311
294
  assert(value == None or isinstance(value, CValue))
@@ -321,11 +304,11 @@ class CTypeEnumItem():
321
304
 
322
305
 
323
306
  class CTypeEnum(CType):
324
- def __init__(self, items, tag='', specs=None):
307
+ def __init__(self, items, tag='', specifiers=None):
325
308
  super().__init__()
326
309
  self.items = items
327
310
  self.tag = tag
328
- self.specs = specs if specs != None else []
311
+ self.specifiers = specifiers if specifiers != None else []
329
312
  self.precedence = 0
330
313
 
331
314
  def to_str(self, text='', with_qualifiers=True):
@@ -342,7 +325,7 @@ class CTypeEnum(CType):
342
325
 
343
326
  while i < nitems:
344
327
  item = self.items[i]
345
- assert(isinstance(item, CTypeEnumItem))
328
+ assert(isinstance(item, CEnumItem))
346
329
  if item.nl > 0:
347
330
  nl_end = 1
348
331
 
@@ -406,25 +389,26 @@ class KV():
406
389
 
407
390
 
408
391
  class CValue():
409
- def __init__(self):
392
+ def __init__(self, nl=0):
410
393
  self.mark = None
394
+ self.nl = nl
411
395
 
412
396
 
413
- class CValueNamed(CValue):
414
- def __init__(self, id_str):
415
- super().__init__()
416
- self.id_str = id_str
397
+ class CValueIdentifier(CValue):
398
+ def __init__(self, id, nl=0):
399
+ super().__init__(nl=nl)
400
+ self.id = id
417
401
  self.precedence = 15
418
402
 
419
403
  def __str__(self):
420
- return self.id_str
404
+ return self.id
421
405
 
422
406
 
423
407
 
424
408
 
425
409
  class CValueInteger(CValue):
426
- def __init__(self, number, as_hex=False, nsigns=0, suffix=''):
427
- super().__init__()
410
+ def __init__(self, number, as_hex=False, nsigns=0, suffix='', nl=0):
411
+ super().__init__(nl=nl)
428
412
  assert(isinstance(number, int))
429
413
  assert(isinstance(as_hex, bool))
430
414
  self.precedence = 15
@@ -452,9 +436,9 @@ def string_literal_prefix(width):
452
436
 
453
437
 
454
438
  class CValueString(CValue):
455
- def __init__(self, string, width):
439
+ def __init__(self, string, width, nl=0):
456
440
  assert(isinstance(string, str))
457
- super().__init__()
441
+ super().__init__(nl=nl)
458
442
  self.string = string
459
443
  self.width = width
460
444
  self.precedence = 15
@@ -486,9 +470,9 @@ def code_to_char(cc):
486
470
 
487
471
 
488
472
  class CValueChar(CValue):
489
- def __init__(self, cc, width=8):
473
+ def __init__(self, cc, width=8, nl=0):
490
474
  assert(isinstance(cc, int))
491
- super().__init__()
475
+ super().__init__(nl=nl)
492
476
  self.char_code = cc
493
477
  self.width = width
494
478
  self.precedence = 15
@@ -499,8 +483,8 @@ class CValueChar(CValue):
499
483
 
500
484
 
501
485
  class CValueArray(CValue):
502
- def __init__(self, items):
503
- super().__init__()
486
+ def __init__(self, items, nl=0):
487
+ super().__init__(nl=nl)
504
488
  self.items = items
505
489
  self.precedence = 15
506
490
 
@@ -531,8 +515,8 @@ class CValueArray(CValue):
531
515
 
532
516
 
533
517
  class CValueStruct(CValue):
534
- def __init__(self, items):
535
- super().__init__()
518
+ def __init__(self, items, nl=0):
519
+ super().__init__(nl=nl)
536
520
  self.items = items
537
521
  self.precedence = 15
538
522
 
@@ -571,15 +555,15 @@ class CValueStruct(CValue):
571
555
 
572
556
 
573
557
 
574
- class CValueSubexpr(CValue):
575
- def __init__(self, value):
558
+ class CValueParen(CValue):
559
+ def __init__(self, value, nl=0):
576
560
  assert(isinstance(value, CValue))
577
- super().__init__()
561
+ super().__init__(nl=nl)
578
562
  self.value = value
579
563
  self.precedence = 15
580
564
 
581
565
  def __str__(self):
582
- return '(%s)' % str_cvalue(self.value, ext_precedence=self.precedence)
566
+ return str_cvalue(self.value, ext_precedence=valuePrecedenceMax)
583
567
 
584
568
 
585
569
 
@@ -596,30 +580,30 @@ class CValueCall(CValue):
596
580
  return '%s(%s)' % (str_cvalue(self.left, ext_precedence=self.precedence), print_list_items(self.args, str_cvalue))
597
581
 
598
582
 
599
- class CValueAccess(CValue):
600
- def __init__(self, left, field_id_str):
601
- assert(isinstance(field_id_str, str))
583
+ class CValueFieldAccess(CValue):
584
+ def __init__(self, left, field_id):
585
+ assert(isinstance(field_id, str))
602
586
  assert(isinstance(left, CValue))
603
587
  super().__init__()
604
588
  self.left = left
605
- self.field_id_str = field_id_str
589
+ self.field_id = field_id
606
590
  self.precedence = 14
607
591
 
608
592
  def __str__(self):
609
- return '%s.%s' % (str_cvalue(self.left, ext_precedence=self.precedence), self.field_id_str)
593
+ return '%s.%s' % (str_cvalue(self.left, ext_precedence=self.precedence), self.field_id)
610
594
 
611
595
 
612
- class CValueAccessPtr(CValue):
613
- def __init__(self, left, field_id_str):
614
- assert(isinstance(field_id_str, str))
596
+ class CValuePtrFieldAccess(CValue):
597
+ def __init__(self, left, field_id):
598
+ assert(isinstance(field_id, str))
615
599
  assert(isinstance(left, CValue))
616
600
  super().__init__()
617
601
  self.left = left
618
- self.field_id_str = field_id_str
602
+ self.field_id = field_id
619
603
  self.precedence = 14
620
604
 
621
605
  def __str__(self):
622
- return '%s->%s' % (str_cvalue(self.left, ext_precedence=self.precedence), self.field_id_str)
606
+ return '%s->%s' % (str_cvalue(self.left, ext_precedence=self.precedence), self.field_id)
623
607
 
624
608
 
625
609
  class CValueIndex(CValue):
@@ -650,7 +634,7 @@ class CValueCast(CValue):
650
634
  return '(%s)%s' % (str_ctype(self.type, with_qualifiers=False), vstr)
651
635
 
652
636
 
653
- class CValueRef(CValue):
637
+ class CValueReference(CValue):
654
638
  def __init__(self, value):
655
639
  assert(isinstance(value, CValue))
656
640
  super().__init__()
@@ -661,7 +645,7 @@ class CValueRef(CValue):
661
645
  return '&%s' % str_cvalue(self.value, ext_precedence=self.precedence)
662
646
 
663
647
 
664
- class CValueDeref(CValue):
648
+ class CValueDereference(CValue):
665
649
  def __init__(self, value):
666
650
  assert(isinstance(value, CValue))
667
651
  super().__init__()
@@ -672,29 +656,7 @@ class CValueDeref(CValue):
672
656
  return '*%s' % str_cvalue(self.value, ext_precedence=self.precedence)
673
657
 
674
658
 
675
- class CValueInc(CValue):
676
- def __init__(self, value):
677
- assert(isinstance(value, CValue))
678
- super().__init__()
679
- self.value = value
680
- self.precedence = 13
681
-
682
- def __str__(self):
683
- return '++%s' % (str_cvalue(self.value, ext_precedence=self.precedence))
684
-
685
-
686
- class CValueDec(CValue):
687
- def __init__(self, value):
688
- assert(isinstance(value, CValue))
689
- super().__init__()
690
- self.value = value
691
- self.precedence = 13
692
-
693
- def __str__(self):
694
- return '--%s' % str_cvalue(self.value, ext_precedence=self.precedence)
695
-
696
-
697
- class CValuePositive(CValue):
659
+ class CValueUnaryPlus(CValue):
698
660
  def __init__(self, value):
699
661
  assert(isinstance(value, CValue))
700
662
  super().__init__()
@@ -705,7 +667,7 @@ class CValuePositive(CValue):
705
667
  return '+%s' % (str_cvalue(self.value, ext_precedence=self.precedence))
706
668
 
707
669
 
708
- class CValueNegative(CValue):
670
+ class CValueUnaryMinus(CValue):
709
671
  def __init__(self, value):
710
672
  assert(isinstance(value, CValue))
711
673
  super().__init__()
@@ -716,7 +678,7 @@ class CValueNegative(CValue):
716
678
  return '-%s' % (str_cvalue(self.value, ext_precedence=self.precedence))
717
679
 
718
680
 
719
- class CValueNotLogical(CValue):
681
+ class CValueLogicalNot(CValue):
720
682
  def __init__(self, value):
721
683
  assert(isinstance(value, CValue))
722
684
  super().__init__()
@@ -727,7 +689,7 @@ class CValueNotLogical(CValue):
727
689
  return '!%s' % (str_cvalue(self.value, ext_precedence=self.precedence))
728
690
 
729
691
 
730
- class CValueNotBitwise(CValue):
692
+ class CValueBitwiseNot(CValue):
731
693
  def __init__(self, value):
732
694
  assert(isinstance(value, CValue))
733
695
  super().__init__()
@@ -771,7 +733,7 @@ class CValueMul(CValue):
771
733
 
772
734
  def __str__(self):
773
735
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
774
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
736
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
775
737
  return '%s * %s' % (lx, rx)
776
738
 
777
739
 
@@ -786,11 +748,11 @@ class CValueDiv(CValue):
786
748
 
787
749
  def __str__(self):
788
750
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
789
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
751
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
790
752
  return '%s / %s' % (lx, rx)
791
753
 
792
754
 
793
- class CValueRem(CValue):
755
+ class CValueMod(CValue):
794
756
  def __init__(self, left, right):
795
757
  assert(isinstance(left, CValue))
796
758
  assert(isinstance(right, CValue))
@@ -801,7 +763,7 @@ class CValueRem(CValue):
801
763
 
802
764
  def __str__(self):
803
765
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
804
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
766
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
805
767
  return '%s %% %s' % (lx, rx)
806
768
 
807
769
 
@@ -816,7 +778,7 @@ class CValueAdd(CValue):
816
778
 
817
779
  def __str__(self):
818
780
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
819
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
781
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
820
782
  return '%s + %s' % (lx, rx)
821
783
 
822
784
 
@@ -831,11 +793,11 @@ class CValueSub(CValue):
831
793
 
832
794
  def __str__(self):
833
795
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
834
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
796
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
835
797
  return '%s - %s' % (lx, rx)
836
798
 
837
799
 
838
- class CValueShl(CValue):
800
+ class CValueShiftLeft(CValue):
839
801
  def __init__(self, left, right):
840
802
  assert(isinstance(left, CValue))
841
803
  assert(isinstance(right, CValue))
@@ -850,7 +812,7 @@ class CValueShl(CValue):
850
812
  lprec = self.precedence
851
813
  if self.left.precedence == self.precedence + 1:
852
814
  lprec = valuePrecedenceMax
853
- rprec = self.precedence
815
+ rprec = self.precedence + 1
854
816
  if self.right.precedence == self.precedence + 1:
855
817
  rprec = valuePrecedenceMax
856
818
 
@@ -859,7 +821,7 @@ class CValueShl(CValue):
859
821
  return '%s << %s' % (lx, rx)
860
822
 
861
823
 
862
- class CValueShr(CValue):
824
+ class CValueShiftRight(CValue):
863
825
  def __init__(self, left, right):
864
826
  assert(isinstance(left, CValue))
865
827
  assert(isinstance(right, CValue))
@@ -874,7 +836,7 @@ class CValueShr(CValue):
874
836
  lprec = self.precedence
875
837
  if self.left.precedence == self.precedence + 1:
876
838
  lprec = valuePrecedenceMax
877
- rprec = self.precedence
839
+ rprec = self.precedence + 1
878
840
  if self.right.precedence == self.precedence + 1:
879
841
  rprec = valuePrecedenceMax
880
842
 
@@ -894,7 +856,7 @@ class CValueLt(CValue):
894
856
 
895
857
  def __str__(self):
896
858
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
897
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
859
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
898
860
  return '%s < %s' % (lx, rx)
899
861
 
900
862
 
@@ -909,7 +871,7 @@ class CValueGt(CValue):
909
871
 
910
872
  def __str__(self):
911
873
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
912
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
874
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
913
875
  return '%s > %s' % (lx, rx)
914
876
 
915
877
 
@@ -924,7 +886,7 @@ class CValueLE(CValue):
924
886
 
925
887
  def __str__(self):
926
888
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
927
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
889
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
928
890
  return '%s <= %s' % (lx, rx)
929
891
 
930
892
 
@@ -939,7 +901,7 @@ class CValueGE(CValue):
939
901
 
940
902
  def __str__(self):
941
903
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
942
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
904
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
943
905
  return '%s >= %s' % (lx, rx)
944
906
 
945
907
 
@@ -954,7 +916,7 @@ class CValueEq(CValue):
954
916
 
955
917
  def __str__(self):
956
918
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
957
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
919
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
958
920
  return '%s == %s' % (lx, rx)
959
921
 
960
922
 
@@ -969,7 +931,7 @@ class CValueNe(CValue):
969
931
 
970
932
  def __str__(self):
971
933
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
972
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
934
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
973
935
  return '%s != %s' % (lx, rx)
974
936
 
975
937
 
@@ -982,7 +944,7 @@ def select_prio_plus(sp, xp, n=0):
982
944
  return sp
983
945
 
984
946
 
985
- class CValueAndBitwise(CValue):
947
+ class CValueBitwiseAnd(CValue):
986
948
  def __init__(self, left, right):
987
949
  assert(isinstance(left, CValue))
988
950
  assert(isinstance(right, CValue))
@@ -993,11 +955,11 @@ class CValueAndBitwise(CValue):
993
955
 
994
956
  def __str__(self):
995
957
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
996
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
958
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
997
959
  return '%s & %s' % (lx, rx)
998
960
 
999
961
 
1000
- class CValueXorBitwise(CValue):
962
+ class CValueBitwiseXor(CValue):
1001
963
  def __init__(self, left, right):
1002
964
  assert(isinstance(left, CValue))
1003
965
  assert(isinstance(right, CValue))
@@ -1008,11 +970,11 @@ class CValueXorBitwise(CValue):
1008
970
 
1009
971
  def __str__(self):
1010
972
  lx = str_cvalue(self.left, ext_precedence=select_prio_plus(self.precedence, self.left.precedence, n=1))
1011
- rx = str_cvalue(self.right, ext_precedence=select_prio_plus(self.precedence, self.right.precedence, n=1))
973
+ rx = str_cvalue(self.right, ext_precedence=max(self.precedence + 1, select_prio_plus(self.precedence, self.right.precedence, n=1)))
1012
974
  return '%s ^ %s' % (lx, rx)
1013
975
 
1014
976
 
1015
- class CValueOrBitwise(CValue):
977
+ class CValueBitwiseOr(CValue):
1016
978
  def __init__(self, left, right):
1017
979
  assert(isinstance(left, CValue))
1018
980
  assert(isinstance(right, CValue))
@@ -1023,11 +985,11 @@ class CValueOrBitwise(CValue):
1023
985
 
1024
986
  def __str__(self):
1025
987
  lx = str_cvalue(self.left, ext_precedence=select_prio_plus(self.precedence, self.left.precedence, n=2))
1026
- rx = str_cvalue(self.right, ext_precedence=select_prio_plus(self.precedence, self.right.precedence, n=2))
988
+ rx = str_cvalue(self.right, ext_precedence=max(self.precedence + 1, select_prio_plus(self.precedence, self.right.precedence, n=2)))
1027
989
  return '%s | %s' % (lx, rx)
1028
990
 
1029
991
 
1030
- class CValueAndLogical(CValue):
992
+ class CValueLogicalAnd(CValue):
1031
993
  def __init__(self, left, right):
1032
994
  assert(isinstance(left, CValue))
1033
995
  assert(isinstance(right, CValue))
@@ -1038,11 +1000,11 @@ class CValueAndLogical(CValue):
1038
1000
 
1039
1001
  def __str__(self):
1040
1002
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
1041
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
1003
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
1042
1004
  return '%s && %s' % (lx, rx)
1043
1005
 
1044
1006
 
1045
- class CValueOrLogical(CValue):
1007
+ class CValueLogicalOr(CValue):
1046
1008
  def __init__(self, left, right):
1047
1009
  assert(isinstance(left, CValue))
1048
1010
  assert(isinstance(right, CValue))
@@ -1053,7 +1015,7 @@ class CValueOrLogical(CValue):
1053
1015
 
1054
1016
  def __str__(self):
1055
1017
  lx = str_cvalue(self.left, ext_precedence=select_prio_plus(self.precedence, self.left.precedence, n=1))
1056
- rx = str_cvalue(self.right, ext_precedence=select_prio_plus(self.precedence, self.right.precedence, n=1))
1018
+ rx = str_cvalue(self.right, ext_precedence=max(self.precedence + 1, select_prio_plus(self.precedence, self.right.precedence, n=1)))
1057
1019
  return '%s || %s' % (lx, rx)
1058
1020
 
1059
1021
 
@@ -1109,7 +1071,7 @@ class CValueVaCopy(CValue):
1109
1071
 
1110
1072
 
1111
1073
  # string concat
1112
- class CValueCat(CValue):
1074
+ class CValueStringConcat(CValue):
1113
1075
  def __init__(self, left, right):
1114
1076
  assert(isinstance(left, CValue))
1115
1077
  assert(isinstance(right, CValue))
@@ -1120,7 +1082,7 @@ class CValueCat(CValue):
1120
1082
 
1121
1083
  def __str__(self):
1122
1084
  lx = str_cvalue(self.left, ext_precedence=self.precedence)
1123
- rx = str_cvalue(self.right, ext_precedence=self.precedence)
1085
+ rx = str_cvalue(self.right, ext_precedence=self.precedence + 1)
1124
1086
  return lx + ' ' + rx
1125
1087
 
1126
1088
 
@@ -1158,7 +1120,7 @@ class CStmt():
1158
1120
  pass
1159
1121
 
1160
1122
 
1161
- class CStmtCommentLine(CStmt):
1123
+ class CStmtLineComment(CStmt):
1162
1124
  def __init__(self, lines):
1163
1125
  assert(isinstance(lines, list))
1164
1126
  super().__init__()
@@ -1179,7 +1141,7 @@ class CStmtCommentLine(CStmt):
1179
1141
  return sstr
1180
1142
 
1181
1143
 
1182
- class CStmtCommentBlock(CStmt):
1144
+ class CStmtBlockComment(CStmt):
1183
1145
  def __init__(self, text):
1184
1146
  assert(isinstance(text, str))
1185
1147
  super().__init__()
@@ -1212,7 +1174,7 @@ class CStmtBlock(CStmt):
1212
1174
  return sstr
1213
1175
 
1214
1176
 
1215
- class CStmtValueExpr(CStmt):
1177
+ class CStmtExpr(CStmt):
1216
1178
  def __init__(self, value):
1217
1179
  assert(isinstance(value, CValue))
1218
1180
  super().__init__()
@@ -1224,7 +1186,7 @@ class CStmtValueExpr(CStmt):
1224
1186
  return sstr + str_cvalue(self.value) + ';'
1225
1187
 
1226
1188
 
1227
- class CStmtValueAssign(CStmt):
1189
+ class CStmtAssignment(CStmt):
1228
1190
  def __init__(self, lvalue, rvalue):
1229
1191
  assert(isinstance(lvalue, CValue))
1230
1192
  assert(isinstance(rvalue, CValue))
@@ -1237,7 +1199,7 @@ class CStmtValueAssign(CStmt):
1237
1199
  return sstr + "%s = %s;" % (str_cvalue(self.lvalue), str_cvalue(self.rvalue))
1238
1200
 
1239
1201
 
1240
- class CStmtInc(CStmt):
1202
+ class CStmtIncrement(CStmt):
1241
1203
  def __init__(self, value):
1242
1204
  assert(isinstance(value, CValue))
1243
1205
  super().__init__()
@@ -1247,7 +1209,7 @@ class CStmtInc(CStmt):
1247
1209
  return str_nl_indent(self.nl) + "++%s;" % str_cvalue(self.value)
1248
1210
 
1249
1211
 
1250
- class CStmtDec(CStmt):
1212
+ class CStmtDecrement(CStmt):
1251
1213
  def __init__(self, value):
1252
1214
  assert(isinstance(value, CValue))
1253
1215
  super().__init__()
@@ -1259,7 +1221,7 @@ class CStmtDec(CStmt):
1259
1221
 
1260
1222
  class CStmtDeclType(CStmt):
1261
1223
  def __init__(self, type, attributes=None):
1262
- assert(isinstance(type, CTypeNamed))
1224
+ assert(isinstance(type, CTypeIdentifier))
1263
1225
  super().__init__()
1264
1226
  self.type = type
1265
1227
  self.attributes = attributes
@@ -1272,33 +1234,33 @@ class CStmtDeclType(CStmt):
1272
1234
 
1273
1235
 
1274
1236
  class CStmtDefType(CStmt):
1275
- def __init__(self, id_str, type, attributes=None):
1276
- assert(isinstance(id_str, str))
1237
+ def __init__(self, id, type, attributes=None):
1238
+ assert(isinstance(id, str))
1277
1239
  assert(isinstance(type, CType))
1278
1240
  super().__init__()
1279
- self.id_str = id_str
1241
+ self.id = id
1280
1242
  self.type = type
1281
1243
  self.attributes = attributes
1282
1244
 
1283
1245
  def __str__(self):
1284
1246
  sstr = str_nl_indent(self.nl)
1285
1247
  sstr += str_gcc_attributes(self.attributes)
1286
- sstr += 'typedef %s;' % self.type.to_str(text=self.id_str)
1248
+ sstr += 'typedef %s;' % self.type.to_str(text=self.id)
1287
1249
  return sstr
1288
1250
 
1289
1251
 
1290
1252
 
1291
1253
  class CStmtDefVar(CStmt):
1292
- def __init__(self, id_str, type, init_value=None, storage_class='', attributes=None):
1293
- assert(isinstance(id_str, str))
1254
+ def __init__(self, id, type, initializer=None, storage_class='', attributes=None):
1255
+ assert(isinstance(id, str))
1294
1256
  assert(isinstance(type, CType))
1295
- if init_value != None:
1296
- assert(isinstance(init_value, CValue))
1257
+ if initializer != None:
1258
+ assert(isinstance(initializer, CValue))
1297
1259
  super().__init__()
1298
- self.id_str = id_str
1260
+ self.id = id
1299
1261
  self.type = type
1300
1262
  self.storage = storage_class
1301
- self.init_value = init_value
1263
+ self.initializer = initializer
1302
1264
  self.attributes = attributes
1303
1265
 
1304
1266
  def __str__(self):
@@ -1307,22 +1269,22 @@ class CStmtDefVar(CStmt):
1307
1269
  if self.storage not in (None, ''):
1308
1270
  sstr += self.storage + ' '
1309
1271
  #mass
1310
- sstr += str_ctype(self.type, text=self.id_str)
1311
- if self.init_value != None:
1312
- sstr += ' = %s' % str_cvalue(self.init_value)
1272
+ sstr += str_ctype(self.type, text=self.id)
1273
+ if self.initializer != None:
1274
+ sstr += ' = %s' % str_cvalue(self.initializer)
1313
1275
  return sstr + ';'
1314
1276
 
1315
1277
 
1316
1278
 
1317
1279
  class CStmtDefFunc(CStmt):
1318
- def __init__(self, id_str, type, block, storage_class='', attributes=None):
1319
- assert(isinstance(id_str, str))
1280
+ def __init__(self, id, type, block, storage_class='', attributes=None):
1281
+ assert(isinstance(id, str))
1320
1282
  assert(isinstance(type, CType))
1321
1283
  assert(isinstance(block, CStmtBlock))
1322
1284
  #if init_value != None:
1323
1285
  # assert(isinstance(init_value, CValue))
1324
1286
  super().__init__()
1325
- self.id_str = id_str
1287
+ self.id = id
1326
1288
  self.type = type
1327
1289
  self.storage = storage_class
1328
1290
  self.block = block
@@ -1334,7 +1296,7 @@ class CStmtDefFunc(CStmt):
1334
1296
  sstr += str_gcc_attributes(self.attributes)
1335
1297
  if self.storage not in (None, ''):
1336
1298
  sstr += self.storage + ' '
1337
- sstr += self.type.to_str(text=self.id_str)
1299
+ sstr += self.type.to_str(text=self.id)
1338
1300
 
1339
1301
  if styleguide['LINE_BREAK_BEFORE_FUNC_BRACE']:
1340
1302
  sstr += str_nl_indent()
@@ -1347,49 +1309,49 @@ class CStmtDefFunc(CStmt):
1347
1309
 
1348
1310
 
1349
1311
  class CStmtIf(CStmt):
1350
- def __init__(self, value_cond, block_then, block_else):
1351
- assert(isinstance(value_cond, CValue))
1352
- assert(isinstance(block_then, CStmtBlock))
1353
- if block_else:
1354
- assert((isinstance(block_else, CStmtBlock) or isinstance(block_else, CStmtIf)))
1312
+ def __init__(self, condition, then_block, else_block):
1313
+ assert(isinstance(condition, CValue))
1314
+ assert(isinstance(then_block, CStmtBlock))
1315
+ if else_block:
1316
+ assert((isinstance(else_block, CStmtBlock) or isinstance(else_block, CStmtIf)))
1355
1317
  super().__init__()
1356
- self.value_cond = value_cond
1357
- self.block_then = block_then
1358
- self.block_else = block_else
1318
+ self.condition = condition
1319
+ self.then_block = then_block
1320
+ self.else_block = else_block
1359
1321
 
1360
1322
  def __str__(self):
1361
1323
  sstr = str_nl_indent(self.nl)
1362
- sstr += "if (%s)" % str_cvalue(self.value_cond)
1324
+ sstr += "if (%s)" % str_cvalue(self.condition)
1363
1325
  if styleguide['LINE_BREAK_BEFORE_BLOCK_BRACE']:
1364
1326
  sstr += str_nl_indent()
1365
1327
  else:
1366
1328
  sstr += ' '
1367
- sstr += str(self.block_then)
1368
- if self.block_else != None:
1329
+ sstr += str(self.then_block)
1330
+ if self.else_block != None:
1369
1331
  if styleguide['LINE_BREAK_BEFORE_BLOCK_BRACE']:
1370
1332
  sstr += str_nl_indent()
1371
1333
  else:
1372
1334
  sstr += ' '
1373
1335
  sstr += 'else'
1374
- if isinstance(self.block_else, CStmtBlock) and styleguide['LINE_BREAK_BEFORE_BLOCK_BRACE']:
1336
+ if isinstance(self.else_block, CStmtBlock) and styleguide['LINE_BREAK_BEFORE_BLOCK_BRACE']:
1375
1337
  sstr += str_nl_indent()
1376
1338
  else:
1377
1339
  sstr += ' '
1378
- sstr += str(self.block_else)
1340
+ sstr += str(self.else_block)
1379
1341
  return sstr
1380
1342
 
1381
1343
 
1382
1344
  class CStmtWhile(CStmt):
1383
- def __init__(self, value_cond, block):
1384
- assert(isinstance(value_cond, CValue))
1345
+ def __init__(self, condition, block):
1346
+ assert(isinstance(condition, CValue))
1385
1347
  assert(isinstance(block, CStmtBlock))
1386
1348
  super().__init__()
1387
- self.value_cond = value_cond
1349
+ self.condition = condition
1388
1350
  self.block = block
1389
1351
 
1390
1352
  def __str__(self):
1391
1353
  sstr = str_nl_indent(self.nl)
1392
- sstr += "while (%s)" % str_cvalue(self.value_cond)
1354
+ sstr += "while (%s)" % str_cvalue(self.condition)
1393
1355
  if styleguide['LINE_BREAK_BEFORE_BLOCK_BRACE']:
1394
1356
  sstr += str_nl_indent()
1395
1357
  else:
@@ -1399,17 +1361,17 @@ class CStmtWhile(CStmt):
1399
1361
 
1400
1362
 
1401
1363
  class CStmtReturn(CStmt):
1402
- def __init__(self, value_retval):
1403
- if value_retval != None:
1404
- assert(isinstance(value_retval, CValue))
1364
+ def __init__(self, return_value):
1365
+ if return_value != None:
1366
+ assert(isinstance(return_value, CValue))
1405
1367
  super().__init__()
1406
- self.value_retval = value_retval
1368
+ self.return_value = return_value
1407
1369
 
1408
1370
  def __str__(self):
1409
1371
  sstr = str_nl_indent(self.nl)
1410
1372
  sstr += 'return'
1411
- if self.value_retval != None:
1412
- sstr += ' ' + str_cvalue(self.value_retval)
1373
+ if self.return_value != None:
1374
+ sstr += ' ' + str_cvalue(self.return_value)
1413
1375
  return sstr + ";"
1414
1376
 
1415
1377
 
@@ -1442,7 +1404,7 @@ class CStmtContinue(CStmt):
1442
1404
  # : clobbered registers/memory /* optional */
1443
1405
  #);
1444
1406
 
1445
- class CStmtAsm(CStmt):
1407
+ class CStmtInlineAsm(CStmt):
1446
1408
  def __init__(self, text, outputs, inputs, clobbers):
1447
1409
  super().__init__()
1448
1410
  assert(isinstance(text, str))
@@ -1481,7 +1443,7 @@ class CStmtAsm(CStmt):
1481
1443
 
1482
1444
 
1483
1445
 
1484
- class CInsert(CStmt):
1446
+ class CRawText(CStmt):
1485
1447
  def __init__(self, text):
1486
1448
  super().__init__()
1487
1449
  self.text = text
@@ -1491,7 +1453,7 @@ class CInsert(CStmt):
1491
1453
  return self.text
1492
1454
 
1493
1455
 
1494
- class CMacrodefinition():
1456
+ class CMacroDef():
1495
1457
  def __init__(self, id, text=None):
1496
1458
  assert(isinstance(id, str))
1497
1459
  if text:
@@ -1510,7 +1472,7 @@ class CMacrodefinition():
1510
1472
  return sstr
1511
1473
 
1512
1474
 
1513
- class CMacrodefinitionValue():
1475
+ class CMacroDefValue():
1514
1476
  def __init__(self, id, value):
1515
1477
  assert(isinstance(id, str))
1516
1478
  assert(isinstance(value, CValue))
@@ -1543,18 +1505,18 @@ class CMacroUndef():
1543
1505
 
1544
1506
 
1545
1507
  class CInclude():
1546
- def __init__(self, text, isglobal):
1508
+ def __init__(self, text, is_system):
1547
1509
  assert(isinstance(text, str))
1548
- assert(isinstance(isglobal, bool))
1510
+ assert(isinstance(is_system, bool))
1549
1511
  self.nl = 1 #!!! (because it is not CStmt...)
1550
1512
  super().__init__()
1551
1513
  self.text = text
1552
- self.isglobal = isglobal
1514
+ self.is_system = is_system
1553
1515
  self.mark = None
1554
1516
 
1555
1517
  def __str__(self):
1556
1518
  #sstr = str_nl_indent(self.nl)
1557
- if self.isglobal:
1519
+ if self.is_system:
1558
1520
  return "\n#include <%s>" % self.text
1559
1521
  return "\n#include \"%s\"" % self.text
1560
1522
 
@@ -1565,7 +1527,7 @@ def str_cdef(x):
1565
1527
 
1566
1528
 
1567
1529
  # pairs = ("macro text", [<defs>])
1568
- class CIfdefRegion():
1530
+ class CConditionalRegion():
1569
1531
  def __init__(self, pairs, _else=None):
1570
1532
  self.pairs = pairs
1571
1533
  self._else = _else
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cshape"
7
- version = "0.1.0"
7
+ version = "0.2.2"
8
8
  description = "A dependency-free C AST + printer: build a tree in Python, get C11 source back"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -0,0 +1,57 @@
1
+ import unittest
2
+
3
+ from cshape import (
4
+ CField, CStmtBlock, CStmtDefFunc, CStmtDefVar, CStmtReturn, CTypeArray,
5
+ CTypeFunction, CTypeIdentifier, CValueAdd, CValueArray, CValueIdentifier,
6
+ CValueInteger, render,
7
+ )
8
+
9
+
10
+ class SmokeTest(unittest.TestCase):
11
+ def test_render_function(self):
12
+ func = CStmtDefFunc(
13
+ id='add',
14
+ type=CTypeFunction(
15
+ params=[CField(id='a', type=CTypeIdentifier('int')),
16
+ CField(id='b', type=CTypeIdentifier('int'))],
17
+ to=CTypeIdentifier('int'),
18
+ ),
19
+ block=CStmtBlock([
20
+ CStmtReturn(CValueAdd(CValueIdentifier('a'), CValueIdentifier('b'))),
21
+ ]),
22
+ )
23
+
24
+ self.assertEqual(
25
+ render(func).strip(),
26
+ 'int add(int a, int b) {\n\treturn a + b;\n}',
27
+ )
28
+
29
+ def test_render_is_reentrant(self):
30
+ # render() must not leak indent/style state between independent calls
31
+ named = CTypeIdentifier('int')
32
+ render(named, style='modern')
33
+ self.assertEqual(render(named, style='legacy'), 'int')
34
+
35
+ def test_mark_shows_up_as_comment(self):
36
+ v = CValueIdentifier('x')
37
+ v.mark = 'debug-note'
38
+ self.assertIn('/*debug-note*/', render(v))
39
+
40
+ def test_value_constructor_accepts_nl_for_array_layout(self):
41
+ array_def = CStmtDefVar(
42
+ id='numbers',
43
+ type=CTypeArray(CTypeIdentifier('int')),
44
+ initializer=CValueArray([
45
+ CValueInteger(1, nl=1),
46
+ CValueInteger(2),
47
+ ]),
48
+ )
49
+
50
+ self.assertEqual(
51
+ render(array_def).strip(),
52
+ 'int numbers[] = {\n\t1, 2\n};',
53
+ )
54
+
55
+
56
+ if __name__ == '__main__':
57
+ unittest.main()
@@ -1,41 +0,0 @@
1
- import unittest
2
-
3
- from cshape import (
4
- CField, CStmtBlock, CStmtDefFunc, CStmtReturn, CTypeFunc, CTypeNamed,
5
- CValueAdd, CValueNamed, render,
6
- )
7
-
8
-
9
- class SmokeTest(unittest.TestCase):
10
- def test_render_function(self):
11
- func = CStmtDefFunc(
12
- id_str='add',
13
- type=CTypeFunc(
14
- params=[CField(id_str='a', type=CTypeNamed('int')),
15
- CField(id_str='b', type=CTypeNamed('int'))],
16
- to=CTypeNamed('int'),
17
- ),
18
- block=CStmtBlock([
19
- CStmtReturn(CValueAdd(CValueNamed('a'), CValueNamed('b'))),
20
- ]),
21
- )
22
-
23
- self.assertEqual(
24
- render(func).strip(),
25
- 'int add(int a, int b) {\n\treturn a + b;\n}',
26
- )
27
-
28
- def test_render_is_reentrant(self):
29
- # render() must not leak indent/style state between independent calls
30
- named = CTypeNamed('int')
31
- render(named, style='modern')
32
- self.assertEqual(render(named, style='legacy'), 'int')
33
-
34
- def test_mark_shows_up_as_comment(self):
35
- v = CValueNamed('x')
36
- v.mark = 'debug-note'
37
- self.assertIn('/*debug-note*/', render(v))
38
-
39
-
40
- if __name__ == '__main__':
41
- unittest.main()
File without changes
File without changes