todo 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. Update that simple tokenizer compulsory test so things will compile
  2. Handle cases like escaped question marks and pound symbols that I don't understand yet.
  3. (done) Fix #include <stdio.h> to read include directive correctly
  4. txt/orig state of affairs:
  5. The problem is that there are two ways to interpret line,col:
  6. With respect to txt
  7. With respect to orig
  8. This isn't a problem when txt and orig point to the same character, as in:
  9. int in\
  10. dex
  11. int \
  12. index /*Here, the backslash break should be gobbled up by the space identifier*/
  13. line,col has no ambiguity as to where it should point. However, when they point to different characters (i.e. at the beginning of a line):
  14. \
  15. int index
  16. line,col could either point to orig or to the first real character. Thus, we will do the latter.
  17. Moreover, will a newline followed by backslash breaks generate a token that gobbles up said breaks? I believe it will, but no need to call this mandatory.
  18. Thus, on a lookup with a txt pointer, the line/col/orig should match the real character and not preceding backslash breaks.
  19. I've been assuming that every token starts with its first character, neglecting the case where a line starts with backslash breaks. The question is, given the txt pointer to the first character, where should the derived orig land?
  20. Currently, the orig lands after the beginning backslash breaks, when instead it should probably land before them.
  21. Here's what the tokenizer's text anchoring needs:
  22. Broken/unbroken text pointer -> line/col
  23. Unbroken contents per token to identify identifier text
  24. Original contents per token to rebuild the document
  25. Ability to change "original contents" so the document will be saved with modifications
  26. Ability to insert new tokens
  27. Solution:
  28. New tokens will typically have identical txt and orig, yea even the same pointer.
  29. txt/txt_size for unbroken contents, orig/orig_size for original
  30. modify orig to change the document
  31. txt identifies identifier text
  32. Line lookup tables are used to resolve txt/orig pointers; other pointers can't be resolved in the same fashion and may require traversing backward through the list.
  33. What this means:
  34. Token txt/txt_size, orig/orig_size, orig_lines, txt_lines, and tok_point_lookup are all still correct.
  35. Token line,col will be removed
  36. Other improvements to do:
  37. Sanity check the point lookups like crazy
  38. Remove the array() structures in token_list, as these are supposed to be read-only
  39. Make sure tok_point_lookup returns correct values for every single pointer possible, particularly those in orig that are on backslash-breaks
  40. Convert the tok_message_queue into an array of messages bound to tokens.
  41. Ask Rusty about the trailing newline in this case:
  42. /* Blah
  43. *
  44. * blah
  45. */
  46. Here, rather than the trailing space being blank, it is "blank" from the comment perspective.
  47. May require deeper analysis.
  48. Todos from ccan_tokenizer.h
  49. /*
  50. Assumption: Every token fits in one and exactly one line
  51. Counterexamples:
  52. Backslash-broken lines
  53. Multiline comments
  54. Checks to implement in the tokenizer:
  55. is the $ character used in an identifier (some configurations of GCC allow this)
  56. are there potentially ambiguous sequences used in a string literal (e.g. "\0000")
  57. Are there stray characters? (e.g. '\0', '@', '\b')
  58. Are there trailing spaces at the end of lines (unless said spaces consume the entire line)?
  59. Are there trailing spaces after a backslash-broken line?
  60. Fixes todo:
  61. backslash-newline sequence should register as an empty character, and the tokenizer's line value should be incremented accordingly.
  62. */
  63. Lex angle bracket strings in #include
  64. Check the rules in the documentation
  65. Examine the message queue as part of testing the tokenizer:
  66. Make sure there are no bug messages
  67. Make sure files compile with no warnings
  68. For the tokenizer sanity check, make sure integers and floats have valid suffixes respectively
  69. (e.g. no TOK_F for an integer, no TOK_ULL for a floating)
  70. Update the scan_number sanity checks
  71. (done) Move scan_number et al. to a separate C file
  72. Test:
  73. Overflow and underflow floats
  74. 0x.p0
  75. (done) 0755f //octal 0755 with invalid suffix
  76. (done) 0755e1 //floating 7550
  77. Figure out how keywords will be handled.
  78. Preprocessor directives are <strike>case-insensitive</strike> actually case-sensitive (except __VA_ARGS__)
  79. All C keywords are case sensitive
  80. __VA_ARGS__ should be read as an identifier unless it's in the expansion of a macro. Otherwise, GCC generates a warning.
  81. We are in the expansion of a macro after <startline> <space> # <space>
  82. Don't forget about __attribute__
  83. Except for __VA_ARGS__, all preprocessor keywords are proceeded by <startline> <space> # <space>
  84. Solution:
  85. All the words themselves will go into one opkw dictionary, and for both type and opkw, no distinction will be made between preprocessor and normal keywords.
  86. Instead, int type will become short type; unsigned short cpp:1;
  87. Merge
  88. Commit ccan_tokenizer to the ccan repo
  89. Introduce ccan_tokenizer to ccanlint
  90. Write testcases for scanning all available operators
  91. Support integer and floating point suffices (e.g. 500UL, 0.5f)
  92. Examine the message queue after tokenizing
  93. Make sure single-character operators have an opkw < 128
  94. Make sure c_dictionary has no duplicate entries
  95. Write verifiers for other types than TOK_WHITE
  96. What's been done:
  97. Operator table has been organized
  98. Merged Rusty's changes
  99. Fixed if -> while in finalize
  100. Fixed a couple mistakes in run-simple-token.c testcases themselves
  101. Expected orig/orig_size sizes weren't right
  102. Made token_list_sanity_check a public function and used it throughout run-simple-token.c
  103. Tests succeed and pass valgrind
  104. Lines/columns of every token are recorded
  105. (done) Fix "0\nstatic"
  106. (done) Write tests to make sure backslash-broken lines have correct token locations.
  107. (done) Correctly handle backslash-broken lines
  108. One plan: Separate the scanning code from the reading code. Scanning sends valid ranges to reading, and reading fills valid tokens for the tokenizer/scanner to properly add
  109. Another plan: Un-break backslash-broken lines into another copy of the input. Create an array of the positions of each real line break so
  110. Annotate message queue messages with current token
  111. Conversion to make:
  112. From:
  113. Position in unbroken text
  114. To:
  115. Real line number
  116. Real offset from start of line
  117. Thus, we want an array of real line start locations wrt the unbroken text
  118. Here is a bro\
  119. ken line. Here is a
  120. real line.
  121. <LINE>Here is a bro<LINE>ken line. Here is a
  122. <LINE>real line.
  123. If we know the position of the token text wrt the unbroken text, we can look up the real line number and offset using only the array of real line start positions within the unbroken text.
  124. Because all we need is the orig and orig_size with respect to the unbroken text to orient