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