-- AST (Abstract Syntax Tree) for C module AST where import Text.ParserCombinators.Parsec(SourcePos) data File = File [Global] deriving Show data Global = GlobalDecl Declaration | FunctionDecl (Maybe Type) String [(Type,Int,String,SourcePos)] SourcePos | FunctionDef (Maybe Type) String [(Type,Int,String,SourcePos)] CodeBlock SourcePos | Typedef Type Int String [ExprAt] SourcePos | Preprocessor String SourcePos deriving Show data Type = Type [TypeQualifier] Type' deriving Show data Type' = CharType | ShortType | LongType | IntType | FloatType | DoubleType | CustomType String deriving Show data Declaration = Declaration [DeclModifier] Type [DeclarationTerm] deriving Show -- The elements of this struct are: Pointer Level, Name, Array Sizes, Initialiser, Pos data DeclarationTerm = DeclTerm Int String [ExprAt] (Maybe ExprAt) SourcePos deriving Show data Statement = DeclStatement Declaration | ExpStatement ExprAt | IfStatement ExprAt CodeBlock (Maybe CodeBlock) | While ExprAt CodeBlock | DoWhile CodeBlock ExprAt | For ExprAt ExprAt ExprAt CodeBlock | Break | Continue | Return (Maybe ExprAt) | EmptyStatement | Block CodeBlock deriving Show data DeclModifier = Static | Extern deriving Show data ExprAt = ExprAt SourcePos Expression deriving Show data Expression = Identifier String | ConstExpr Constant | ArrayInit [ExprAt] | FunctionCall ExprAt [ExprAt] | ArraySubscript ExprAt ExprAt | SelectByReference ExprAt String | SelectThroughPointer ExprAt String | PostIncrement ExprAt | PostDecrement ExprAt | Unary UnaryOp ExprAt | Binary BinaryOp ExprAt ExprAt | Assignment AssignmentOp ExprAt ExprAt | Conditional ExprAt ExprAt ExprAt | Comma ExprAt ExprAt deriving Show data TypeQualifier = Const | Volatile | Unsigned | Signed deriving Show data Constant = CharConst Char | ShortConst Int | LongConst Int | FloatConst Float | DoubleConst Double | StringConst String deriving Show data UnaryOp = Dereference | AddressOf | UnaryPlus | UnaryMinus | LogicalNot | BitwiseComplement | PreIncrement | PreDecrement | Cast Type Int | Sizeof deriving Show data BinaryOp = Times | Divide | Mod | Plus | Minus | ShiftRight | ShiftLeft | LessThan | GreaterThan | LessThanOrEq | GreaterThanOrEq | EqualTo | NotEqualTo | BitwiseAnd | BitwiseXOr | BitwiseOr | LogicalAnd | LogicalOr deriving Show data AssignmentOp = Assign | IncreaseBy | DecreaseBy | MultiplyBy | DivideBy | ModBy | ShiftRightBy | ShiftLeftBy | BitwiseAndBy | BitwiseXOrBy | BitwiseOrBy deriving Show type CodeBlock = [Statement]