raz -q def: where the name at the cursor is declared raz -q def Main.raz:LINE:COL reads to the cursor as words does and writes one row: the place of the name's declaration (as check gives places), its kind, name and type. A module's place is its file; a name of the universe or a built-in has none. For an editor's hover and go to definition (raz-lsp). Scan: word, the cursor's name whole; a cursor at a name's start is in that name. Diag: writePlace, out of row. Sym: describe, out of offer. Parse: answer, for words and def (setDefine).
| @@ -95,6 +95,7 @@ | ||
| 95 | 95 | raz run [option]... Main.raz [arg]... |
| 96 | 96 | raz -q check [option]... Main.raz |
| 97 | 97 | raz -q words [option]... Main.raz:LINE:COL |
| 98 | + raz -q def [option]... Main.raz:LINE:COL | |
| 98 | 99 | raz -h |
| 99 | 100 | raz --version |
| 100 | 101 |
| @@ -16,18 +16,18 @@ | ||
| 16 | 16 | |
| 17 | 17 | | File | Lines | Code | What | |
| 18 | 18 | |---|---|---|---| |
| 19 | -| `src/Diag.raz` | 472 | 358 | Messages: positions, source excerpts, colour, counts | | |
| 20 | -| `src/Scan.raz` | 1,260 | 1,036 | Symbols, literals, comments, positions | | |
| 21 | -| `src/Sym.raz` | 856 | 682 | Types, objects, scopes, layout | | |
| 19 | +| `src/Diag.raz` | 479 | 363 | Messages: positions, source excerpts, colour, counts | | |
| 20 | +| `src/Scan.raz` | 1,267 | 1,040 | Symbols, literals, comments, positions | | |
| 21 | +| `src/Sym.raz` | 865 | 688 | Types, objects, scopes, layout | | |
| 22 | 22 | | `src/Chunk.raz` | 364 | 280 | The compiled program: chunks, fixups, line notes | |
| 23 | 23 | | `src/X64.raz` | 1,777 | 1,450 | The instruction encoder, jumps within a procedure, the assembler | |
| 24 | 24 | | `src/Gen.raz` | 2,846 | 1,989 | The stack machine, for x86-64: values, operations, checks, calls, frames | |
| 25 | 25 | | `src/Item.raz` | 2,553 | 2,051 | Items: types, constants, variables, operators, conversions, calls | |
| 26 | -| `src/Parse.raz` | 4,892 | 4,154 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 26 | +| `src/Parse.raz` | 4,918 | 4,175 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 27 | 27 | | `src/Link.raz` | 411 | 317 | Tree shaking, layout, patching, the places | |
| 28 | 28 | | `src/Elf.raz` | 450 | 356 | Static and dynamic ELF, symbol table, line numbers | |
| 29 | 29 | | `src/Host.raz` | 103 | 52 | The system running the compiler | |
| 30 | -| `src/Raz.raz` | 488 | 381 | The command line, and `-q` for an editor | | |
| 30 | +| `src/Raz.raz` | 492 | 384 | The command line, and `-q` for an editor | | |
| 31 | 31 | |
| 32 | 32 | Every file opens with a comment that says what it is, what it depends |
| 33 | 33 | on and what it leaves out. Read those first; they are the map. |
| @@ -2343,7 +2343,8 @@ | ||
| 2343 | 2343 | `raz -q` answers an editor's language server about the text it holds, |
| 2344 | 2344 | saved or not, with the compiler itself, so that there is one grammar |
| 2345 | 2345 | and one set of rules. It is a compile that writes no program, with |
| 2346 | -three changes, each in the unit it concerns. | |
| 2346 | +three changes, each in the unit it concerns. `-q def` answers an | |
| 2347 | +editor's hover and "go to definition" the same way. | |
| 2347 | 2348 | |
| 2348 | 2349 | - **The text from standard input.** `Raz.forEditor` gives `Scan` the |
| 2349 | 2350 | main module's path (`Scan.setStdin`); `Scan.open`, asked for that |
| @@ -2363,12 +2364,17 @@ | ||
| 2363 | 2364 | cursor, it makes the symbol there a name, `Scan.atCursor`, which no |
| 2364 | 2365 | source can spell (`(cursor)`), and keeps what is typed of the name |
| 2365 | 2366 | in `Scan.prefix`: the bytes from the start of the name the cursor is |
| 2366 | - in or just after, or none if it is between symbols. The parser reads | |
| 2367 | - on as for any name; where `qualIdent` would look a name up, it | |
| 2368 | - meets `atCursor` and calls `complete` instead, which writes the | |
| 2369 | - names that reach there (`Sym.offer`, over the same test as | |
| 2370 | - `closest`'s, `Sym.reaches`) and ends the compile. After `M.`, the | |
| 2371 | - names are what `M` exports. A cursor inside a comment or a string | |
| 2367 | + in, just after or at the start of, or none if it is between | |
| 2368 | + symbols; `Scan.word` is that name whole. The parser reads on as for | |
| 2369 | + any name; where `qualIdent` would look a name up, it meets | |
| 2370 | + `atCursor` and calls `answer` instead, which ends the compile. For | |
| 2371 | + `-q words` it writes the names that reach there (`Sym.offer`, over | |
| 2372 | + the same test as `closest`'s, `Sym.reaches`); after `M.`, the names | |
| 2373 | + are what `M` exports. For `-q def` (`Parse.define`) it looks | |
| 2374 | + `Scan.word` up there and writes its declaration's place | |
| 2375 | + (`Diag.writePlace`, which `-q check`'s rows use too) and what it is | |
| 2376 | + (`Sym.describe`, which `offer`'s rows use): a module's place is its | |
| 2377 | + file, and a name of the universe or a built-in has none. A cursor inside a comment or a string | |
| 2372 | 2378 | is dropped, so that it gives no names. Since `cursor` is part of the |
| 2373 | 2379 | scanner's state, a recovery or a read ahead that puts the state back |
| 2374 | 2380 | puts the cursor back too, and it is met again. |
| @@ -22,6 +22,10 @@ | ||
| 22 | 22 | .Fl q Cm words |
| 23 | 23 | .Op Ar option ... |
| 24 | 24 | .Ar Main.raz : Ns Ar LINE : Ns Ar COL |
| 25 | +.Nm | |
| 26 | +.Fl q Cm def | |
| 27 | +.Op Ar option ... | |
| 28 | +.Ar Main.raz : Ns Ar LINE : Ns Ar COL | |
| 25 | 29 | .Sh DESCRIPTION |
| 26 | 30 | .Nm |
| 27 | 31 | compiles the module in |
| @@ -189,6 +193,12 @@ | ||
| 189 | 193 | .Ar Main.raz , |
| 190 | 194 | write the names that can be typed at that cursor, a row each, and |
| 191 | 195 | nothing else. |
| 196 | +.It Fl q Cm def | |
| 197 | +For an editor: with | |
| 198 | +.Ar Main.raz : Ns Ar LINE : Ns Ar COL | |
| 199 | +in place of | |
| 200 | +.Ar Main.raz , | |
| 201 | +write where the name at that cursor is declared, and what it is. | |
| 192 | 202 | .It Fl h , Fl \-help |
| 193 | 203 | Say the options. |
| 194 | 204 | .It Fl \-version |
| @@ -306,6 +316,34 @@ | ||
| 306 | 316 | The rows come in no order. |
| 307 | 317 | Inside a comment or a string, after a record's dot, or where a name is |
| 308 | 318 | declared, there are none. |
| 319 | +It exits 0. | |
| 320 | +.Pp | |
| 321 | +.Fl q Cm def | |
| 322 | +reads the module up to the cursor as | |
| 323 | +.Cm words | |
| 324 | +does, and gives one row for the name the cursor is in, or just after: | |
| 325 | +.Bd -literal -offset indent | |
| 326 | +FILE LINE COL ENDLINE ENDCOL KIND NAME TYPE | |
| 327 | +.Ed | |
| 328 | +.Pp | |
| 329 | +where the place is that of the name in its declaration, as | |
| 330 | +.Cm check | |
| 331 | +gives places, and | |
| 332 | +.Ar KIND | |
| 333 | +and | |
| 334 | +.Ar TYPE | |
| 335 | +are as | |
| 336 | +.Cm words | |
| 337 | +gives them. | |
| 338 | +A module's place is the start of its file; a name of the language's | |
| 339 | +own, as | |
| 340 | +.Cm INT | |
| 341 | +or | |
| 342 | +.Cm LEN , | |
| 343 | +has no file, and zeros. | |
| 344 | +Where | |
| 345 | +.Cm words | |
| 346 | +would give no names, it gives no row. | |
| 309 | 347 | It exits 0. |
| 310 | 348 | .Sh LISTING |
| 311 | 349 | The listing of |
| @@ -247,23 +247,30 @@ | ||
| 247 | 247 | return n; |
| 248 | 248 | end; |
| 249 | 249 | |
| 250 | -(* A message as raz -q check gives it, a row for an editor: the file, | |
| 251 | - the line and the byte in the line where p starts, the same where it | |
| 252 | - ends, the kind and the message, split by tabs; all from 1. A message | |
| 253 | - about no place in a file has no file, and zeros. *) | |
| 254 | -proc row(p: Pos; kind, msg: []const U8); | |
| 250 | +(* p as raz -q gives a place, written to b: the file, the line and the | |
| 251 | + byte in the line where p starts, the same where it ends, split by | |
| 252 | + tabs; all from 1. A place in no file has no file, and zeros. *) | |
| 253 | +proc writePlace*(var b: Buf.Buf; p: Pos); | |
| 255 | 254 | var line, start, endLine, endStart: INT; e: Pos; |
| 256 | 255 | begin |
| 257 | 256 | if p.f >= numFiles then |
| 258 | - Fmt.write(out, "\t0\t0\t0\t0\t{}\t{}\n", [Fmt.str(kind), Fmt.str(msg)]); | |
| 259 | - else | |
| 260 | - line, start := locate(p); | |
| 261 | - e := p; | |
| 262 | - e.a := p.b; | |
| 263 | - endLine, endStart := locate(e); | |
| 264 | - Fmt.write(out, "{}\t{}\t{}\t{}\t{}\t{}\t{}\n", [Fmt.str(files[p.f].path), Fmt.int(line), | |
| 265 | - Fmt.int(p.a - start + 1), Fmt.int(endLine), Fmt.int(p.b - endStart + 1), Fmt.str(kind), Fmt.str(msg)]); | |
| 257 | + Buf.str(b, "\t0\t0\t0\t0"); | |
| 258 | + return; | |
| 266 | 259 | end; |
| 260 | + line, start := locate(p); | |
| 261 | + e := p; | |
| 262 | + e.a := p.b; | |
| 263 | + endLine, endStart := locate(e); | |
| 264 | + Fmt.write(b, "{}\t{}\t{}\t{}\t{}", [Fmt.str(files[p.f].path), Fmt.int(line), Fmt.int(p.a - start + 1), | |
| 265 | + Fmt.int(endLine), Fmt.int(p.b - endStart + 1)]); | |
| 266 | +end; | |
| 267 | + | |
| 268 | +(* A message as raz -q check gives it, a row for an editor: its place, | |
| 269 | + its kind and its text, split by tabs *) | |
| 270 | +proc row(p: Pos; kind, msg: []const U8); | |
| 271 | +begin | |
| 272 | + writePlace(out, p); | |
| 273 | + Fmt.write(out, "\t{}\t{}\n", [Fmt.str(kind), Fmt.str(msg)]); | |
| 267 | 274 | flush; |
| 268 | 275 | end; |
| 269 | 276 |
| @@ -94,6 +94,7 @@ | ||
| 94 | 94 | firstModule*, lastModule*: PModule; (* in the order they were finished *) |
| 95 | 95 | |
| 96 | 96 | checkMode: BOOL; (* reading a file only for its interface *) |
| 97 | + define: BOOL; (* raz -q def: the cursor asks where its name is declared *) | |
| 97 | 98 | inTypes: BOOL; (* in a type section: ^T, and a procedure type, may name a later type *) |
| 98 | 99 | laters: [MaxLater]Later; |
| 99 | 100 | numLater: INT; |
| @@ -179,6 +180,12 @@ | ||
| 179 | 180 | thisVersion := v; |
| 180 | 181 | end; |
| 181 | 182 | |
| 183 | +(* raz -q def, not words: the cursor asks where its name is declared *) | |
| 184 | +proc setDefine*(yes: BOOL); | |
| 185 | +begin | |
| 186 | + define := yes; | |
| 187 | +end; | |
| 188 | + | |
| 182 | 189 | proc nameOf(n: INT): []const U8; |
| 183 | 190 | begin |
| 184 | 191 | return Scan.nameOf(n); |
| @@ -558,14 +565,33 @@ | ||
| 558 | 565 | [Fmt.str(a), Fmt.str(nameOf(o^.name)), Fmt.str(b), Fmt.str(nameOf(o^.name))])); |
| 559 | 566 | end; |
| 560 | 567 | |
| 561 | -(* raz -q words: the current symbol is the cursor, where a name of | |
| 562 | - scope s can be typed, or of any scope open if s < 0. The names that | |
| 563 | - start with what is typed are written, and the compile ends. *) | |
| 564 | -proc complete(s: INT); | |
| 565 | -var b: Buf.Buf; | |
| 568 | +(* raz -q words or def: the current symbol is the cursor, where a name | |
| 569 | + of scope s is written, or of any scope open if s < 0. words writes | |
| 570 | + the names that start with what is typed there; def where the name | |
| 571 | + written there is declared, its place and what it is: a module's | |
| 572 | + place is its file, and the language's own names have none. Then the | |
| 573 | + compile ends. *) | |
| 574 | +proc answer(s: INT); | |
| 575 | +var b: Buf.Buf; o: PObj; | |
| 566 | 576 | begin |
| 567 | 577 | Buf.init(b, Heap.heap); |
| 568 | - Sym.offer(s, Scan.prefix, b); | |
| 578 | + if not define then | |
| 579 | + Sym.offer(s, Scan.prefix, b); | |
| 580 | + else | |
| 581 | + if s < 0 then o := Sym.lookup(internName(Scan.word)); else o := Sym.find(s, internName(Scan.word)); end; | |
| 582 | + if (o # nil) and (o^.typ # Sym.tPoison) then | |
| 583 | + if (o^.cls = Sym.oModule) and (o^.home # nil) and (o^.home^.path # "") then | |
| 584 | + Fmt.write(b, "{}\t1\t1\t1\t1", [Fmt.str(Diag.shownPath(o^.home^.path))]); | |
| 585 | + elsif (o^.scope = 0) or (o^.cls = Sym.oBuiltin) then | |
| 586 | + Diag.writePlace(b, {f: MAX(INT), a: 0, b: 0}); | |
| 587 | + else | |
| 588 | + Diag.writePlace(b, o^.pos); | |
| 589 | + end; | |
| 590 | + Buf.add(b, '\t'); | |
| 591 | + Sym.describe(o, b); | |
| 592 | + Buf.add(b, '\n'); | |
| 593 | + end; | |
| 594 | + end; | |
| 569 | 595 | Out.str(Buf.bytes(b)); |
| 570 | 596 | Out.flush(); |
| 571 | 597 | Rt.exit(0); |
| @@ -575,7 +601,7 @@ | ||
| 575 | 601 | var o: PObj; m: PModule; at: Diag.Pos; |
| 576 | 602 | begin |
| 577 | 603 | if Scan.tok # Scan.sIdent then return nil, expected("a name"); end; |
| 578 | - if Scan.id = Scan.atCursor then complete(-1); end; | |
| 604 | + if Scan.id = Scan.atCursor then answer(-1); end; | |
| 579 | 605 | at := Scan.tokPos(); |
| 580 | 606 | o := Sym.lookup(Scan.id); |
| 581 | 607 | if o = nil then |
| @@ -593,7 +619,7 @@ | ||
| 593 | 619 | try expect(Scan.sPeriod); |
| 594 | 620 | if Scan.tok # Scan.sIdent then return nil, expected("a name"); end; |
| 595 | 621 | m := o^.home; |
| 596 | - if Scan.id = Scan.atCursor then complete(m^.scope); end; | |
| 622 | + if Scan.id = Scan.atCursor then answer(m^.scope); end; | |
| 597 | 623 | o := Sym.find(m^.scope, Scan.id); |
| 598 | 624 | if (o = nil) or not o^.exported then |
| 599 | 625 | Diag.error(Scan.tokPos(), say2("{} isn't exported by {}", nameOf(Scan.id), nameOf(m^.name))); |
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | raz [-I dir]... [-o file] [-Werror] [-S] [-libc glibc|musl] [-base addr] [-bare] Main.raz |
| 4 | 4 | raz run [-I dir]... Main.raz [arg]... |
| 5 | - raz -q check|words [-I dir]... Main.raz[:LINE:COL] | |
| 5 | + raz -q check|words|def [-I dir]... Main.raz[:LINE:COL] | |
| 6 | 6 | raz --version |
| 7 | 7 | |
| 8 | 8 | Compiles the main module and every module it imports, writes the |
| @@ -13,8 +13,9 @@ | ||
| 13 | 13 | place with the arguments after Main.raz, so its status is the |
| 14 | 14 | program's; its argv[0] is Main.raz. raz -q, for an editor, reads |
| 15 | 15 | the main module's text from standard input and stops once it is |
| 16 | - checked: check writes its messages as rows, and words the names | |
| 17 | - that can be typed at the cursor (forEditor). | |
| 16 | + checked: check writes its messages as rows, words the names that | |
| 17 | + can be typed at the cursor, and def where the name there is | |
| 18 | + declared (forEditor). | |
| 18 | 19 | |
| 19 | 20 | The program starts by saving argc and argv, runs every module's body |
| 20 | 21 | (those of the modules the program imports, imported modules first), |
| @@ -137,8 +138,8 @@ | ||
| 137 | 138 | end; |
| 138 | 139 | |
| 139 | 140 | (* raz -q, for an editor: the main module's text is standard input, |
| 140 | - and messages are rows (check) or not given (words, whose path names | |
| 141 | - the cursor). The result is the main module's path. *) | |
| 141 | + and messages are rows (check) or not given (words and def, whose | |
| 142 | + path names the cursor). The result is the main module's path. *) | |
| 142 | 143 | proc forEditor(query, path: []const U8): []const U8; |
| 143 | 144 | var line, col: INT; ok: BOOL; |
| 144 | 145 | begin |
| @@ -146,12 +147,13 @@ | ||
| 146 | 147 | col := 0; |
| 147 | 148 | if query = "check" then |
| 148 | 149 | Diag.setForm(Diag.Form.rows); |
| 149 | - elsif query = "words" then | |
| 150 | + elsif (query = "words") or (query = "def") then | |
| 150 | 151 | path, line, col, ok := cursorAt(path); |
| 151 | - if not ok then Diag.fatal(say1("-q words {}: expected FILE:LINE:COL", path)); end; | |
| 152 | + if not ok then Diag.fatal(Diag.say("-q {} {}: expected FILE:LINE:COL", [Fmt.str(query), Fmt.str(path)])); end; | |
| 152 | 153 | Diag.setForm(Diag.Form.silent); |
| 154 | + Parse.setDefine(query = "def"); | |
| 153 | 155 | else |
| 154 | - Diag.fatal(say1("-q {}: expected check or words", query)); | |
| 156 | + Diag.fatal(say1("-q {}: expected check, words or def", query)); | |
| 155 | 157 | end; |
| 156 | 158 | Scan.setStdin(path, line, col); |
| 157 | 159 | return path; |
| @@ -182,6 +184,8 @@ | ||
| 182 | 184 | Out.str(" input, and writes each message as a row (see raz(1))\n"); |
| 183 | 185 | Out.str(" -q words with Main.raz:LINE:COL, writes the names that can be\n"); |
| 184 | 186 | Out.str(" typed at the cursor there, one row each\n"); |
| 187 | + Out.str(" -q def with Main.raz:LINE:COL, writes where the name at the\n"); | |
| 188 | + Out.str(" cursor is declared, and what it is\n"); | |
| 185 | 189 | Out.str(" -h, --help says this\n"); |
| 186 | 190 | Out.str(" --version says the version, and the report it follows\n"); |
| 187 | 191 | Out.str("see raz(1), and the report, doc/raz.md\n"); |
| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | For an editor (raz -q), one file's text may come from standard |
| 10 | 10 | input instead (setStdin), and a place in it may be marked: the |
| 11 | 11 | symbol there is a name, atCursor, standing for what is typed of the |
| 12 | - name at the cursor, prefix, so that the parser can say what names | |
| 13 | - can be typed there. | |
| 12 | + name at the cursor, prefix, and for the name written there whole, | |
| 13 | + word, so that the parser can say what names can be typed there, or | |
| 14 | + where the name there is declared. | |
| 14 | 15 | |
| 15 | 16 | Depends on: Sys, to read files; Diag, to report errors. |
| 16 | 17 | Leaves out: recovery from errors in the text itself, such as a string |
| @@ -90,6 +91,7 @@ | ||
| 90 | 91 | |
| 91 | 92 | atCursor*: INT; (* the name the symbol at the cursor has *) |
| 92 | 93 | prefix*: []const U8; (* what is typed of the name at the cursor *) |
| 94 | + word*: []const U8; (* the whole name at the cursor, as raz -q def asks of it *) | |
| 93 | 95 | stdinPath: []const U8; (* the file whose text is standard input, or "" *) |
| 94 | 96 | cursorLine, cursorCol: INT; (* the cursor in it, from 1, or 0 for none *) |
| 95 | 97 | |
| @@ -1081,10 +1083,11 @@ | ||
| 1081 | 1083 | end; |
| 1082 | 1084 | |
| 1083 | 1085 | (* Makes the current symbol the name at the cursor, typed from start up |
| 1084 | - to at; the cursor is passed then *) | |
| 1085 | -proc cursorName(start, at: INT); | |
| 1086 | + to at, and written whole up to stop; the cursor is passed then *) | |
| 1087 | +proc cursorName(start, at, stop: INT); | |
| 1086 | 1088 | begin |
| 1087 | 1089 | prefix := cur.buf[start..at]; |
| 1090 | + word := cur.buf[start..stop]; | |
| 1088 | 1091 | cur.cursor := MAX(INT); |
| 1089 | 1092 | tok := sIdent; |
| 1090 | 1093 | id := atCursor; |
| @@ -1123,12 +1126,16 @@ | ||
| 1123 | 1126 | cur.tokLineStart := cur.lineStart; |
| 1124 | 1127 | if p >= cur.cursor then |
| 1125 | 1128 | (* the cursor is before this symbol: if it was between symbols, not |
| 1126 | - in a string or a comment, a name of nothing typed is made there *) | |
| 1127 | - if cur.prevEnd <= cur.cursor then | |
| 1128 | - cursorName(cur.cursor, cur.cursor); | |
| 1129 | + in a string or a comment, a name of nothing typed is made there; | |
| 1130 | + at the start of a name, the name is the cursor's, read below *) | |
| 1131 | + if (p = cur.cursor) and (isLetter(c) or (c = '_')) then | |
| 1132 | + (* the name's own branch makes it *) | |
| 1133 | + elsif cur.prevEnd <= cur.cursor then | |
| 1134 | + cursorName(cur.cursor, cur.cursor, cur.cursor); | |
| 1129 | 1135 | return; |
| 1136 | + else | |
| 1137 | + cur.cursor := MAX(INT); | |
| 1130 | 1138 | end; |
| 1131 | - cur.cursor := MAX(INT); | |
| 1132 | 1139 | end; |
| 1133 | 1140 | if single[c] # sNull then |
| 1134 | 1141 | INC(cur.pos); |
| @@ -1141,7 +1148,7 @@ | ||
| 1141 | 1148 | repeat INC(p); until not nameChar[buf[p]]; |
| 1142 | 1149 | cur.pos := p; |
| 1143 | 1150 | if p >= cur.cursor then (* the name the cursor is in or just after *) |
| 1144 | - cursorName(start, cur.cursor); | |
| 1151 | + cursorName(start, cur.cursor, p); | |
| 1145 | 1152 | return; |
| 1146 | 1153 | end; |
| 1147 | 1154 | if p - start > MaxIdent then |
| @@ -438,20 +438,29 @@ | ||
| 438 | 438 | end; |
| 439 | 439 | end; |
| 440 | 440 | |
| 441 | +(* What o is, as raz -q says it: its kind, its name and its type, | |
| 442 | + split by tabs, written to out *) | |
| 443 | +proc describe*(o: ^Obj; var out: Buf.Buf); | |
| 444 | +var t: []const U8; | |
| 445 | +begin | |
| 446 | + t := ""; | |
| 447 | + if (o^.typ # nil) and (o^.cls # oModule) and (o^.cls # oBuiltin) then t := typeName(o^.typ); end; | |
| 448 | + Fmt.write(out, "{}\t{}\t{}", [Fmt.str(kindOf(o)), Fmt.str(Scan.nameOf(o^.name)), Fmt.str(t)]); | |
| 449 | +end; | |
| 450 | + | |
| 441 | 451 | (* raz -q words: a row in out for each name in reach that starts with |
| 442 | 452 | prefix, in scope s as closest has it: its kind, the name and its |
| 443 | 453 | type, split by tabs. A name another declaration hides is left out. *) |
| 444 | 454 | proc offer*(s: INT; prefix: []const U8; var out: Buf.Buf); |
| 445 | -var i: INT; o: ^Obj; n, t: []const U8; | |
| 455 | +var i: INT; o: ^Obj; n: []const U8; | |
| 446 | 456 | begin |
| 447 | 457 | for i := 0 to hashMask do |
| 448 | 458 | o := hashTab[i]; |
| 449 | 459 | if reaches(o, s) and ((s >= 0) or (lookup(o^.name) = o)) then |
| 450 | 460 | n := Scan.nameOf(o^.name); |
| 451 | - t := ""; | |
| 452 | - if (o^.typ # nil) and (o^.cls # oModule) and (o^.cls # oBuiltin) then t := typeName(o^.typ); end; | |
| 453 | 461 | if (LEN(n) >= LEN(prefix)) and (n[0..LEN(prefix)] = prefix) then |
| 454 | - Fmt.write(out, "{}\t{}\t{}\n", [Fmt.str(kindOf(o)), Fmt.str(n), Fmt.str(t)]); | |
| 462 | + describe(o, out); | |
| 463 | + Buf.add(out, '\n'); | |
| 455 | 464 | end; |
| 456 | 465 | end; |
| 457 | 466 | end; |
| @@ -168,12 +168,15 @@ | ||
| 168 | 168 | && readelf -s $out/own/Own | grep -q ' Own.main$' && readelf --debug-dump=decodedline $out/own/Own | grep -q 'Own.raz'; then pass=$((pass + 1)) |
| 169 | 169 | else echo "FAIL own Rt: status $status, $statusFail"; cat $out/own/Own.out $out/own/OwnFail.out; fail=$((fail + 1)); fi |
| 170 | 170 | |
| 171 | -# raz -q, for an editor: check's rows, and the names words offers at a | |
| 171 | +# raz -q, for an editor: check's rows; the names words offers at a | |
| 172 | 172 | # cursor after a part of a name, after a module's dot, and none in a |
| 173 | -# comment or a string. The text is standard input: checking an empty | |
| 174 | -# one shows that the file on disk isn't read. | |
| 173 | +# comment or a string; and where def finds a local, another module's | |
| 174 | +# name, a module and a built-in, which has no place. The text is | |
| 175 | +# standard input: checking an empty one shows that the file on disk | |
| 176 | +# isn't read. | |
| 175 | 177 | for t in "check Check.raz check" "words Words.raz:9:16 prefix" "words Words.raz:10:11 export" \ |
| 176 | - "words Words.raz:11:10 none" "words Words.raz:12:15 none"; do | |
| 178 | + "words Words.raz:11:10 none" "words Words.raz:12:15 none" "def Def.raz:10:15 def-local" \ | |
| 179 | + "def Def.raz:11:9 def-export" "def Def.raz:11:6 def-module" "def Def.raz:10:24 def-builtin"; do | |
| 177 | 180 | set -- $t |
| 178 | 181 | f=test/query/${2%%:*} |
| 179 | 182 | $raz -q $1 test/query/$2 < $f > $out/query.out |
| @@ -0,0 +1,19 @@ | ||
| 1 | +module Def; | |
| 2 | +import Out; | |
| 3 | + | |
| 4 | +var count: INT; | |
| 5 | + | |
| 6 | +(* Says hello. *) | |
| 7 | +proc greet(name: []const U8); | |
| 8 | +var total: INT; | |
| 9 | +begin | |
| 10 | + total := count + LEN(name); | |
| 11 | + Out.str(name); | |
| 12 | +end; | |
| 13 | + | |
| 14 | +proc main*; | |
| 15 | +begin | |
| 16 | + greet("x"); | |
| 17 | +end; | |
| 18 | + | |
| 19 | +end Def. |
| @@ -0,0 +1 @@ | ||
| 1 | + 0 0 0 0 builtin LEN |
| @@ -0,0 +1 @@ | ||
| 1 | +lib/Out.raz 53 6 53 9 proc str proc([]const U8) |
| @@ -0,0 +1 @@ | ||
| 1 | +test/query/Def.raz 4 5 4 10 var count INT |
| @@ -0,0 +1 @@ | ||
| 1 | +lib/Out.raz 1 1 1 1 module Out |