-
Notifications
You must be signed in to change notification settings - Fork 1
/
usage.py
executable file
·57 lines (55 loc) · 1.77 KB
/
usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from codegen import *
if __name__ == "__main__":
func = Function('int', 'main')
func.addComment()
func.add(Line('char', 'hello', '=', '\'H\''))
struct = Struct('PPDLState')
struct.add(Line('int', 'i'))
struct.add(Line('char', 'c'))
struct.add(Line('unsigned long', 'ui'))
struct.add(Line('char', 'a2'))
struct.addPrefix('typedef')
func.add(struct)
union = Union(Line('g++'))
_union = Union(Line('k++'))
union.add(_union)
cond = If('1', '>' , '0')
cond.add(Line('int' , 'i'))
cond.add(union)
cond.addVar('int', 'k')
cond.addVar('int', 'g')
cond.addVar('int', 'l')
cond.add(Line('' , 'hello', '=', '\'Y\''))
cond.add(For('i = 0', 'i < 10', 'i++'))
_for = For('i = 0', 'i < 10', 'i++')
_for.addComment()
_for.add(Line('char', 'ItIsFor'))
cond.addElse(Line('int' , 'i'))
cond.addElse(_for)
func.add(cond)
doWhile = DoWhile('1 > 2')
_while = While('0 < 1')
_while.add(Line('char', 'HelloWorld'))
switch = Switch('HelloWorld')
switch.add('\'f\'', Line('', 'HelloWorld', '=', '\'g\''))
switch.add('\'d\'', Line('', 'HelloWorld', '=', '\'\\0\''))
switch.addDefault(Line('', 'HelloWorld', '=', '\'\\0\''))
_while.add(switch)
doWhile.add(_while)
doWhile.add(Line(Call("pow", ['2', Call("pow", ['2', '2'])])))
func.add(doWhile)
source = Source()
source.add(Pragma("warning(disable:4047)"))
ifdef = Ifdef("unix")
ifdef.add(Define("DEBUG_NIX", "1"))
ifdef.add(Include("math.h"))
ifdef.addElse(Include("stdio.h"))
source.add(ifdef)
ifndef = Ifdef("unix", negative = True)
ifndef.add(Define("DEBUG_WIN", "1"))
source.add(ifndef)
source.add(struct)
source.add(func)
print(source)