author | nemo |
Sat, 07 Jul 2012 14:29:35 -0400 | |
changeset 7345 | f253e225da15 |
parent 7333 | 520a16a14747 |
child 7429 | fcf13e40d6b6 |
permissions | -rw-r--r-- |
6467 | 1 |
module PascalUnitSyntaxTree where |
2 |
||
6618 | 3 |
import Data.Maybe |
6626
a447993f2ad7
Further work on propagating types. Now it hopefully works fully, just need to annotate namespace with types first.
unc0rr
parents:
6618
diff
changeset
|
4 |
import Data.Char |
6467 | 5 |
|
6 |
data PascalUnit = |
|
7 |
Program Identifier Implementation Phrase |
|
8 |
| Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize) |
|
6512 | 9 |
| System [TypeVarDeclaration] |
6467 | 10 |
deriving Show |
11 |
data Interface = Interface Uses TypesAndVars |
|
12 |
deriving Show |
|
13 |
data Implementation = Implementation Uses TypesAndVars |
|
14 |
deriving Show |
|
6489 | 15 |
data Identifier = Identifier String BaseType |
6467 | 16 |
deriving Show |
17 |
data TypesAndVars = TypesAndVars [TypeVarDeclaration] |
|
18 |
deriving Show |
|
19 |
data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl |
|
7317 | 20 |
| VarDeclaration Bool Bool ([Identifier], TypeDecl) (Maybe InitExpression) |
6467 | 21 |
| FunctionDeclaration Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase)) |
22 |
| OperatorDeclaration String Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase)) |
|
23 |
deriving Show |
|
24 |
data TypeDecl = SimpleType Identifier |
|
25 |
| RangeType Range |
|
26 |
| Sequence [Identifier] |
|
27 |
| ArrayDecl (Maybe Range) TypeDecl |
|
28 |
| RecordType [TypeVarDeclaration] (Maybe [[TypeVarDeclaration]]) |
|
29 |
| PointerTo TypeDecl |
|
30 |
| String Integer |
|
31 |
| Set TypeDecl |
|
32 |
| FunctionType TypeDecl [TypeVarDeclaration] |
|
7323
8490a4f439a5
Convert function with var parameters declarations into #define + function which accepts pointers
unc0rr
parents:
7317
diff
changeset
|
33 |
| DeriveType InitExpression |
6826 | 34 |
| VoidType |
7323
8490a4f439a5
Convert function with var parameters declarations into #define + function which accepts pointers
unc0rr
parents:
7317
diff
changeset
|
35 |
| VarParamType TypeDecl -- this is a hack |
6467 | 36 |
deriving Show |
37 |
data Range = Range Identifier |
|
38 |
| RangeFromTo InitExpression InitExpression |
|
6893 | 39 |
| RangeInfinite |
6467 | 40 |
deriving Show |
41 |
data Initialize = Initialize String |
|
42 |
deriving Show |
|
43 |
data Finalize = Finalize String |
|
44 |
deriving Show |
|
45 |
data Uses = Uses [Identifier] |
|
46 |
deriving Show |
|
47 |
data Phrase = ProcCall Reference [Expression] |
|
48 |
| IfThenElse Expression Phrase (Maybe Phrase) |
|
49 |
| WhileCycle Expression Phrase |
|
50 |
| RepeatCycle Expression [Phrase] |
|
51 |
| ForCycle Identifier Expression Expression Phrase |
|
52 |
| WithBlock Reference Phrase |
|
53 |
| Phrases [Phrase] |
|
54 |
| SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase]) |
|
55 |
| Assignment Reference Expression |
|
6895 | 56 |
| BuiltInFunctionCall [Expression] Reference |
6467 | 57 |
| NOP |
58 |
deriving Show |
|
59 |
data Expression = Expression String |
|
60 |
| BuiltInFunCall [Expression] Reference |
|
61 |
| PrefixOp String Expression |
|
62 |
| PostfixOp String Expression |
|
63 |
| BinOp String Expression Expression |
|
64 |
| StringLiteral String |
|
7070 | 65 |
| PCharLiteral String |
6467 | 66 |
| CharCode String |
67 |
| HexCharCode String |
|
68 |
| NumberLiteral String |
|
69 |
| FloatLiteral String |
|
70 |
| HexNumber String |
|
71 |
| Reference Reference |
|
72 |
| SetExpression [Identifier] |
|
73 |
| Null |
|
74 |
deriving Show |
|
75 |
data Reference = ArrayElement [Expression] Reference |
|
76 |
| FunCall [Expression] Reference |
|
77 |
| TypeCast Identifier Expression |
|
78 |
| SimpleReference Identifier |
|
79 |
| Dereference Reference |
|
80 |
| RecordField Reference Reference |
|
81 |
| Address Reference |
|
82 |
| RefExpression Expression |
|
83 |
deriving Show |
|
84 |
data InitExpression = InitBinOp String InitExpression InitExpression |
|
85 |
| InitPrefixOp String InitExpression |
|
86 |
| InitReference Identifier |
|
87 |
| InitArray [InitExpression] |
|
88 |
| InitRecord [(Identifier, InitExpression)] |
|
89 |
| InitFloat String |
|
90 |
| InitNumber String |
|
91 |
| InitHexNumber String |
|
92 |
| InitString String |
|
93 |
| InitChar String |
|
94 |
| BuiltInFunction String [InitExpression] |
|
95 |
| InitSet [InitExpression] |
|
96 |
| InitAddress InitExpression |
|
97 |
| InitNull |
|
98 |
| InitRange Range |
|
99 |
| InitTypeCast Identifier InitExpression |
|
100 |
deriving Show |
|
6489 | 101 |
|
6618 | 102 |
data BaseType = BTUnknown |
6489 | 103 |
| BTChar |
104 |
| BTString |
|
105 |
| BTInt |
|
6635
c2fa29fe2a58
Some progress, still can't find the source of bad behavior
unc0rr
parents:
6626
diff
changeset
|
106 |
| BTBool |
6649
7f78e8a6db69
Fix a bug with type declaration trying to resolve type being declared
unc0rr
parents:
6635
diff
changeset
|
107 |
| BTFloat |
7042
de20086a6bcc
Support overloaded operators on (hwFloat op hwFloat) calls
unc0rr
parents:
7032
diff
changeset
|
108 |
| BTRecord String [(String, BaseType)] |
6893 | 109 |
| BTArray Range BaseType BaseType |
7333
520a16a14747
Properly convert taking address of function with var parameters
unc0rr
parents:
7323
diff
changeset
|
110 |
| BTFunction Bool Int BaseType |
6489 | 111 |
| BTPointerTo BaseType |
6827 | 112 |
| BTUnresolved String |
6653 | 113 |
| BTSet BaseType |
6489 | 114 |
| BTEnum [String] |
6618 | 115 |
| BTVoid |
6816 | 116 |
| BTUnit |
7323
8490a4f439a5
Convert function with var parameters declarations into #define + function which accepts pointers
unc0rr
parents:
7317
diff
changeset
|
117 |
| BTVarParam BaseType |
6489 | 118 |
deriving Show |