author | Xeli |
Tue, 07 Feb 2012 18:56:49 +0100 | |
changeset 6648 | 025473a2c420 |
parent 6635 | c2fa29fe2a58 |
child 6649 | 7f78e8a6db69 |
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 |
|
20 |
| VarDeclaration Bool ([Identifier], TypeDecl) (Maybe InitExpression) |
|
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] |
|
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
|
33 |
| DeriveType InitExpression |
6467 | 34 |
| UnknownType |
35 |
deriving Show |
|
36 |
data Range = Range Identifier |
|
37 |
| RangeFromTo InitExpression InitExpression |
|
38 |
deriving Show |
|
39 |
data Initialize = Initialize String |
|
40 |
deriving Show |
|
41 |
data Finalize = Finalize String |
|
42 |
deriving Show |
|
43 |
data Uses = Uses [Identifier] |
|
44 |
deriving Show |
|
45 |
data Phrase = ProcCall Reference [Expression] |
|
46 |
| IfThenElse Expression Phrase (Maybe Phrase) |
|
47 |
| WhileCycle Expression Phrase |
|
48 |
| RepeatCycle Expression [Phrase] |
|
49 |
| ForCycle Identifier Expression Expression Phrase |
|
50 |
| WithBlock Reference Phrase |
|
51 |
| Phrases [Phrase] |
|
52 |
| SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase]) |
|
53 |
| Assignment Reference Expression |
|
54 |
| NOP |
|
55 |
deriving Show |
|
56 |
data Expression = Expression String |
|
57 |
| BuiltInFunCall [Expression] Reference |
|
58 |
| PrefixOp String Expression |
|
59 |
| PostfixOp String Expression |
|
60 |
| BinOp String Expression Expression |
|
61 |
| StringLiteral String |
|
62 |
| CharCode String |
|
63 |
| HexCharCode String |
|
64 |
| NumberLiteral String |
|
65 |
| FloatLiteral String |
|
66 |
| HexNumber String |
|
67 |
| Reference Reference |
|
68 |
| SetExpression [Identifier] |
|
69 |
| Null |
|
70 |
deriving Show |
|
71 |
data Reference = ArrayElement [Expression] Reference |
|
72 |
| FunCall [Expression] Reference |
|
73 |
| TypeCast Identifier Expression |
|
74 |
| SimpleReference Identifier |
|
75 |
| Dereference Reference |
|
76 |
| RecordField Reference Reference |
|
77 |
| Address Reference |
|
78 |
| RefExpression Expression |
|
79 |
deriving Show |
|
80 |
data InitExpression = InitBinOp String InitExpression InitExpression |
|
81 |
| InitPrefixOp String InitExpression |
|
82 |
| InitReference Identifier |
|
83 |
| InitArray [InitExpression] |
|
84 |
| InitRecord [(Identifier, InitExpression)] |
|
85 |
| InitFloat String |
|
86 |
| InitNumber String |
|
87 |
| InitHexNumber String |
|
88 |
| InitString String |
|
89 |
| InitChar String |
|
90 |
| BuiltInFunction String [InitExpression] |
|
91 |
| InitSet [InitExpression] |
|
92 |
| InitAddress InitExpression |
|
93 |
| InitNull |
|
94 |
| InitRange Range |
|
95 |
| InitTypeCast Identifier InitExpression |
|
96 |
deriving Show |
|
6489 | 97 |
|
6618 | 98 |
data BaseType = BTUnknown |
6489 | 99 |
| BTChar |
100 |
| BTString |
|
101 |
| BTInt |
|
6635
c2fa29fe2a58
Some progress, still can't find the source of bad behavior
unc0rr
parents:
6626
diff
changeset
|
102 |
| BTBool |
6618 | 103 |
| BTRecord [(String, BaseType)] |
104 |
| BTArray BaseType BaseType |
|
6489 | 105 |
| BTFunction |
106 |
| BTPointerTo BaseType |
|
107 |
| BTSet |
|
108 |
| BTEnum [String] |
|
6618 | 109 |
| BTVoid |
6489 | 110 |
deriving Show |
6618 | 111 |
|
112 |
||
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
|
113 |
{-- |
6618 | 114 |
type2BaseType :: TypeDecl -> BaseType |
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
|
115 |
type2BaseType st@(SimpleType (Identifier s _)) = f (map toLower s) |
6618 | 116 |
where |
117 |
f "longint" = BTInt |
|
118 |
f "integer" = BTInt |
|
119 |
f "word" = BTInt |
|
120 |
f "pointer" = BTPointerTo BTVoid |
|
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
|
121 |
f _ = error $ show st |
6618 | 122 |
type2BaseType (Sequence ids) = BTEnum $ map (\(Identifier i _) -> i) ids |
123 |
type2BaseType (RecordType tv mtvs) = BTRecord $ concatMap f (concat $ tv : fromMaybe [] mtvs) |
|
124 |
where |
|
125 |
f (VarDeclaration _ (ids, td) _) = map (\(Identifier i _) -> (i, type2BaseType td)) ids |
|
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
|
126 |
type2BaseType (PointerTo t) = BTPointerTo $ type2BaseType t |
a447993f2ad7
Further work on propagating types. Now it hopefully works fully, just need to annotate namespace with types first.
unc0rr
parents:
6618
diff
changeset
|
127 |
type2BaseType a = error $ show a |
a447993f2ad7
Further work on propagating types. Now it hopefully works fully, just need to annotate namespace with types first.
unc0rr
parents:
6618
diff
changeset
|
128 |
--} |