tools/pas2c/PascalUnitSyntaxTree.hs
author Wuzzy <almikes@aol.com>
Fri, 06 May 2016 17:26:06 +0200
changeset 11814 8eccc307ca1e
parent 10747 07ade56c3b4a
child 13887 5988e73080a3
permissions -rw-r--r--
Frontend: Increase space for help text in the footer
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]
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
     8
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
     9
data Interface = Interface Uses TypesAndVars
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    10
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    11
data Implementation = Implementation Uses TypesAndVars
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    12
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    13
data Identifier = Identifier String BaseType
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    14
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    15
data TypesAndVars = TypesAndVars [TypeVarDeclaration]
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    16
    deriving (Show, Eq)
10015
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)
10129
cd2a64a1f4aa - Pas2C: make use of 'external' function decorator
unc0rr
parents: 10120
diff changeset
    19
    | FunctionDeclaration Identifier Bool Bool Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    20
    | OperatorDeclaration String Identifier Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    21
    deriving (Show, Eq)
10015
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
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    35
    deriving (Show, Eq)
10015
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
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    39
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    40
data Initialize = Initialize String
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    41
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    42
data Finalize = Finalize String
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    43
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    44
data Uses = Uses [Identifier]
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    45
    deriving (Show, Eq)
10015
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
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    57
    deriving (Show, Eq)
10015
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
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    73
    deriving (Show, Eq)
10015
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
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
    82
    deriving (Show, Eq)
10015
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
10747
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10142
diff changeset
    92
    | InitPChar String
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    93
    | InitChar String
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    94
    | BuiltInFunction String [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    95
    | InitSet [InitExpression]
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    96
    | InitAddress InitExpression
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    97
    | InitNull
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    98
    | InitRange Range
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
    99
    | InitTypeCast Identifier InitExpression
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
   100
    deriving (Show, Eq)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   101
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   102
data BaseType = BTUnknown
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   103
    | BTChar
4feced261c68 partial merge of the webgl branch
koda
parents: 8020
diff changeset
   104
    | BTString
10120
b7f632c12784 Pas2C recognizes ansistrings
unc0rr
parents: 10113
diff changeset
   105
    | BTAString
10015
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
10129
cd2a64a1f4aa - Pas2C: make use of 'external' function decorator
unc0rr
parents: 10120
diff changeset
   111
    | BTFunction Bool Bool [(Bool, BaseType)] BaseType -- in (Bool, BaseType), Bool indiciates whether var or not
10015
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
10142
adb804cb2638 Reduce number of warnings in pas2c-generated code
unc0rr
parents: 10129
diff changeset
   119
    deriving (Show, Eq)