Rev 8973 | Rev 8975 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8973 | Rev 8974 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | import argparse |
3 | import argparse |
4 | import sys |
4 | import sys |
Line 5... | Line 5... | ||
5 | 5 | ||
6 | """ TODO: |
6 | """ TODO: |
7 | - Optimize name and var_type checking |
- | |
8 | - Translate dict in AsmReaderReadingComments into just a set of fields |
- | |
9 | - Check if we should return handled_files from handle_file |
7 | - Optimize name and var_type checking |
Line 10... | Line 8... | ||
10 | """ |
8 | """ |
11 | 9 | ||
12 | # Parameters |
10 | # Parameters |
Line 1261... | Line 1259... | ||
1261 | self.status_reset() |
1259 | self.status_reset() |
1262 | self.comment = '' |
1260 | self.comment = '' |
Line 1263... | Line 1261... | ||
1263 | 1261 | ||
1264 | def status_reset(self): |
1262 | def status_reset(self): |
1265 | # If the line has non-comment code |
1263 | # If the line has non-comment code |
1266 | self.status['has_code'] = False |
1264 | self.status_has_code = False |
1267 | # If the line has a comment at the end |
1265 | # If the line has a comment at the end |
1268 | self.status['has_comment'] = False |
1266 | self.status_has_comment = False |
1269 | # Let it recognize strings further, we are definitely out of a comment |
1267 | # Let it recognize strings further, we are definitely out of a comment |
Line 1270... | Line 1268... | ||
1270 | self.should_recognize_strings = True |
1268 | self.should_recognize_strings = True |
1271 | 1269 | ||
1272 | def status_set_has_comment(self): |
1270 | def status_set_has_comment(self): |
1273 | self.status['has_comment'] = True |
1271 | self.status_has_comment = True |
Line 1274... | Line 1272... | ||
1274 | # Don't let it recognize strings cause we are in a comment now |
1272 | # Don't let it recognize strings cause we are in a comment now |
1275 | self.should_recognize_strings = False |
1273 | self.should_recognize_strings = False |
1276 | - | ||
1277 | def status_set_has_code(self): |
- | |
1278 | self.status['has_code'] = True |
- | |
1279 | - | ||
1280 | def status_has_comment(self): |
- | |
1281 | return self.status['has_comment'] |
- | |
Line 1282... | Line 1274... | ||
1282 | 1274 | ||
1283 | def status_has_code(self): |
1275 | def status_set_has_code(self): |
1284 | return self.status['has_code'] |
1276 | self.status_has_code = True |
1285 | 1277 | ||
1286 | def update_status(self): |
1278 | def update_status(self): |
1287 | # If we aren't in a comment and we aren't in a string - say we are now in a comment if ';' met |
1279 | # If we aren't in a comment and we aren't in a string - say we are now in a comment if ';' met |
1288 | if not self.status_has_comment() and not self.in_string and self.curr() == ';': |
1280 | if not self.status_has_comment and not self.in_string and self.curr() == ';': |
1289 | self.status_set_has_comment() |
1281 | self.status_set_has_comment() |
1290 | # Else if we are in a comment - collect the comment |
1282 | # Else if we are in a comment - collect the comment |
1291 | elif self.status_has_comment(): |
1283 | elif self.status_has_comment: |
1292 | self.comment += self.curr() |
1284 | self.comment += self.curr() |
Line 1293... | Line 1285... | ||
1293 | # Else if there's some non-whitespace character out of a comment |
1285 | # Else if there's some non-whitespace character out of a comment |
1294 | # then the line has code |
1286 | # then the line has code |
1295 | elif not self.status_has_comment() and not self.curr().isspace(): |
1287 | elif not self.status_has_comment and not self.curr().isspace(): |
Line 1305... | Line 1297... | ||
1305 | def nextline(self): |
1297 | def nextline(self): |
1306 | super().nextline() |
1298 | super().nextline() |
1307 | # If the line we leave was not a comment-only line |
1299 | # If the line we leave was not a comment-only line |
1308 | # then forget the collected comment |
1300 | # then forget the collected comment |
1309 | # Otherwise the collected comment should be complemented by comment from next line in step() |
1301 | # Otherwise the collected comment should be complemented by comment from next line in step() |
1310 | if self.status_has_code(): |
1302 | if self.status_has_code: |
1311 | self.comment = '' |
1303 | self.comment = '' |
1312 | # Reset the line status (now it's the status of the new line) |
1304 | # Reset the line status (now it's the status of the new line) |
1313 | self.status_reset() |
1305 | self.status_reset() |
1314 | # Set new status for this line according to the first character in the line |
1306 | # Set new status for this line according to the first character in the line |
1315 | self.update_status() |
1307 | self.update_status() |