tools/pas2c/PascalUnitSyntaxTree.hs
author koda
Tue, 21 Jan 2014 22:38:13 +0100
changeset 10015 4feced261c68
parent 8020 00b1facf2805
child 10111 459bc720cea1
permissions -rw-r--r--
partial merge of the webgl branch This commit contains the new pas2c conversion tool, the pascal to c build structure and the opengl2 rendering backend. Patch reviewed by unC0Rr.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     1
module PascalUnitSyntaxTree where
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     2
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     3
import Data.Maybe
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     4
import Data.Char
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     5
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     6
data PascalUnit =
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     7
    Program Identifier Implementation Phrase
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     8
    | Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize)
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     9
    | System [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    10
    | Redo [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    11
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    12
data Interface = Interface Uses TypesAndVars
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    13
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    14
data Implementation = Implementation Uses TypesAndVars
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    15
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    16
data Identifier = Identifier String BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    17
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    18
data TypesAndVars = TypesAndVars [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    19
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    20
data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    21
    | VarDeclaration Bool Bool ([Identifier], TypeDecl) (Maybe InitExpression)
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    22
    | FunctionDeclaration Identifier Bool Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    23
    | OperatorDeclaration String Identifier Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    24
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    25
data TypeDecl = SimpleType Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    26
    | RangeType Range
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    27
    | Sequence [Identifier]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    28
    | ArrayDecl (Maybe Range) TypeDecl
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    29
    | RecordType [TypeVarDeclaration] (Maybe [[TypeVarDeclaration]])
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    30
    | PointerTo TypeDecl
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    31
    | String Integer
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    32
    | Set TypeDecl
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    33
    | FunctionType TypeDecl [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    34
    | DeriveType InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    35
    | VoidType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    36
    | VarParamType TypeDecl -- this is a hack
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    37
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    38
data Range = Range Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    39
           | RangeFromTo InitExpression InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    40
           | RangeInfinite
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    41
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    42
data Initialize = Initialize String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    43
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    44
data Finalize = Finalize String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    45
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    46
data Uses = Uses [Identifier]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    47
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    48
data Phrase = ProcCall Reference [Expression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    49
        | IfThenElse Expression Phrase (Maybe Phrase)
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    50
        | WhileCycle Expression Phrase
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    51
        | RepeatCycle Expression [Phrase]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    52
        | ForCycle Identifier Expression Expression Phrase Bool -- The last Boolean indicates wether it's up or down counting
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    53
        | WithBlock Reference Phrase
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    54
        | Phrases [Phrase]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    55
        | SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase])
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    56
        | Assignment Reference Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    57
        | BuiltInFunctionCall [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    58
        | NOP
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    59
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    60
data Expression = Expression String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    61
    | BuiltInFunCall [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    62
    | PrefixOp String Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    63
    | PostfixOp String Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    64
    | BinOp String Expression Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    65
    | StringLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    66
    | PCharLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    67
    | CharCode String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    68
    | HexCharCode String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    69
    | NumberLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    70
    | FloatLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    71
    | HexNumber String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    72
    | Reference Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    73
    | SetExpression [Identifier]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    74
    | Null
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    75
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    76
data Reference = ArrayElement [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    77
    | FunCall [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    78
    | TypeCast Identifier Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    79
    | SimpleReference Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    80
    | Dereference Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    81
    | RecordField Reference Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    82
    | Address Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    83
    | RefExpression Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    84
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    85
data InitExpression = InitBinOp String InitExpression InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    86
    | InitPrefixOp String InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    87
    | InitReference Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    88
    | InitArray [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    89
    | InitRecord [(Identifier, InitExpression)]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    90
    | InitFloat String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    91
    | InitNumber String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    92
    | InitHexNumber String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    93
    | InitString String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    94
    | InitChar String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    95
    | BuiltInFunction String [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    96
    | InitSet [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    97
    | InitAddress InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    98
    | InitNull
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    99
    | InitRange Range
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   100
    | InitTypeCast Identifier InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   101
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   102
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   103
data BaseType = BTUnknown
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   104
    | BTChar
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   105
    | BTString
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   106
    | BTInt Bool -- second param indicates whether signed or not
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   107
    | BTBool
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   108
    | BTFloat
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   109
    | BTRecord String [(String, BaseType)]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   110
    | BTArray Range BaseType BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   111
    | BTFunction Bool [(Bool, BaseType)] BaseType -- (Bool, BaseType), Bool indiciates whether var or not
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   112
    | BTPointerTo BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   113
    | BTUnresolved String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   114
    | BTSet BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   115
    | BTEnum [String]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   116
    | BTVoid
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   117
    | BTUnit
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   118
    | BTVarParam BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   119
    deriving Show