-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ast.hs
164 lines (164 loc) · 4.59 KB
/
Ast.hs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
data CTranslUnit = CTranslUnit [CExtDecl] NodeInfo
data CExtDecl
= CDeclExt CDecl
| CFDefExt CFunDef
| CAsmExt CStrLit
data CFunDef = CFunDef [CDeclSpec] CDeclr [CDecl] CStat NodeInfo
data CDecl = CDecl [CDeclSpec] [(Maybe CDeclr, Maybe CInit, Maybe CExpr)] NodeInfo
data CStructUnion = CStruct CStructTag (Maybe Ident) (Maybe [CDecl]) [CAttr] NodeInfo
data CStructTag
= CStructTag
| CUnionTag
data CEnum = CEnum (Maybe Ident) (Maybe [(Ident, Maybe CExpr)]) [CAttr] NodeInfo
data CDeclSpec
= CStorageSpec CStorageSpec
| CTypeSpec CTypeSpec
| CTypeQual CTypeQual
partitionDeclSpecs :: [CDeclSpec] -> ([CStorageSpec], [CAttr], [CTypeQual], [CTypeSpec], Bool)
data CStorageSpec
= CAuto NodeInfo
| CRegister NodeInfo
| CStatic NodeInfo
| CExtern NodeInfo
| CTypedef NodeInfo
| CThread NodeInfo
data CTypeSpec
= CVoidType NodeInfo
| CCharType NodeInfo
| CShortType NodeInfo
| CIntType NodeInfo
| CLongType NodeInfo
| CFloatType NodeInfo
| CDoubleType NodeInfo
| CSignedType NodeInfo
| CUnsigType NodeInfo
| CBoolType NodeInfo
| CComplexType NodeInfo
| CSUType CStructUnion NodeInfo
| CEnumType CEnum NodeInfo
| CTypeDef Ident NodeInfo
| CTypeOfExpr CExpr NodeInfo
| CTypeOfType CDecl NodeInfo
isSUEDef :: CTypeSpec -> Bool
data CTypeQual
= CConstQual NodeInfo
| CVolatQual NodeInfo
| CRestrQual NodeInfo
| CInlineQual NodeInfo
| CAttrQual CAttr
data CAttr = CAttr Ident [CExpr] NodeInfo
data CDeclr = CDeclr (Maybe Ident) [CDerivedDeclr] (Maybe CStrLit) [CAttr] NodeInfo
data CDerivedDeclr
= CPtrDeclr [CTypeQual] NodeInfo
| CArrDeclr [CTypeQual] CArrSize NodeInfo
| CFunDeclr (Either [Ident] ([CDecl], Bool)) [CAttr] NodeInfo
data CArrSize
= CNoArrSize Bool
| CArrSize Bool CExpr
data CInit
= CInitExpr CExpr NodeInfo
| CInitList CInitList NodeInfo
type CInitList = [([CDesignator], CInit)]
data CDesignator
= CArrDesig CExpr NodeInfo
| CMemberDesig Ident NodeInfo
| CRangeDesig CExpr CExpr NodeInfo
data CStat
= CLabel Ident CStat [CAttr] NodeInfo
| CCase CExpr CStat NodeInfo
| CCases CExpr CExpr CStat NodeInfo
| CDefault CStat NodeInfo
| CExpr (Maybe CExpr) NodeInfo
| CCompound [Ident] [CBlockItem] NodeInfo
| CIf CExpr CStat (Maybe CStat) NodeInfo
| CSwitch CExpr CStat NodeInfo
| CWhile CExpr CStat Bool NodeInfo
| CFor (Either (Maybe CExpr) CDecl) (Maybe CExpr) (Maybe CExpr) CStat NodeInfo
| CGoto Ident NodeInfo
| CGotoPtr CExpr NodeInfo
| CCont NodeInfo
| CBreak NodeInfo
| CReturn (Maybe CExpr) NodeInfo
| CAsm CAsmStmt NodeInfo
data CBlockItem
= CBlockStmt CStat
| CBlockDecl CDecl
| CNestedFunDef CFunDef
data CAsmStmt = CAsmStmt (Maybe CTypeQual) CStrLit [CAsmOperand] [CAsmOperand] [CStrLit] NodeInfo
data CAsmOperand = CAsmOperand (Maybe Ident) CStrLit CExpr NodeInfo
data CExpr
= CComma [CExpr] NodeInfo
| CAssign CAssignOp CExpr CExpr NodeInfo
| CCond CExpr (Maybe CExpr) CExpr NodeInfo
| CBinary CBinaryOp CExpr CExpr NodeInfo
| CCast CDecl CExpr NodeInfo
| CUnary CUnaryOp CExpr NodeInfo
| CSizeofExpr CExpr NodeInfo
| CSizeofType CDecl NodeInfo
| CAlignofExpr CExpr NodeInfo
| CAlignofType CDecl NodeInfo
| CComplexReal CExpr NodeInfo
| CComplexImag CExpr NodeInfo
| CIndex CExpr CExpr NodeInfo
| CCall CExpr [CExpr] NodeInfo
| CMember CExpr Ident Bool NodeInfo
| CVar Ident NodeInfo
| CConst CConst
| CCompoundLit CDecl CInitList NodeInfo
| CStatExpr CStat NodeInfo
| CLabAddrExpr Ident NodeInfo
| CBuiltinExpr CBuiltin
data CAssignOp
= CAssignOp
| CMulAssOp
| CDivAssOp
| CRmdAssOp
| CAddAssOp
| CSubAssOp
| CShlAssOp
| CShrAssOp
| CAndAssOp
| CXorAssOp
| COrAssOp
data CBinaryOp
= CMulOp
| CDivOp
| CRmdOp
| CAddOp
| CSubOp
| CShlOp
| CShrOp
| CLeOp
| CGrOp
| CLeqOp
| CGeqOp
| CEqOp
| CNeqOp
| CAndOp
| CXorOp
| COrOp
| CLndOp
| CLorOp
data CUnaryOp
= CPreIncOp
| CPreDecOp
| CPostIncOp
| CPostDecOp
| CAdrOp
| CIndOp
| CPlusOp
| CMinOp
| CCompOp
| CNegOp
data CBuiltin
= CBuiltinVaArg CExpr CDecl NodeInfo
| CBuiltinOffsetOf CDecl [CDesignator] NodeInfo
| CBuiltinTypesCompatible CDecl CDecl NodeInfo
data CConst
= CIntConst CInteger NodeInfo
| CCharConst CChar NodeInfo
| CFloatConst CFloat NodeInfo
| CStrConst CString NodeInfo
data CStrLit = CStrLit CString NodeInfo
cstringOfLit :: CStrLit -> CString
liftStrLit :: CStrLit -> CConst