tools/pas2c/PascalUnitSyntaxTree.hs
author unc0rr
Fri, 07 Feb 2014 15:44:27 +0400
changeset 10120 b7f632c12784
parent 10113 b26c2772e754
child 10129 cd2a64a1f4aa
permissions -rw-r--r--
Pas2C recognizes ansistrings
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
data PascalUnit =
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     4
    Program Identifier Implementation Phrase
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     5
    | Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize)
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     6
    | System [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     7
    | Redo [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     8
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     9
data Interface = Interface Uses TypesAndVars
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    10
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    11
data Implementation = Implementation Uses TypesAndVars
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    12
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    13
data Identifier = Identifier String BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    14
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    15
data TypesAndVars = TypesAndVars [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    16
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    17
data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    18
    | VarDeclaration Bool Bool ([Identifier], TypeDecl) (Maybe InitExpression)
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    19
    | FunctionDeclaration Identifier Bool Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    20
    | OperatorDeclaration String Identifier Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    21
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    22
data TypeDecl = SimpleType Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    23
    | RangeType Range
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    24
    | Sequence [Identifier]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    25
    | ArrayDecl (Maybe Range) TypeDecl
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    26
    | RecordType [TypeVarDeclaration] (Maybe [[TypeVarDeclaration]])
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    27
    | PointerTo TypeDecl
10111
459bc720cea1 Drop support for other string types than string255
unc0rr
parents: 10015
diff changeset
    28
    | String
10120
b7f632c12784 Pas2C recognizes ansistrings
unc0rr
parents: 10113
diff changeset
    29
    | AString
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    30
    | Set TypeDecl
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    31
    | FunctionType TypeDecl [TypeVarDeclaration]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    32
    | DeriveType InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    33
    | VoidType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    34
    | VarParamType TypeDecl -- this is a hack
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    35
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    36
data Range = Range Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    37
           | RangeFromTo InitExpression InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    38
           | RangeInfinite
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    39
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    40
data Initialize = Initialize String
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 Finalize = Finalize 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 Uses = Uses [Identifier]
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 Phrase = ProcCall Reference [Expression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    47
        | IfThenElse Expression Phrase (Maybe Phrase)
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    48
        | WhileCycle Expression Phrase
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    49
        | RepeatCycle Expression [Phrase]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    50
        | 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
    51
        | WithBlock Reference Phrase
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    52
        | Phrases [Phrase]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    53
        | SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase])
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    54
        | Assignment Reference Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    55
        | BuiltInFunctionCall [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    56
        | NOP
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    57
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    58
data Expression = Expression String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    59
    | BuiltInFunCall [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    60
    | PrefixOp String Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    61
    | PostfixOp String Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    62
    | BinOp String Expression Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    63
    | StringLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    64
    | PCharLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    65
    | CharCode String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    66
    | HexCharCode String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    67
    | NumberLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    68
    | FloatLiteral String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    69
    | HexNumber String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    70
    | Reference Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    71
    | SetExpression [Identifier]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    72
    | Null
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    73
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    74
data Reference = ArrayElement [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    75
    | FunCall [Expression] Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    76
    | TypeCast Identifier Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    77
    | SimpleReference Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    78
    | Dereference Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    79
    | RecordField Reference Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    80
    | Address Reference
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    81
    | RefExpression Expression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    82
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    83
data InitExpression = InitBinOp String InitExpression InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    84
    | InitPrefixOp String InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    85
    | InitReference Identifier
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    86
    | InitArray [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    87
    | InitRecord [(Identifier, InitExpression)]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    88
    | InitFloat String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    89
    | InitNumber String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    90
    | InitHexNumber String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    91
    | InitString String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    92
    | InitChar String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    93
    | BuiltInFunction String [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    94
    | InitSet [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    95
    | InitAddress InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    96
    | InitNull
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    97
    | InitRange Range
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    98
    | InitTypeCast Identifier InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    99
    deriving Show
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   100
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   101
data BaseType = BTUnknown
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   102
    | BTChar
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   103
    | BTString
10120
b7f632c12784 Pas2C recognizes ansistrings
unc0rr
parents: 10113
diff changeset
   104
    | BTAString
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   105
    | BTInt Bool -- second param indicates whether signed or not
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   106
    | BTBool
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   107
    | BTFloat
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   108
    | BTRecord String [(String, BaseType)]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   109
    | BTArray Range BaseType BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   110
    | 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
   111
    | BTPointerTo BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   112
    | BTUnresolved String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   113
    | BTSet BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   114
    | BTEnum [String]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   115
    | BTVoid
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   116
    | BTUnit
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   117
    | BTVarParam BaseType
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   118
    deriving Show