14 afterAccept: node retval: retval |
14 afterAccept: node retval: retval |
15 | return | |
15 | return | |
16 return := super afterAccept: node retval: retval. |
16 return := super afterAccept: node retval: retval. |
17 return category: 'generated - tokens'. |
17 return category: 'generated - tokens'. |
18 ^ return |
18 ^ return |
|
19 ! |
|
20 |
|
21 fromTokenMode |
|
22 compiler rememberStrategy: (PPCCompilerTokenizingRememberStrategy on: compiler). |
|
23 compiler errorStrategy: (PPCCompilerTokenizingErrorStrategy on: compiler). |
|
24 ! |
|
25 |
|
26 toTokenMode |
|
27 compiler rememberStrategy: (PPCCompilerTokenRememberStrategy on: compiler). |
|
28 compiler errorStrategy: (PPCCompilerTokenErrorStrategy on: compiler). |
19 ! ! |
29 ! ! |
20 |
30 |
21 !PPCTokenCodeGenerator methodsFor:'visiting'! |
31 !PPCTokenCodeGenerator methodsFor:'visiting'! |
22 |
32 |
|
33 visitOptionalNode: node |
|
34 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: self retvalVar. |
|
35 compiler codeAssign: 'false.' to: 'error'. |
|
36 compiler codeReturn. |
|
37 ! |
|
38 |
23 visitTokenNode: node |
39 visitTokenNode: node |
24 | id startVar endVar | |
40 | id startVar endVar | |
|
41 "Tokens cannot be inlined, |
|
42 - their result is true/false |
|
43 - the return value is always stored in currentTokenValue |
|
44 - the current token type is always stored in currentTokenType |
|
45 " |
|
46 self assert: node isMarkedForInline not. |
|
47 |
25 startVar := compiler allocateTemporaryVariableNamed: 'start'. |
48 startVar := compiler allocateTemporaryVariableNamed: 'start'. |
26 endVar := compiler allocateTemporaryVariableNamed: 'end'. |
49 endVar := compiler allocateTemporaryVariableNamed: 'end'. |
27 |
50 |
28 id := compiler idFor: node. |
51 id := compiler idFor: node. |
29 compiler rememberStrategy: (PPCCompilerTokenRememberStrategy on: compiler). |
52 self toTokenMode. |
|
53 |
|
54 compiler add: 'currentTokenType isNil ifFalse: [ ^ currentTokenType == ', id storeString, '].'. |
|
55 compiler profileTokenRead: id. |
|
56 |
|
57 node allNodes size > 2 ifTrue: [ |
|
58 self addGuard: node ifTrue: nil ifFalse: [ compiler addOnLine: '^ false' ]. |
|
59 ]. |
|
60 |
30 |
61 |
31 compiler codeAssign: 'context position + 1.' to: startVar. |
62 compiler codeAssign: 'context position + 1.' to: startVar. |
32 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: #whatever. |
63 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: #whatever. |
33 compiler add: 'error ifFalse: [ '. |
64 compiler add: 'error ifTrue: [ ^ error := false ].'. |
34 compiler indent. |
65 |
35 compiler codeAssign: 'context position.' to: endVar. |
66 compiler codeAssign: 'context position.' to: endVar. |
|
67 |
|
68 compiler codeTranscriptShow: 'current token type: ', id storeString. |
|
69 compiler codeAssign: id storeString, '.' to: 'currentTokenType'. |
|
70 compiler codeAssign: node tokenClass asString, ' on: (context collection) |
|
71 start: ', startVar, ' |
|
72 stop: ', endVar, ' |
|
73 value: nil.' |
|
74 to: 'currentTokenValue := ', self retvalVar. |
36 |
75 |
37 compiler codeTranscriptShow: 'current token type: ', id storeString. |
76 |
38 compiler codeAssign: id storeString, '.' to: 'currentTokenType'. |
77 compiler codeClearError. |
39 compiler codeAssign: node tokenClass asString, ' on: (context collection) |
78 compiler add: '^ true'. |
40 start: ', startVar, ' |
79 |
41 stop: ', endVar, ' |
80 self fromTokenMode. |
42 value: nil.' |
81 ! |
43 to: 'currentTokenValue := ', self retvalVar. |
82 |
44 compiler codeReturn. |
83 visitTrimmingTokenCharacterNode: node |
45 compiler dedent. |
84 | id | |
46 compiler add: '].'. |
85 |
47 compiler rememberStrategy: (PPCCompilerTokenizingRememberStrategy on: compiler). |
86 "Tokens cannot be inlined, |
|
87 - their result is true/false |
|
88 - the return value is always stored in currentTokenValue |
|
89 - the current token type is always stored in currentTokenType |
|
90 " |
|
91 self assert: node isMarkedForInline not. |
|
92 |
|
93 id := compiler idFor: node. |
|
94 self toTokenMode. |
|
95 |
|
96 compiler add: 'currentTokenType isNil ifFalse: [ ^ currentTokenType == ', id storeString, '].'. |
|
97 compiler profileTokenRead: id. |
|
98 |
|
99 self addGuard: node ifTrue: nil ifFalse: [ compiler addOnLine: ' ^ false' ]. |
|
100 |
|
101 compiler add: 'context next.'. |
|
102 |
|
103 compiler codeTranscriptShow: 'current token type: ', id storeString. |
|
104 compiler codeAssign: id storeString, '.' to: 'currentTokenType'. |
|
105 compiler codeAssign: node tokenClass asString, ' on: (context collection) |
|
106 start: context position |
|
107 stop: context position |
|
108 value: nil.' |
|
109 to: 'currentTokenValue := ', self retvalVar. |
|
110 |
|
111 compiler addComment: 'Consume Whitespace:'. |
|
112 compiler codeStoreValueOf: [ self visit: node whitespace ] intoVariable: #whatever. |
|
113 compiler nl. |
|
114 |
|
115 compiler add: '^ true'. |
|
116 |
|
117 self fromTokenMode. |
48 ! |
118 ! |
49 |
119 |
50 visitTrimmingTokenNode: node |
120 visitTrimmingTokenNode: node |
51 | id startVar endVar | |
121 | id startVar endVar | |
|
122 |
|
123 "Tokens cannot be inlined, |
|
124 - their result is true/false |
|
125 - the return value is always stored in currentTokenValue |
|
126 - the current token type is always stored in currentTokenType |
|
127 " |
|
128 self assert: node isMarkedForInline not. |
52 |
129 |
53 startVar := compiler allocateTemporaryVariableNamed: 'start'. |
130 startVar := compiler allocateTemporaryVariableNamed: 'start'. |
54 endVar := compiler allocateTemporaryVariableNamed: 'end'. |
131 endVar := compiler allocateTemporaryVariableNamed: 'end'. |
55 |
132 |
56 id := compiler idFor: node. |
133 id := compiler idFor: node. |
57 compiler rememberStrategy: (PPCCompilerTokenRememberStrategy on: compiler). |
134 self toTokenMode. |
58 |
135 |
|
136 compiler add: 'currentTokenType isNil ifFalse: [ ^ currentTokenType == ', id storeString, '].'. |
|
137 compiler profileTokenRead: id. |
59 |
138 |
60 compiler addComment: 'Consume Whitespace:'. |
139 node allNodes size > 2 ifTrue: [ |
61 compiler codeStoreValueOf: [ self visit: node whitespace ] intoVariable: #whatever. |
140 self addGuard: node ifTrue: nil ifFalse: [ compiler addOnLine: '^ false' ]. |
62 compiler nl. |
141 ]. |
63 |
142 |
64 compiler codeAssign: 'context position + 1.' to: startVar. |
143 compiler codeAssign: 'context position + 1.' to: startVar. |
65 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: #whatever. |
144 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: #whatever. |
66 |
145 |
67 compiler add: 'error ifFalse: [ '. |
146 compiler add: 'error ifTrue: [ ^ error := false ].'. |
68 compiler indent. |
147 |
69 compiler codeAssign: 'context position.' to: endVar. |
148 compiler codeAssign: 'context position.' to: endVar. |
70 |
149 |
71 compiler addComment: 'Consume Whitespace:'. |
150 compiler addComment: 'Consume Whitespace:'. |
72 compiler codeStoreValueOf: [ self visit: node whitespace ] intoVariable: #whatever. |
151 compiler codeStoreValueOf: [ self visit: node whitespace ] intoVariable: #whatever. |
73 compiler nl. |
152 compiler nl. |