]> git.ozlabs.org Git - ccan/blob - ccan/ccan_tokenizer/todo
Added module ccan_tokenizer from snapshot at:
[ccan] / ccan / ccan_tokenizer / todo
1 Update that simple tokenizer compulsory test so things will compile
2
3
4
5 (done) Fix #include <stdio.h> to read include directive correctly
6
7 txt/orig state of affairs:
8
9 The problem is that there are two ways to interpret line,col:
10         With respect to txt
11         With respect to orig
12
13 This isn't a problem when txt and orig point to the same character, as in:
14
15 int in\
16 dex
17 int \
18 index /*Here, the backslash break should be gobbled up by the space identifier*/
19
20 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):
21
22 \
23 int index
24
25 line,col could either point to orig or to the first real character.  Thus, we will do the latter.
26
27 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.
28
29 Thus, on a lookup with a txt pointer, the line/col/orig should match the real character and not preceding backslash breaks.
30
31
32 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?
33
34 Currently, the orig lands after the beginning backslash breaks, when instead it should probably land before them.
35
36 Here's what the tokenizer's text anchoring needs:
37         Broken/unbroken text pointer -> line/col
38         Unbroken contents per token to identify identifier text
39         Original contents per token to rebuild the document
40         Ability to change "original contents" so the document will be saved with modifications
41         Ability to insert new tokens
42
43 Solution:
44         New tokens will typically have identical txt and orig, yea even the same pointer.
45         txt/txt_size for unbroken contents, orig/orig_size for original
46         modify orig to change the document
47         txt identifies identifier text
48         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.
49
50 What this means:
51         Token txt/txt_size, orig/orig_size, orig_lines, txt_lines, and tok_point_lookup are all still correct.
52         Token line,col will be removed
53         
54 Other improvements to do:
55         Sanity check the point lookups like crazy
56         Remove the array() structures in token_list, as these are supposed to be read-only
57
58 Make sure tok_point_lookup returns correct values for every single pointer possible, particularly those in orig that are on backslash-breaks
59
60 Convert the tok_message_queue into an array of messages bound to tokens.
61
62 Ask Rusty about the trailing newline in this case:
63
64 /* Blah
65  * 
66  * blah
67  */
68
69 Here, rather than the trailing space being blank, it is "blank" from the comment perspective.
70 May require deeper analysis.
71
72 Todos from ccan_tokenizer.h
73 /*
74 Assumption:  Every token fits in one and exactly one line
75 Counterexamples:
76         Backslash-broken lines
77         Multiline comments
78
79 Checks to implement in the tokenizer:
80
81 is the $ character used in an identifier (some configurations of GCC allow this)
82 are there potentially ambiguous sequences used in a string literal (e.g. "\0000")
83 Are there stray characters?  (e.g. '\0', '@', '\b')
84 Are there trailing spaces at the end of lines (unless said spaces consume the entire line)?
85         Are there trailing spaces after a backslash-broken line?
86
87
88 Fixes todo:
89
90 backslash-newline sequence should register as an empty character, and the tokenizer's line value should be incremented accordingly.
91 */
92
93 Lex angle bracket strings in #include
94
95 Check the rules in the documentation
96
97 Examine the message queue as part of testing the tokenizer:
98         Make sure there are no bug messages
99         Make sure files compile with no warnings
100 For the tokenizer sanity check, make sure integers and floats have valid suffixes respectively
101         (e.g. no TOK_F for an integer, no TOK_ULL for a floating)
102
103 Update the scan_number sanity checks
104 (done) Move scan_number et al. to a separate C file
105
106 Test:
107         Overflow and underflow floats
108         0x.p0
109         (done) 0755f //octal 0755 with invalid suffix
110         (done) 0755e1 //floating 7550
111
112 Figure out how keywords will be handled.
113         Preprocessor directives are <strike>case-insensitive</strike> actually case-sensitive (except __VA_ARGS__)
114         All C keywords are case sensitive
115         __VA_ARGS__ should be read as an identifier unless it's in the expansion of a macro.  Otherwise, GCC generates a warning.
116                 We are in the expansion of a macro after <startline> <space> # <space> 
117         Don't forget about __attribute__
118         Except for __VA_ARGS__, all preprocessor keywords are proceeded by <startline> <space> # <space>
119
120 Solution:
121         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.
122         Instead, int type will become short type; unsigned short cpp:1;
123
124 Merge
125 Commit ccan_tokenizer to the ccan repo
126 Introduce ccan_tokenizer to ccanlint
127
128 Write testcases for scanning all available operators
129 Support integer and floating point suffices (e.g. 500UL, 0.5f)
130 Examine the message queue after tokenizing
131 Make sure single-character operators have an opkw < 128
132 Make sure c_dictionary has no duplicate entries
133 Write verifiers for other types than TOK_WHITE
134
135 What's been done:
136
137 Operator table has been organized
138 Merged Rusty's changes
139 Fixed if -> while in finalize
140 Fixed a couple mistakes in run-simple-token.c testcases themselves
141         Expected orig/orig_size sizes weren't right
142 Made token_list_sanity_check a public function and used it throughout run-simple-token.c
143 Tests succeed and pass valgrind
144
145 Lines/columns of every token are recorded
146
147 (done) Fix "0\nstatic"
148 (done) Write tests to make sure backslash-broken lines have correct token locations.
149 (done) Correctly handle backslash-broken lines
150         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
151         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 
152 Annotate message queue messages with current token
153
154 Conversion to make:
155         From:
156                 Position in unbroken text
157         To:
158                 Real line number
159                 Real offset from start of line
160
161 Thus, we want an array of real line start locations wrt the unbroken text
162
163 Here is a bro\
164 ken line.  Here is a
165 real line.
166
167 <LINE>Here is a bro<LINE>ken line.  Here is a
168 <LINE>real line.
169
170 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.
171
172 Because all we need is the orig and orig_size with respect to the unbroken text to orient