Errors point at the offending construct Items carry their source span; errors about an item or two operands underline it, a missing symbol goes after the one before when the next starts a new line, scanner errors underline the bad characters. An import's arguments keep positions: generic errors point at the importer, with a note at the parameter. Paths are shown from the working directory. 40 new tests in test/err/At*.
| @@ -220,7 +220,7 @@ | ||
| 220 | 220 | `X.err` becomes the whole message, without colour, and the |
| 221 | 221 | Makefile compares all of it. *main*; regenerating and checking |
| 222 | 222 | the 57 `.err` files, *agent*. |
| 223 | -- [ ] 21. Exact positions. An item and a statement remember where | |
| 223 | +- [x] 21. Exact positions. An item and a statement remember where | |
| 224 | 224 | they start, so an error points at the whole offending |
| 225 | 225 | expression, not the symbol after it; a missing `;`, `then` or |
| 226 | 226 | `end` points just after the symbol before it. The scanner keeps |
| @@ -8,12 +8,12 @@ | ||
| 8 | 8 | |
| 9 | 9 | | File | Lines | Code | What | |
| 10 | 10 | |---|---|---|---| |
| 11 | -| `src/diag.pas` | 227 | 162 | Messages: positions, source excerpts, colour, counts | | |
| 12 | -| `src/scan.pas` | 535 | 459 | Symbols, literals, comments, positions | | |
| 13 | -| `src/sym.pas` | 508 | 422 | Types, objects, scopes, layout | | |
| 11 | +| `src/diag.pas` | 243 | 174 | Messages: positions, source excerpts, colour, counts | | |
| 12 | +| `src/scan.pas` | 584 | 495 | Symbols, literals, comments, positions | | |
| 13 | +| `src/sym.pas` | 510 | 424 | Types, objects, scopes, layout | | |
| 14 | 14 | | `src/x64.pas` | 680 | 546 | Code buffer, chunks, fixups, line notes, instruction encoder | |
| 15 | -| `src/gen.pas` | 1,414 | 1,240 | Items: loading, storing, copying, frames, calls | | |
| 16 | -| `src/parse.pas` | 1,816 | 1,685 | Declarations, statements, expressions, built-ins | | |
| 15 | +| `src/gen.pas` | 1,421 | 1,247 | Items: loading, storing, copying, frames, calls | | |
| 16 | +| `src/parse.pas` | 1,851 | 1,720 | Declarations, statements, expressions, built-ins | | |
| 17 | 17 | | `src/link.pas` | 131 | 95 | Tree shaking, layout, patching | |
| 18 | 18 | | `src/elf.pas` | 425 | 351 | Static and dynamic ELF, symbol table, line numbers | |
| 19 | 19 | | `src/raz.pas` | 219 | 172 | The command line, the entry points | |
| @@ -145,8 +145,12 @@ | ||
| 145 | 145 | Source is UTF-8, checked by `Utf8` wherever a byte above 127 appears: |
| 146 | 146 | in strings, characters and comments. Anywhere else it is an error. |
| 147 | 147 | |
| 148 | -`TokPos` is the position of the current symbol. Errors go through | |
| 149 | -`Mark`, which reports one there (`diag.Error`) and stops. There is no | |
| 148 | +`TokPos` is the position of the current symbol, `SpanFrom` the stretch | |
| 149 | +from a saved position to the end of the symbol before the current one, | |
| 150 | +and `MissingPos` the place to say a symbol is missing: just after the | |
| 151 | +symbol before, when the current one starts a new line. Errors go | |
| 152 | +through `Mark`, at the current symbol, or `MarkAt`, at a position; each | |
| 153 | +reports the error (`diag.Error`) and stops. There is no | |
| 150 | 154 | recovery: the first error ends the compilation. `SaveScan` and `RestoreScan` keep |
| 151 | 155 | the scanner's state while an imported module is compiled. |
| 152 | 156 | |
| @@ -224,6 +228,11 @@ | ||
| 224 | 228 | (`bSlot`); plus `off`; |
| 225 | 229 | - `mReg`: a value in `rax`; `mStack`: a value pushed on the stack; |
| 226 | 230 | - `mProc`, `mType`, `mStr`, and a few more the parser needs. |
| 231 | + | |
| 232 | +An item also carries `pos`, the stretch of source it came from, which | |
| 233 | +the parser sets as it reads an expression; an error about an item is | |
| 234 | +reported there (`MarkAt(x.pos, ...)`), and one about two operands | |
| 235 | +across both (`Join(x.pos, y.pos)`). | |
| 227 | 236 | |
| 228 | 237 | Three routines move items towards the machine. `Value` brings a value |
| 229 | 238 | into `rax`, loading it with the one instruction its size needs. |
| @@ -36,6 +36,7 @@ | ||
| 36 | 36 | function AddFile(const path: shortstring; buf: PChar; len: longint): longint; |
| 37 | 37 | function PathOf(f: longint): shortstring; |
| 38 | 38 | function LineOf(const p: TPos): longint; |
| 39 | +function Join(const p, q: TPos): TPos; | |
| 39 | 40 | procedure Error(const p: TPos; const msg: shortstring); |
| 40 | 41 | procedure Warning(const p: TPos; const msg: shortstring); |
| 41 | 42 | procedure Note(const p: TPos; const msg: shortstring); |
| @@ -58,14 +59,22 @@ | ||
| 58 | 59 | files: ^TFile; { numFiles of them, in room for cap } |
| 59 | 60 | numFiles, cap: longint; |
| 60 | 61 | colour, colourKnown: boolean; |
| 62 | + cwd: shortstring; { the working directory and a /, or '' if unknown } | |
| 61 | 63 | |
| 64 | +{ Paths are shown from the working directory where they are under it, | |
| 65 | + so messages read the same wherever the compiler or its library is. } | |
| 62 | 66 | function AddFile(const path: shortstring; buf: PChar; len: longint): longint; |
| 67 | +var d: array[0..255] of char; | |
| 63 | 68 | begin |
| 69 | + if numFiles = 0 then | |
| 70 | + if FpGetcwd(@d[0], SizeOf(d)) <> nil then cwd := StrPas(@d[0]) + '/'; | |
| 64 | 71 | if numFiles = cap then begin |
| 65 | 72 | cap := 2 * cap + 8; |
| 66 | 73 | ReallocMem(files, cap * SizeOf(TFile)); |
| 67 | 74 | end; |
| 68 | - files[numFiles].path := path; | |
| 75 | + if (cwd <> '') and (copy(path, 1, length(cwd)) = cwd) then | |
| 76 | + files[numFiles].path := copy(path, length(cwd) + 1, 255) | |
| 77 | + else files[numFiles].path := path; | |
| 69 | 78 | files[numFiles].buf := buf; |
| 70 | 79 | files[numFiles].len := len; |
| 71 | 80 | AddFile := numFiles; |
| @@ -167,6 +176,13 @@ | ||
| 167 | 176 | if p.b < stop then n := Chars(buf, p.a, p.b) else n := Chars(buf, p.a, stop); |
| 168 | 177 | if n < 1 then n := 1; |
| 169 | 178 | writeln(StdErr, Paint(kindColour, StringOfChar('^', n))); |
| 179 | +end; | |
| 180 | + | |
| 181 | +{ From the start of p to the end of q } | |
| 182 | +function Join(const p, q: TPos): TPos; | |
| 183 | +begin | |
| 184 | + Join := p; | |
| 185 | + Join.b := q.b; | |
| 170 | 186 | end; |
| 171 | 187 | |
| 172 | 188 | { Messages } |
| @@ -44,6 +44,7 @@ | ||
| 44 | 44 | vol: boolean; { mVar: reached through ^VOLATILE } |
| 45 | 45 | isVar: boolean; { mVar: a variable of the program, not a temporary } |
| 46 | 46 | obj: PObj; { mProc, mBuiltin, mCase } |
| 47 | + pos: TPos; { where it is in the source, for messages } | |
| 47 | 48 | end; |
| 48 | 49 | |
| 49 | 50 | TCall = record |
| @@ -147,8 +148,11 @@ | ||
| 147 | 148 | { Items } |
| 148 | 149 | |
| 149 | 150 | procedure MakeConst(var x: TItem; t: PType; v: int64); |
| 151 | +var p: TPos; | |
| 150 | 152 | begin |
| 153 | + p := x.pos; | |
| 151 | 154 | FillChar(x, SizeOf(x), 0); |
| 155 | + x.pos := p; | |
| 152 | 156 | x.mode := mConst; |
| 153 | 157 | x.typ := t; |
| 154 | 158 | x.val := v; |
| @@ -306,7 +310,7 @@ | ||
| 306 | 310 | case x.mode of |
| 307 | 311 | mConst: ConstTo(RAX, x); |
| 308 | 312 | mVar: begin |
| 309 | - if not IsScalar(x.typ) then Mark('not a single value'); | |
| 313 | + if not IsScalar(x.typ) then MarkAt(x.pos, 'not a single value'); | |
| 310 | 314 | m := MemOf(x, RAX); |
| 311 | 315 | Load(RAX, m, ScalarSize(x.typ), (x.typ^.form = fInt) and x.typ^.signed); |
| 312 | 316 | end; |
| @@ -314,11 +318,11 @@ | ||
| 314 | 318 | mStack: PopR(RAX); |
| 315 | 319 | mProc: begin |
| 316 | 320 | if x.obj^.isCode and (x.obj^.typ^.base <> nil) and x.obj^.typ^.base^.tuple then |
| 317 | - Mark('a code procedure with two results can only be called'); | |
| 321 | + MarkAt(x.pos, 'a code procedure with two results can only be called'); | |
| 318 | 322 | if x.obj^.ext then Load(RAX, MemRip(x.obj^.chunk, 0), 8, false) |
| 319 | 323 | else Lea(RAX, MemRip(x.obj^.chunk, 0)); |
| 320 | 324 | end; |
| 321 | - else Mark('not a value'); | |
| 325 | + else MarkAt(x.pos, 'not a value'); | |
| 322 | 326 | end; |
| 323 | 327 | x.mode := mReg; |
| 324 | 328 | end; |
| @@ -331,7 +335,7 @@ | ||
| 331 | 335 | m := MemOf(x, r); |
| 332 | 336 | if (x.base <> bReg) or (x.reg <> r) or (x.off <> 0) then Lea(r, m); |
| 333 | 337 | x.base := bReg; x.reg := r; x.off := 0; |
| 334 | - end else Mark('not a variable'); | |
| 338 | + end else MarkAt(x.pos, 'not a variable'); | |
| 335 | 339 | end; |
| 336 | 340 | |
| 337 | 341 | procedure Save(var x: TItem); |
| @@ -380,8 +384,11 @@ | ||
| 380 | 384 | end; |
| 381 | 385 | |
| 382 | 386 | procedure TempItem(var x: TItem; t: PType; off: int64); |
| 387 | +var p: TPos; | |
| 383 | 388 | begin |
| 389 | + p := x.pos; | |
| 384 | 390 | FillChar(x, SizeOf(x), 0); |
| 391 | + x.pos := p; | |
| 385 | 392 | x.mode := mVar; x.typ := t; x.base := bFrame; x.off := off; |
| 386 | 393 | end; |
| 387 | 394 | |
| @@ -405,7 +412,7 @@ | ||
| 405 | 412 | procedure CopyToTemp(var x: TItem); |
| 406 | 413 | var t: int64; |
| 407 | 414 | begin |
| 408 | - if x.vol then Mark('can''t copy through a volatile pointer'); | |
| 415 | + if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer'); | |
| 409 | 416 | t := AllocTemp(x.typ^.size, x.typ^.align); |
| 410 | 417 | Address(x, RSI); |
| 411 | 418 | Lea(RDI, Mem(RBP, t)); |
| @@ -442,14 +449,14 @@ | ||
| 442 | 449 | MovRI(RAX, 0); |
| 443 | 450 | RepStosb; |
| 444 | 451 | TempItem(x, t, tmp); |
| 445 | - end else Mark('can''t use a string as ' + TypeName(t)); | |
| 452 | + end else MarkAt(x.pos, 'can''t use a string as ' + TypeName(t)); | |
| 446 | 453 | exit; |
| 447 | 454 | end; |
| 448 | - if x.mode in [mType, mBuiltin, mNone, mCase] then Mark('not a value'); | |
| 455 | + if x.mode in [mType, mBuiltin, mNone, mCase] then MarkAt(x.pos, 'not a value'); | |
| 449 | 456 | if Same(s, t) then exit; |
| 450 | 457 | if (s = tRConst) and (t^.form = fReal) then RealTo(x, t) |
| 451 | 458 | else if (s^.form = fConst) and (t^.form = fInt) then begin |
| 452 | - if (x.mode = mConst) and not Fits(x.val, t) then Mark('constant doesn''t fit ' + TypeName(t)); | |
| 459 | + if (x.mode = mConst) and not Fits(x.val, t) then MarkAt(x.pos, 'constant doesn''t fit ' + TypeName(t)); | |
| 453 | 460 | x.typ := t; |
| 454 | 461 | end else if (s^.form = fNil) and (t^.form in [fPtr, fProc, fError]) then |
| 455 | 462 | x.typ := t |
| @@ -457,11 +464,11 @@ | ||
| 457 | 464 | and Same(s^.base, t^.base) then |
| 458 | 465 | x.typ := t |
| 459 | 466 | else if (s^.form = fArray) and (t^.form = fSlice) and Same(s^.base, t^.base) then begin |
| 460 | - if x.vol then Mark('can''t make a slice through a volatile pointer'); | |
| 467 | + if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer'); | |
| 461 | 468 | Address(x, RAX); |
| 462 | 469 | SliceOf(x, t, s^.len); |
| 463 | 470 | end else |
| 464 | - Mark('can''t use ' + TypeName(s) + ' as ' + TypeName(t)); | |
| 471 | + MarkAt(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t)); | |
| 465 | 472 | end; |
| 466 | 473 | |
| 467 | 474 | procedure Assign(var dst, src: TItem); |
| @@ -473,7 +480,7 @@ | ||
| 473 | 480 | m := MemOf(dst, RCX); |
| 474 | 481 | Store(m, RAX, ScalarSize(dst.typ)); |
| 475 | 482 | end else begin |
| 476 | - if dst.vol or src.vol then Mark('can''t copy through a volatile pointer'); | |
| 483 | + if dst.vol or src.vol then MarkAt(src.pos, 'can''t copy through a volatile pointer'); | |
| 477 | 484 | Address(src, RSI); |
| 478 | 485 | Address(dst, RDI); |
| 479 | 486 | Copy(dst.typ^.size); |
| @@ -508,8 +515,8 @@ | ||
| 508 | 515 | var t: PType; |
| 509 | 516 | begin |
| 510 | 517 | t := x.typ; |
| 511 | - if t^.form <> fPtr then Mark('not a pointer'); | |
| 512 | - if t^.base = nil then Mark('pointer to an undeclared type'); | |
| 518 | + if t^.form <> fPtr then MarkAt(x.pos, 'not a pointer'); | |
| 519 | + if t^.base = nil then MarkAt(x.pos, 'pointer to an undeclared type'); | |
| 513 | 520 | Value(x); |
| 514 | 521 | x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0; |
| 515 | 522 | x.typ := t^.base; x.vol := t^.vol; x.isVar := true; |
| @@ -525,12 +532,12 @@ | ||
| 525 | 532 | begin |
| 526 | 533 | if x.mode = mStr then Coerce(x, tBytes); |
| 527 | 534 | if (x.typ^.form = fPtr) and (x.typ^.base^.form = fArray) then |
| 528 | - Mark('a pointer to an array is indexed as p^[i]'); | |
| 535 | + MarkAt(x.pos, 'a pointer to an array is indexed as p^[i]'); | |
| 529 | 536 | if x.typ^.form = fPtr then begin |
| 530 | 537 | Value(x); PushRax; x.mode := mStack |
| 531 | 538 | end else if (x.mode = mVar) and (x.typ^.form in [fArray, fSlice]) then |
| 532 | 539 | Save(x) |
| 533 | - else Mark('not an array, slice or pointer'); | |
| 540 | + else MarkAt(x.pos, 'not an array, slice or pointer'); | |
| 534 | 541 | end; |
| 535 | 542 | |
| 536 | 543 | procedure Index(var x, y: TItem); |
| @@ -538,7 +545,7 @@ | ||
| 538 | 545 | begin |
| 539 | 546 | t := x.typ; |
| 540 | 547 | s := t^.base^.size; |
| 541 | - if not IsInt(y.typ) then Mark('an index is an integer'); | |
| 548 | + if not IsInt(y.typ) then MarkAt(y.pos, 'an index is an integer'); | |
| 542 | 549 | if t^.form = fPtr then begin |
| 543 | 550 | Value(y); |
| 544 | 551 | if s <> 1 then ImulI(RAX, s); |
| @@ -547,7 +554,7 @@ | ||
| 547 | 554 | x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0; |
| 548 | 555 | x.vol := t^.vol; x.isVar := true; |
| 549 | 556 | end else if (t^.form = fArray) and (y.mode = mConst) then begin |
| 550 | - if (y.val < 0) or (y.val >= t^.len) then Mark('index out of range'); | |
| 557 | + if (y.val < 0) or (y.val >= t^.len) then MarkAt(y.pos, 'index out of range'); | |
| 551 | 558 | x.off := x.off + y.val * s; |
| 552 | 559 | if x.base = bStack then begin |
| 553 | 560 | PopR(RAX); x.base := bReg; x.reg := RAX |
| @@ -576,7 +583,7 @@ | ||
| 576 | 583 | |
| 577 | 584 | procedure SliceLo(var lo: TItem); |
| 578 | 585 | begin |
| 579 | - if not IsInt(lo.typ) then Mark('an index is an integer'); | |
| 586 | + if not IsInt(lo.typ) then MarkAt(lo.pos, 'an index is an integer'); | |
| 580 | 587 | Value(lo); |
| 581 | 588 | PushRax; |
| 582 | 589 | end; |
| @@ -586,8 +593,8 @@ | ||
| 586 | 593 | begin |
| 587 | 594 | t := x.typ; |
| 588 | 595 | s := t^.base^.size; |
| 589 | - if not IsInt(hi.typ) then Mark('an index is an integer'); | |
| 590 | - if x.vol then Mark('can''t make a slice through a volatile pointer'); | |
| 596 | + if not IsInt(hi.typ) then MarkAt(hi.pos, 'an index is an integer'); | |
| 597 | + if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer'); | |
| 591 | 598 | Value(hi); |
| 592 | 599 | MovRR(RDX, RAX); |
| 593 | 600 | PopR(RCX); |
| @@ -630,7 +637,7 @@ | ||
| 630 | 637 | end else if IsInt(x.typ) then begin |
| 631 | 638 | if x.mode = mConst then x.val := Cut(-x.val, x.typ) |
| 632 | 639 | else begin Value(x); Unary(3, RAX); Norm(x.typ) end; |
| 633 | - end else Mark('can''t negate ' + TypeName(x.typ)); | |
| 640 | + end else MarkAt(x.pos, 'can''t negate ' + TypeName(x.typ)); | |
| 634 | 641 | end; |
| 635 | 642 | |
| 636 | 643 | procedure NotOp(var x: TItem); |
| @@ -641,7 +648,7 @@ | ||
| 641 | 648 | end else if IsInt(x.typ) then begin |
| 642 | 649 | if x.mode = mConst then x.val := Cut(not x.val, x.typ) |
| 643 | 650 | else begin Value(x); Unary(2, RAX); Norm(x.typ) end; |
| 644 | - end else Mark('not needs BOOL or an integer'); | |
| 651 | + end else MarkAt(x.pos, 'not needs BOOL or an integer'); | |
| 645 | 652 | end; |
| 646 | 653 | |
| 647 | 654 | function IsStrLike(t: PType): boolean; |
| @@ -660,7 +667,7 @@ | ||
| 660 | 667 | end else begin |
| 661 | 668 | if x.mode = mStr then begin Address(x, RAX); SliceOf(x, t, x.val) end |
| 662 | 669 | else begin |
| 663 | - if x.vol then Mark('can''t compare through a volatile pointer'); | |
| 670 | + if x.vol then MarkAt(x.pos, 'can''t compare through a volatile pointer'); | |
| 664 | 671 | Address(x, RAX); SliceOf(x, t, x.typ^.len) |
| 665 | 672 | end; |
| 666 | 673 | end; |
| @@ -679,7 +686,7 @@ | ||
| 679 | 686 | end else if (op in [sEql, sNeq]) and IsStrLike(x.typ) then |
| 680 | 687 | StrSlice(x) |
| 681 | 688 | else if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then |
| 682 | - Mark('not a value') | |
| 689 | + MarkAt(x.pos, 'not a value') | |
| 683 | 690 | else if x.mode <> mConst then begin |
| 684 | 691 | Value(x); PushRax; x.mode := mStack |
| 685 | 692 | end; |
| @@ -694,7 +701,7 @@ | ||
| 694 | 701 | Log2 := n; |
| 695 | 702 | end; |
| 696 | 703 | |
| 697 | -function FoldInt(op: TSym; a, b: int64; t: PType): int64; | |
| 704 | +function FoldInt(op: TSym; a, b: int64; t: PType; const p: TPos): int64; | |
| 698 | 705 | var u: boolean; |
| 699 | 706 | begin |
| 700 | 707 | u := (t^.form = fInt) and not t^.signed; |
| @@ -703,11 +710,11 @@ | ||
| 703 | 710 | sMinus: FoldInt := a - b; |
| 704 | 711 | sTimes: FoldInt := a * b; |
| 705 | 712 | sDiv, sMod: begin |
| 706 | - if b = 0 then Mark('division by zero'); | |
| 713 | + if b = 0 then MarkAt(p, 'division by zero'); | |
| 707 | 714 | if u then begin |
| 708 | 715 | if op = sDiv then FoldInt := int64(qword(a) div qword(b)) |
| 709 | 716 | else FoldInt := int64(qword(a) mod qword(b)); |
| 710 | - end else if (b = -1) and (a = low(int64)) then Mark('division overflows') | |
| 717 | + end else if (b = -1) and (a = low(int64)) then MarkAt(p, 'division overflows') | |
| 711 | 718 | else if op = sDiv then FoldInt := a div b |
| 712 | 719 | else FoldInt := a mod b; |
| 713 | 720 | end; |
| @@ -723,7 +730,7 @@ | ||
| 723 | 730 | sLeq: if u then FoldInt := ord(qword(a) <= qword(b)) else FoldInt := ord(a <= b); |
| 724 | 731 | sGtr: if u then FoldInt := ord(qword(a) > qword(b)) else FoldInt := ord(a > b); |
| 725 | 732 | sGeq: if u then FoldInt := ord(qword(a) >= qword(b)) else FoldInt := ord(a >= b); |
| 726 | - else Mark('bad operator'); FoldInt := 0; | |
| 733 | + else MarkAt(p, 'bad operator'); FoldInt := 0; | |
| 727 | 734 | end; |
| 728 | 735 | end; |
| 729 | 736 | |
| @@ -759,10 +766,10 @@ | ||
| 759 | 766 | xt, yt, t: PType; r: TItem; scale, sh: longint; isPtr, unsign, f: boolean; a, b: int64; |
| 760 | 767 | begin |
| 761 | 768 | xt := x.typ; yt := y.typ; |
| 762 | - if y.mode in [mType, mBuiltin, mNone, mCase] then Mark('not a value'); | |
| 769 | + if y.mode in [mType, mBuiltin, mNone, mCase] then MarkAt(y.pos, 'not a value'); | |
| 763 | 770 | |
| 764 | 771 | if (op in [sAnd, sOr]) and (xt^.form = fBool) then begin |
| 765 | - if yt^.form <> fBool then Mark('and, or need two BOOLs'); | |
| 772 | + if yt^.form <> fBool then MarkAt(y.pos, 'and, or need two BOOLs'); | |
| 766 | 773 | if (x.mode = mConst) and (y.mode = mConst) then begin |
| 767 | 774 | FixLink(L); |
| 768 | 775 | if op = sAnd then x.val := x.val and y.val else x.val := x.val or y.val; |
| @@ -775,7 +782,7 @@ | ||
| 775 | 782 | end; |
| 776 | 783 | |
| 777 | 784 | if (op in [sEql, sNeq]) and IsStrLike(xt) then begin |
| 778 | - if not IsStrLike(yt) then Mark('can''t compare a string with ' + TypeName(yt)); | |
| 785 | + if not IsStrLike(yt) then MarkAt(y.pos, 'can''t compare a string with ' + TypeName(yt)); | |
| 779 | 786 | StrSlice(y); |
| 780 | 787 | Address(y, RSI); |
| 781 | 788 | Address(x, RDI); |
| @@ -792,58 +799,58 @@ | ||
| 792 | 799 | { the type of the result, and the checks } |
| 793 | 800 | t := nil; scale := 1; isPtr := false; |
| 794 | 801 | if IsInt(xt) and IsInt(yt) then begin |
| 795 | - if op = sSlash then Mark('/ is for reals; integers use div'); | |
| 802 | + if op = sSlash then MarkAt(Join(x.pos, y.pos), '/ is for reals; integers use div'); | |
| 796 | 803 | if op in [sShl, sShr] then begin |
| 797 | 804 | if xt^.form = fConst then t := tConst else t := xt |
| 798 | 805 | end else if (xt^.form = fConst) and (yt^.form = fConst) then t := tConst |
| 799 | 806 | else if xt^.form = fConst then begin |
| 800 | - if (x.mode = mConst) and not Fits(x.val, yt) then Mark('constant doesn''t fit ' + TypeName(yt)); | |
| 807 | + if (x.mode = mConst) and not Fits(x.val, yt) then MarkAt(x.pos, 'constant doesn''t fit ' + TypeName(yt)); | |
| 801 | 808 | t := yt |
| 802 | 809 | end else if yt^.form = fConst then begin |
| 803 | - if (y.mode = mConst) and not Fits(y.val, xt) then Mark('constant doesn''t fit ' + TypeName(xt)); | |
| 810 | + if (y.mode = mConst) and not Fits(y.val, xt) then MarkAt(y.pos, 'constant doesn''t fit ' + TypeName(xt)); | |
| 804 | 811 | t := xt |
| 805 | 812 | end else if Same(xt, yt) then t := xt |
| 806 | - else Mark('different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); | |
| 813 | + else MarkAt(Join(x.pos, y.pos), 'different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); | |
| 807 | 814 | end else if (xt^.form = fReal) and (yt^.form = fReal) then begin |
| 808 | - if not (op in Rel + [sPlus, sMinus, sTimes, sSlash]) then Mark('not a real operator'); | |
| 815 | + if not (op in Rel + [sPlus, sMinus, sTimes, sSlash]) then MarkAt(Join(x.pos, y.pos), 'not a real operator'); | |
| 809 | 816 | if xt = tRConst then t := yt |
| 810 | 817 | else if (yt = tRConst) or Same(xt, yt) then t := xt |
| 811 | - else Mark('different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); | |
| 818 | + else MarkAt(Join(x.pos, y.pos), 'different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); | |
| 812 | 819 | if (x.mode = mConst) and (x.typ <> t) then RealTo(x, t); |
| 813 | 820 | if (y.mode = mConst) and (y.typ <> t) then RealTo(y, t); |
| 814 | 821 | end else if (xt^.form = fBool) and (yt^.form = fBool) then begin |
| 815 | - if not (op in [sXor, sEql, sNeq]) then Mark('not a BOOL operator'); | |
| 822 | + if not (op in [sXor, sEql, sNeq]) then MarkAt(Join(x.pos, y.pos), 'not a BOOL operator'); | |
| 816 | 823 | t := tBool; |
| 817 | 824 | end else if (xt^.form = fPtr) and IsInt(yt) and (op in [sPlus, sMinus]) then begin |
| 818 | 825 | t := xt; scale := xt^.base^.size; isPtr := true; |
| 819 | 826 | if y.mode = mConst then y.typ := tI64; |
| 820 | 827 | end else if (xt^.form = fPtr) and (yt^.form = fPtr) and (op = sMinus) then begin |
| 821 | - if not Same(xt, yt) then Mark('different pointer types'); | |
| 828 | + if not Same(xt, yt) then MarkAt(Join(x.pos, y.pos), 'different pointer types'); | |
| 822 | 829 | t := tI64; scale := xt^.base^.size; isPtr := true; |
| 823 | 830 | end else if (xt^.form in [fPtr, fProc, fNil, fError]) and (yt^.form in [fPtr, fProc, fNil, fError]) then begin |
| 824 | - if not (op in Rel) then Mark('not a pointer operator'); | |
| 831 | + if not (op in Rel) then MarkAt(Join(x.pos, y.pos), 'not a pointer operator'); | |
| 825 | 832 | if (xt^.form in [fProc, fError]) or (yt^.form in [fProc, fError]) then |
| 826 | - if not (op in [sEql, sNeq]) then Mark('procedures and errors compare only with = and #'); | |
| 833 | + if not (op in [sEql, sNeq]) then MarkAt(Join(x.pos, y.pos), 'procedures and errors compare only with = and #'); | |
| 827 | 834 | if (xt^.form <> fNil) and (yt^.form <> fNil) and not Same(xt, yt) then |
| 828 | 835 | if not ((xt^.form = fPtr) and (yt^.form = fPtr) and Same(xt^.base, yt^.base)) then |
| 829 | - Mark('different pointer types'); | |
| 836 | + MarkAt(Join(x.pos, y.pos), 'different pointer types'); | |
| 830 | 837 | t := tU64; |
| 831 | 838 | end else if (xt^.form = fEnum) and Same(xt, yt) then begin |
| 832 | - if not (op in Rel) then Mark('enumerations only compare'); | |
| 839 | + if not (op in Rel) then MarkAt(Join(x.pos, y.pos), 'enumerations only compare'); | |
| 833 | 840 | t := xt; |
| 834 | 841 | end else if (xt^.form = fSet) and Same(xt, yt) then begin |
| 835 | - if not (op in [sPlus, sTimes, sMinus, sEql, sNeq, sLeq, sGeq]) then Mark('not a set operator'); | |
| 842 | + if not (op in [sPlus, sTimes, sMinus, sEql, sNeq, sLeq, sGeq]) then MarkAt(Join(x.pos, y.pos), 'not a set operator'); | |
| 836 | 843 | t := xt; |
| 837 | 844 | end else if (op = sIn) and (yt^.form = fSet) and Same(xt, yt^.base) then |
| 838 | 845 | t := yt |
| 839 | 846 | else |
| 840 | - Mark('can''t combine ' + TypeName(xt) + ' and ' + TypeName(yt)); | |
| 847 | + MarkAt(Join(x.pos, y.pos), 'can''t combine ' + TypeName(xt) + ' and ' + TypeName(yt)); | |
| 841 | 848 | unsign := (t^.form = fInt) and not t^.signed; |
| 842 | 849 | |
| 843 | 850 | { constants } |
| 844 | 851 | if (x.mode = mConst) and (y.mode = mConst) and not isPtr then begin |
| 845 | 852 | if t^.form = fReal then begin |
| 846 | - if not FoldReal(op, x, y, t, r) then Mark('not a real operator'); | |
| 853 | + if not FoldReal(op, x, y, t, r) then MarkAt(Join(x.pos, y.pos), 'not a real operator'); | |
| 847 | 854 | x := r; |
| 848 | 855 | end else if t^.form = fSet then begin |
| 849 | 856 | a := x.val; b := y.val; |
| @@ -857,9 +864,9 @@ | ||
| 857 | 864 | else MakeConst(x, tBool, ord((a = b) = (op = sEql))); |
| 858 | 865 | end; |
| 859 | 866 | end else if op in Rel then |
| 860 | - MakeConst(x, tBool, FoldInt(op, x.val, y.val, t)) | |
| 867 | + MakeConst(x, tBool, FoldInt(op, x.val, y.val, t, Join(x.pos, y.pos))) | |
| 861 | 868 | else |
| 862 | - MakeConst(x, t, Cut(FoldInt(op, x.val, y.val, t), t)); | |
| 869 | + MakeConst(x, t, Cut(FoldInt(op, x.val, y.val, t, Join(x.pos, y.pos)), t)); | |
| 863 | 870 | exit; |
| 864 | 871 | end; |
| 865 | 872 | |
| @@ -935,7 +942,7 @@ | ||
| 935 | 942 | sXor: Alu(aluXor, RAX, RCX); |
| 936 | 943 | sShl: Shift(shShl, RAX); |
| 937 | 944 | sShr: if unsign then Shift(shShr, RAX) else Shift(shSar, RAX); |
| 938 | - else Mark('not an operator for ' + TypeName(t)); | |
| 945 | + else MarkAt(Join(x.pos, y.pos), 'not an operator for ' + TypeName(t)); | |
| 939 | 946 | end; |
| 940 | 947 | Norm(t); |
| 941 | 948 | end; |
| @@ -947,14 +954,14 @@ | ||
| 947 | 954 | var s: PType; r: double; L1, L2: longint; f: boolean; |
| 948 | 955 | begin |
| 949 | 956 | s := x.typ; |
| 950 | - if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then Mark('can''t convert this'); | |
| 957 | + if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then MarkAt(x.pos, 'can''t convert this'); | |
| 951 | 958 | if Same(s, t) then exit; |
| 952 | 959 | if (IsInt(s) or (s^.form in [fEnum, fSet])) and (t^.form = fInt) then begin |
| 953 | 960 | if x.mode = mConst then x.val := Cut(x.val, t) |
| 954 | 961 | else begin Value(x); Norm(t) end; |
| 955 | 962 | end else if IsInt(s) and (t^.form = fEnum) then begin |
| 956 | 963 | if x.mode = mConst then begin |
| 957 | - if (x.val < 0) or (x.val >= t^.len) then Mark('not a position of ' + TypeName(t)) | |
| 964 | + if (x.val < 0) or (x.val >= t^.len) then MarkAt(x.pos, 'not a position of ' + TypeName(t)) | |
| 958 | 965 | end else begin Value(x); CmpI(RAX, t^.len); Check(ccB) end; |
| 959 | 966 | end else if IsInt(s) and (t^.form = fSet) then begin |
| 960 | 967 | if x.mode = mConst then begin |
| @@ -1009,7 +1016,7 @@ | ||
| 1009 | 1016 | end else if (s^.form in [fPtr, fProc]) and (t^.form = fInt) then begin |
| 1010 | 1017 | Value(x); Norm(t) |
| 1011 | 1018 | end else |
| 1012 | - Mark('can''t convert ' + TypeName(s) + ' to ' + TypeName(t)); | |
| 1019 | + MarkAt(x.pos, 'can''t convert ' + TypeName(s) + ' to ' + TypeName(t)); | |
| 1013 | 1020 | x.typ := t; |
| 1014 | 1021 | end; |
| 1015 | 1022 | |
| @@ -1022,7 +1029,7 @@ | ||
| 1022 | 1029 | c.code := x.obj^.isCode; c.ext := x.obj^.ext; |
| 1023 | 1030 | end else begin |
| 1024 | 1031 | c.code := false; c.ext := false; |
| 1025 | - if x.typ^.form <> fProc then Mark('not a procedure'); | |
| 1032 | + if x.typ^.form <> fProc then MarkAt(x.pos, 'not a procedure'); | |
| 1026 | 1033 | c.sig := x.typ; c.chunk := -1; |
| 1027 | 1034 | c.target := ToSlot(x); |
| 1028 | 1035 | end; |
| @@ -1034,17 +1041,17 @@ | ||
| 1034 | 1041 | var p: PObj; s: int64; |
| 1035 | 1042 | begin |
| 1036 | 1043 | p := c.param; |
| 1037 | - if c.n > High(c.slots) then Mark('too many arguments'); | |
| 1044 | + if c.n > High(c.slots) then MarkAt(a.pos, 'too many arguments'); | |
| 1038 | 1045 | if p = nil then begin |
| 1039 | 1046 | { past the parameters of a C procedure that ends in ...: a string |
| 1040 | 1047 | goes as a C string, an integer constant as an I64, a real |
| 1041 | 1048 | constant as an F64; C takes no F32 there } |
| 1042 | - if not c.sig^.variadic then Mark('too many arguments'); | |
| 1049 | + if not c.sig^.variadic then MarkAt(a.pos, 'too many arguments'); | |
| 1043 | 1050 | if a.mode = mStr then Coerce(a, tPtrU8) |
| 1044 | 1051 | else if a.typ^.form = fConst then Coerce(a, tI64) |
| 1045 | 1052 | else if a.typ = tRConst then Coerce(a, tReal) |
| 1046 | - else if IsF32(a.typ) then Mark('an F32 goes to ... as F64(x)') | |
| 1047 | - else if not IsScalar(a.typ) then Mark('only a single value goes to ...'); | |
| 1053 | + else if IsF32(a.typ) then MarkAt(a.pos, 'an F32 goes to ... as F64(x)') | |
| 1054 | + else if not IsScalar(a.typ) then MarkAt(a.pos, 'only a single value goes to ...'); | |
| 1048 | 1055 | c.isF[c.n] := a.typ^.form = fReal; |
| 1049 | 1056 | c.slots[c.n] := ToSlot(a); |
| 1050 | 1057 | inc(c.n); |
| @@ -1052,9 +1059,9 @@ | ||
| 1052 | 1059 | end; |
| 1053 | 1060 | c.isF[c.n] := (p^.typ^.form = fReal) and not p^.isVar; |
| 1054 | 1061 | if p^.isVar then begin |
| 1055 | - if (a.mode <> mVar) or not a.isVar then Mark('a var parameter needs a variable'); | |
| 1056 | - if not Same(a.typ, p^.typ) then Mark('a var parameter needs exactly ' + TypeName(p^.typ)); | |
| 1057 | - if a.vol then Mark('can''t pass through a volatile pointer to a var parameter'); | |
| 1062 | + if (a.mode <> mVar) or not a.isVar then MarkAt(a.pos, 'a var parameter needs a variable'); | |
| 1063 | + if not Same(a.typ, p^.typ) then MarkAt(a.pos, 'a var parameter needs exactly ' + TypeName(p^.typ)); | |
| 1064 | + if a.vol then MarkAt(a.pos, 'can''t pass through a volatile pointer to a var parameter'); | |
| 1058 | 1065 | Address(a, RAX); |
| 1059 | 1066 | s := AllocTemp(8, 8); |
| 1060 | 1067 | Store(Mem(RBP, s), RAX, 8); |
| @@ -1161,7 +1168,7 @@ | ||
| 1161 | 1168 | Value(a); |
| 1162 | 1169 | Store(Mem(RBP, x.off + f^.val), RAX, ScalarSize(f^.typ)); |
| 1163 | 1170 | end else begin |
| 1164 | - if a.vol then Mark('can''t copy through a volatile pointer'); | |
| 1171 | + if a.vol then MarkAt(a.pos, 'can''t copy through a volatile pointer'); | |
| 1165 | 1172 | Address(a, RSI); |
| 1166 | 1173 | Lea(RDI, Mem(RBP, x.off + f^.val)); |
| 1167 | 1174 | Copy(f^.typ^.size); |
| @@ -1173,7 +1180,7 @@ | ||
| 1173 | 1180 | var p: int64; |
| 1174 | 1181 | begin |
| 1175 | 1182 | if x.typ^.form = fEnum then exit(ToSlot(x)); |
| 1176 | - if (x.mode <> mVar) or (x.typ^.form <> fVariant) then Mark('match needs a variant or an enumeration'); | |
| 1183 | + if (x.mode <> mVar) or (x.typ^.form <> fVariant) then MarkAt(x.pos, 'match needs a variant or an enumeration'); | |
| 1177 | 1184 | Address(x, RAX); |
| 1178 | 1185 | p := AllocTemp(8, 8); |
| 1179 | 1186 | Store(Mem(RBP, p), RAX, 8); |
| @@ -1218,7 +1225,7 @@ | ||
| 1218 | 1225 | |
| 1219 | 1226 | procedure CondJump(var x: TItem; var L: longint); |
| 1220 | 1227 | begin |
| 1221 | - if x.typ^.form <> fBool then Mark('a condition is a BOOL'); | |
| 1228 | + if x.typ^.form <> fBool then MarkAt(x.pos, 'a condition is a BOOL'); | |
| 1222 | 1229 | Value(x); |
| 1223 | 1230 | TestRR(RAX, RAX); |
| 1224 | 1231 | Jcc(ccE, L); |
| @@ -1283,10 +1290,10 @@ | ||
| 1283 | 1290 | |
| 1284 | 1291 | procedure ReturnValue(var x: TItem); |
| 1285 | 1292 | begin |
| 1286 | - if result = nil then Mark('this procedure returns nothing'); | |
| 1293 | + if result = nil then MarkAt(x.pos, 'this procedure returns nothing'); | |
| 1287 | 1294 | Coerce(x, result); |
| 1288 | 1295 | if IsAggregate(result) then begin |
| 1289 | - if x.vol then Mark('can''t copy through a volatile pointer'); | |
| 1296 | + if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer'); | |
| 1290 | 1297 | Address(x, RSI); |
| 1291 | 1298 | Load(RDI, Mem(RBP, retSlot), 8, false); |
| 1292 | 1299 | Copy(result^.size); |
| @@ -1303,7 +1310,7 @@ | ||
| 1303 | 1310 | Load(RCX, Mem(RBP, retSlot), 8, false); |
| 1304 | 1311 | Store(Mem(RCX, f^.val), RAX, ScalarSize(f^.typ)); |
| 1305 | 1312 | end else begin |
| 1306 | - if x.vol then Mark('can''t copy through a volatile pointer'); | |
| 1313 | + if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer'); | |
| 1307 | 1314 | Address(x, RSI); |
| 1308 | 1315 | Load(RDI, Mem(RBP, retSlot), 8, false); |
| 1309 | 1316 | Lea(RDI, Mem(RDI, f^.val)); |
| @@ -1350,7 +1357,7 @@ | ||
| 1350 | 1357 | function ErrorChunk(var x: TItem; module, name: longint): longint; |
| 1351 | 1358 | var c: longint; p: PBytes; |
| 1352 | 1359 | begin |
| 1353 | - if x.mode <> mStr then Mark('an error is made from a string'); | |
| 1360 | + if x.mode <> mStr then MarkAt(x.pos, 'an error is made from a string'); | |
| 1354 | 1361 | p := GetMem(x.val + 8); |
| 1355 | 1362 | PInt64(p)^ := x.val; |
| 1356 | 1363 | Move(rodata^[chunks^[x.chunk].start], p^[8], x.val); |
| @@ -74,7 +74,7 @@ | ||
| 74 | 74 | |
| 75 | 75 | procedure Expect(s: TSym; const what: shortstring); |
| 76 | 76 | begin |
| 77 | - if tok <> s then Mark(what + ' expected'); | |
| 77 | + if tok <> s then MarkAt(MissingPos, what + ' expected'); | |
| 78 | 78 | Next; |
| 79 | 79 | end; |
| 80 | 80 | |
| @@ -85,7 +85,7 @@ | ||
| 85 | 85 | |
| 86 | 86 | procedure IdentDef(var n: longint; var exp: boolean); |
| 87 | 87 | begin |
| 88 | - if tok <> sIdent then Mark('name expected'); | |
| 88 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 89 | 89 | n := id; |
| 90 | 90 | Next; |
| 91 | 91 | exp := false; |
| @@ -109,7 +109,7 @@ | ||
| 109 | 109 | |
| 110 | 110 | function ConstValue(var x: TItem): int64; |
| 111 | 111 | begin |
| 112 | - if x.mode <> mConst then Mark('constant expected'); | |
| 112 | + if x.mode <> mConst then MarkAt(x.pos, 'constant expected'); | |
| 113 | 113 | ConstValue := x.val; |
| 114 | 114 | end; |
| 115 | 115 | |
| @@ -117,20 +117,20 @@ | ||
| 117 | 117 | var x: TItem; |
| 118 | 118 | begin |
| 119 | 119 | Expression(x, nil); |
| 120 | - if not IsInt(x.typ) then Mark('integer constant expected'); | |
| 120 | + if not IsInt(x.typ) then MarkAt(x.pos, 'integer constant expected'); | |
| 121 | 121 | ConstExpr := ConstValue(x); |
| 122 | 122 | end; |
| 123 | 123 | |
| 124 | 124 | function QualIdent: PObj; |
| 125 | 125 | var o: PObj; |
| 126 | 126 | begin |
| 127 | - if tok <> sIdent then Mark('name expected'); | |
| 127 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 128 | 128 | o := Lookup(id); |
| 129 | 129 | if o = nil then Mark(NameOf(id) + ' isn''t declared'); |
| 130 | 130 | Next; |
| 131 | 131 | if o^.cls = oModule then begin |
| 132 | 132 | Expect(sPeriod, '.'); |
| 133 | - if tok <> sIdent then Mark('name expected'); | |
| 133 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 134 | 134 | o := Find(o^.module^.scope, id); |
| 135 | 135 | if (o = nil) or not o^.exported then Mark(NameOf(id) + ' isn''t exported'); |
| 136 | 136 | Next; |
| @@ -211,7 +211,7 @@ | ||
| 211 | 211 | repeat |
| 212 | 212 | n := 0; |
| 213 | 213 | repeat |
| 214 | - if tok <> sIdent then Mark('name expected'); | |
| 214 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 215 | 215 | f := NewObj(oField, id, nil); |
| 216 | 216 | f^.exported := true; |
| 217 | 217 | if lastF = nil then c^.fields := f else lastF^.next := f; |
| @@ -293,7 +293,7 @@ | ||
| 293 | 293 | if isVar then Next; |
| 294 | 294 | first := nil; |
| 295 | 295 | repeat |
| 296 | - if tok <> sIdent then Mark('name expected'); | |
| 296 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 297 | 297 | p := NewObj(oVar, id, nil); |
| 298 | 298 | p^.isVar := isVar; |
| 299 | 299 | p^.lev := 1; |
| @@ -322,13 +322,14 @@ | ||
| 322 | 322 | end; |
| 323 | 323 | |
| 324 | 324 | function EnumType: PType; |
| 325 | -var t: PType; o, last: PObj; | |
| 325 | +var t: PType; o, last: PObj; start: TPos; | |
| 326 | 326 | begin |
| 327 | + start := TokPos; | |
| 327 | 328 | t := NewType(fEnum, 1, 1); |
| 328 | 329 | last := nil; |
| 329 | 330 | repeat |
| 330 | 331 | Next; |
| 331 | - if tok <> sIdent then Mark('name expected'); | |
| 332 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 332 | 333 | o := NewObj(oConst, id, t); |
| 333 | 334 | o^.val := t^.len; |
| 334 | 335 | o^.exported := declExported; |
| @@ -339,14 +340,14 @@ | ||
| 339 | 340 | Next; |
| 340 | 341 | until tok <> sComma; |
| 341 | 342 | Expect(sRparen, ')'); |
| 342 | - if t^.len > 256 then Mark('more than 256 names'); | |
| 343 | + if t^.len > 256 then MarkAt(SpanFrom(start), 'more than 256 names'); | |
| 343 | 344 | EnumType := t; |
| 344 | 345 | end; |
| 345 | 346 | |
| 346 | -function SetOf(e: PType): PType; | |
| 347 | +function SetOf(e: PType; const at: TPos): PType; | |
| 347 | 348 | var t: PType; |
| 348 | 349 | begin |
| 349 | - if (e^.form <> fEnum) or (e^.len > 64) then Mark('a set is of an enumeration of at most 64 names'); | |
| 350 | + if (e^.form <> fEnum) or (e^.len > 64) then MarkAt(at, 'a set is of an enumeration of at most 64 names'); | |
| 350 | 351 | t := NewType(fSet, 8, 8); |
| 351 | 352 | if e^.len <= 8 then t^.size := 1 |
| 352 | 353 | else if e^.len <= 16 then t^.size := 2 |
| @@ -358,12 +359,13 @@ | ||
| 358 | 359 | end; |
| 359 | 360 | |
| 360 | 361 | function ParseType: PType; |
| 361 | -var t: PType; o: PObj; n: int64; vol: boolean; | |
| 362 | +var t: PType; o: PObj; n: int64; vol: boolean; start: TPos; | |
| 362 | 363 | begin |
| 364 | + start := TokPos; | |
| 363 | 365 | case tok of |
| 364 | 366 | sIdent: begin |
| 365 | 367 | o := QualIdent; |
| 366 | - if o^.cls <> oType then Mark('type expected'); | |
| 368 | + if o^.cls <> oType then MarkAt(SpanFrom(start), 'type expected'); | |
| 367 | 369 | t := o^.typ; |
| 368 | 370 | end; |
| 369 | 371 | sLbrak: begin |
| @@ -373,8 +375,9 @@ | ||
| 373 | 375 | t := NewType(fSlice, 16, 8); |
| 374 | 376 | t^.base := ParseType(); |
| 375 | 377 | end else begin |
| 378 | + start := TokPos; | |
| 376 | 379 | n := ConstExpr; |
| 377 | - if (n <= 0) or (n > (int64(1) shl 40)) then Mark('bad array length'); | |
| 380 | + if (n <= 0) or (n > (int64(1) shl 40)) then MarkAt(SpanFrom(start), 'bad array length'); | |
| 378 | 381 | Expect(sRbrak, ']'); |
| 379 | 382 | t := NewType(fArray, 0, 1); |
| 380 | 383 | t^.len := n; |
| @@ -405,9 +408,10 @@ | ||
| 405 | 408 | sSet: begin |
| 406 | 409 | Next; |
| 407 | 410 | Expect(sOf, 'of'); |
| 408 | - t := SetOf(ParseType()); | |
| 411 | + start := TokPos; | |
| 412 | + t := SetOf(ParseType(), start); | |
| 409 | 413 | end; |
| 410 | - else Mark('type expected'); | |
| 414 | + else MarkAt(MissingPos, 'type expected'); | |
| 411 | 415 | end; |
| 412 | 416 | ParseType := t; |
| 413 | 417 | end; |
| @@ -437,7 +441,7 @@ | ||
| 437 | 441 | for i := 0 to n - 1 do begin |
| 438 | 442 | if i > 0 then Expect(sComma, ','); |
| 439 | 443 | Expression(a, nil); |
| 440 | - if not (IsScalar(a.typ) and (a.typ^.form <> fReal)) then Mark('integer or pointer expected'); | |
| 444 | + if not (IsScalar(a.typ) and (a.typ^.form <> fReal)) then MarkAt(a.pos, 'integer or pointer expected'); | |
| 441 | 445 | if a.typ^.form = fConst then Coerce(a, tI64); |
| 442 | 446 | slots[i] := ToSlot(a); |
| 443 | 447 | end; |
| @@ -447,10 +451,10 @@ | ||
| 447 | 451 | var p, a: TItem; t: PType; s: array[0..2] of int64; i, n: longint; |
| 448 | 452 | begin |
| 449 | 453 | Expression(p, nil); |
| 450 | - if p.typ^.form <> fPtr then Mark('a pointer expected'); | |
| 454 | + if p.typ^.form <> fPtr then MarkAt(p.pos, 'a pointer expected'); | |
| 451 | 455 | t := p.typ^.base; |
| 452 | 456 | if not (((t^.form = fInt) or ((t^.form = fPtr) and (which <> bXadd))) and (t^.size = 8)) then |
| 453 | - Mark('an 8-byte integer or pointer expected'); | |
| 457 | + MarkAt(p.pos, 'an 8-byte integer or pointer expected'); | |
| 454 | 458 | s[0] := ToSlot(p); |
| 455 | 459 | if which = bCas then n := 2 else n := 1; |
| 456 | 460 | for i := 1 to n do begin |
| @@ -481,14 +485,14 @@ | ||
| 481 | 485 | var y, z: TItem; t: PType; f: PObj; s: int64; c: TCall; L: longint; |
| 482 | 486 | begin |
| 483 | 487 | Expression(x, nil); |
| 484 | - if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then Mark('NEW needs a pointer variable'); | |
| 488 | + if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then MarkAt(x.pos, 'NEW needs a pointer variable'); | |
| 485 | 489 | t := x.typ^.base; |
| 486 | 490 | Save(x); |
| 487 | 491 | Expect(sComma, ','); |
| 488 | 492 | Expression(y, nil); |
| 489 | 493 | if (y.typ^.form <> fPtr) or (y.typ^.base^.obj = nil) or (y.typ^.base^.obj^.module = nil) |
| 490 | 494 | or (NameOf(y.typ^.base^.obj^.name) <> 'Allocator') |
| 491 | - or (NameOf(y.typ^.base^.obj^.module^.name) <> 'Mem') then Mark('NEW needs a ^Mem.Allocator'); | |
| 495 | + or (NameOf(y.typ^.base^.obj^.module^.name) <> 'Mem') then MarkAt(y.pos, 'NEW needs a ^Mem.Allocator'); | |
| 492 | 496 | f := Find(y.typ^.base^.scope, Name('alloc')); |
| 493 | 497 | s := ToSlot(y); |
| 494 | 498 | Load(RAX, Mem(RBP, s), 8, false); |
| @@ -543,7 +547,7 @@ | ||
| 543 | 547 | end; |
| 544 | 548 | bAdr: begin |
| 545 | 549 | Expression(y, nil); |
| 546 | - if (y.mode <> mVar) or not y.isVar then Mark('ADR needs a variable'); | |
| 550 | + if (y.mode <> mVar) or not y.isVar then MarkAt(y.pos, 'ADR needs a variable'); | |
| 547 | 551 | t := NewPtr(y.typ, y.vol); |
| 548 | 552 | Address(y, RAX); |
| 549 | 553 | MakeConst(x, t, 0); |
| @@ -558,7 +562,7 @@ | ||
| 558 | 562 | Load(RAX, Mem(RAX, 8), 8, false); |
| 559 | 563 | MakeConst(x, tI64, 0); |
| 560 | 564 | x.mode := mReg; |
| 561 | - end else Mark('LEN needs an array or slice'); | |
| 565 | + end else MarkAt(y.pos, 'LEN needs an array or slice'); | |
| 562 | 566 | end; |
| 563 | 567 | bSyscall: begin |
| 564 | 568 | n := 1; |
| @@ -566,7 +570,7 @@ | ||
| 566 | 570 | while (tok = sComma) and (n < 7) do begin |
| 567 | 571 | Next; |
| 568 | 572 | Expression(y, nil); |
| 569 | - if not (IsScalar(y.typ) and (y.typ^.form <> fReal)) then Mark('integer or pointer expected'); | |
| 573 | + if not (IsScalar(y.typ) and (y.typ^.form <> fReal)) then MarkAt(y.pos, 'integer or pointer expected'); | |
| 570 | 574 | if y.typ^.form = fConst then Coerce(y, tI64); |
| 571 | 575 | slots[n] := ToSlot(y); |
| 572 | 576 | inc(n); |
| @@ -581,7 +585,7 @@ | ||
| 581 | 585 | bInc, bDec: begin |
| 582 | 586 | Expression(x, nil); |
| 583 | 587 | if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fInt) then |
| 584 | - Mark('INC and DEC need an integer variable'); | |
| 588 | + MarkAt(x.pos, 'INC and DEC need an integer variable'); | |
| 585 | 589 | Save(x); |
| 586 | 590 | if tok = sComma then begin |
| 587 | 591 | Next; |
| @@ -596,7 +600,7 @@ | ||
| 596 | 600 | Expect(sRparen, ')'); |
| 597 | 601 | end; |
| 598 | 602 | |
| 599 | -procedure ConstructCase(var x: TItem; c: PObj); | |
| 603 | +procedure ConstructCase(var x: TItem; c: PObj; const at: TPos); | |
| 600 | 604 | var f: PObj; a: TItem; |
| 601 | 605 | begin |
| 602 | 606 | Construct(x, c); |
| @@ -610,30 +614,32 @@ | ||
| 610 | 614 | if f <> nil then Expect(sComma, ','); |
| 611 | 615 | end; |
| 612 | 616 | Expect(sRparen, ')'); |
| 613 | - end else if f <> nil then Mark(NameOf(c^.name) + ' needs its fields'); | |
| 617 | + end else if f <> nil then MarkAt(at, NameOf(c^.name) + ' needs its fields'); | |
| 614 | 618 | end; |
| 615 | 619 | |
| 616 | 620 | { A designator, with any selectors and calls after it. called tells |
| 617 | 621 | whether the last thing done was a call. } |
| 618 | 622 | procedure Designator(var x: TItem; var called: boolean); |
| 619 | -var o, f: PObj; y, z: TItem; t: PType; | |
| 623 | +var o, f: PObj; y, z: TItem; t: PType; start: TPos; | |
| 620 | 624 | begin |
| 625 | + start := TokPos; | |
| 621 | 626 | o := QualIdent; |
| 622 | 627 | called := false; |
| 623 | - if o^.cls = oModule then Mark('a module is not a value'); | |
| 628 | + if o^.cls = oModule then MarkAt(SpanFrom(start), 'a module is not a value'); | |
| 624 | 629 | MakeItem(x, o); |
| 625 | 630 | if x.mode = mBuiltin then begin |
| 626 | 631 | Builtin(x); |
| 627 | 632 | called := true; |
| 628 | 633 | end else if x.mode = mCase then begin |
| 629 | - ConstructCase(x, o); | |
| 634 | + ConstructCase(x, o, SpanFrom(start)); | |
| 630 | 635 | end; |
| 631 | 636 | repeat |
| 637 | + x.pos := SpanFrom(start); | |
| 632 | 638 | case tok of |
| 633 | 639 | sPeriod: begin |
| 634 | 640 | Next; |
| 635 | - if (x.mode <> mVar) or (x.typ^.form <> fRecord) then Mark('not a record'); | |
| 636 | - if tok <> sIdent then Mark('field expected'); | |
| 641 | + if (x.mode <> mVar) or (x.typ^.form <> fRecord) then MarkAt(x.pos, 'not a record'); | |
| 642 | + if tok <> sIdent then MarkAt(MissingPos, 'field expected'); | |
| 637 | 643 | f := Find(x.typ^.scope, id); |
| 638 | 644 | if f = nil then Mark('no field ' + NameOf(id)); |
| 639 | 645 | if not f^.exported and (x.typ^.module <> curModule) then |
| @@ -671,13 +677,15 @@ | ||
| 671 | 677 | else break; |
| 672 | 678 | end; |
| 673 | 679 | until false; |
| 680 | + x.pos := SpanFrom(start); | |
| 674 | 681 | end; |
| 675 | 682 | |
| 676 | 683 | procedure ArrayLiteral(var x: TItem; want: PType); |
| 677 | 684 | var |
| 678 | 685 | et, at: PType; e: TItem; slots: array[0..1023] of int64; n, i: longint; |
| 679 | - off, es: int64; | |
| 686 | + off, es: int64; start: TPos; | |
| 680 | 687 | begin |
| 688 | + start := TokPos; | |
| 681 | 689 | if (want = nil) or not (want^.form in [fArray, fSlice]) then |
| 682 | 690 | Mark('an array literal needs a known array or slice type'); |
| 683 | 691 | et := want^.base; |
| @@ -699,7 +707,7 @@ | ||
| 699 | 707 | Next; |
| 700 | 708 | until false; |
| 701 | 709 | Expect(sRbrak, ']'); |
| 702 | - if (want^.form = fArray) and (n <> want^.len) then Mark('wrong number of elements'); | |
| 710 | + if (want^.form = fArray) and (n <> want^.len) then MarkAt(SpanFrom(start), 'wrong number of elements'); | |
| 703 | 711 | if n = 0 then begin |
| 704 | 712 | MovRI(RAX, 0); |
| 705 | 713 | SliceOf(x, want, 0); |
| @@ -737,7 +745,7 @@ | ||
| 737 | 745 | n := 0; |
| 738 | 746 | if tok <> sRbrace then |
| 739 | 747 | repeat |
| 740 | - if tok <> sIdent then Mark('field expected'); | |
| 748 | + if tok <> sIdent then MarkAt(MissingPos, 'field expected'); | |
| 741 | 749 | f := Find(t^.scope, id); |
| 742 | 750 | if f = nil then Mark('no field ' + NameOf(id)); |
| 743 | 751 | if not f^.exported and (t^.module <> curModule) then Mark('field ' + NameOf(id) + ' isn''t exported'); |
| @@ -756,20 +764,21 @@ | ||
| 756 | 764 | { A set literal: the bits of the constant names, or'd at run time with |
| 757 | 765 | those of the others. } |
| 758 | 766 | procedure SetLiteral(var x: TItem; t: PType); |
| 759 | -var e: TItem; bits, slot: int64; | |
| 767 | +var e: TItem; bits, slot: int64; start: TPos; | |
| 760 | 768 | begin |
| 769 | + start := TokPos; | |
| 761 | 770 | Next; |
| 762 | - if (t <> nil) and (t^.form <> fSet) then Mark('a set literal needs a set type'); | |
| 771 | + if (t <> nil) and (t^.form <> fSet) then MarkAt(SpanFrom(start), 'a set literal needs a set type'); | |
| 763 | 772 | bits := 0; |
| 764 | 773 | slot := 0; |
| 765 | 774 | if tok <> sRbrace then |
| 766 | 775 | repeat |
| 767 | 776 | if t = nil then Expression(e, nil) else Expression(e, t^.base); |
| 768 | 777 | if t = nil then begin |
| 769 | - if e.typ^.form <> fEnum then Mark('a set holds names of an enumeration'); | |
| 770 | - t := SetOf(e.typ); | |
| 778 | + if e.typ^.form <> fEnum then MarkAt(e.pos, 'a set holds names of an enumeration'); | |
| 779 | + t := SetOf(e.typ, e.pos); | |
| 771 | 780 | end; |
| 772 | - if not Same(e.typ, t^.base) then Mark('not a name of ' + TypeName(t^.base)); | |
| 781 | + if not Same(e.typ, t^.base) then MarkAt(e.pos, 'not a name of ' + TypeName(t^.base)); | |
| 773 | 782 | if e.mode = mConst then bits := bits or (int64(1) shl e.val) |
| 774 | 783 | else begin |
| 775 | 784 | if slot = 0 then begin |
| @@ -788,7 +797,7 @@ | ||
| 788 | 797 | Next; |
| 789 | 798 | until false; |
| 790 | 799 | Expect(sRbrace, '}'); |
| 791 | - if t = nil then Mark('{} needs a known set type'); | |
| 800 | + if t = nil then MarkAt(SpanFrom(start), '{} needs a known set type'); | |
| 792 | 801 | MakeConst(x, t, bits); |
| 793 | 802 | if slot <> 0 then begin |
| 794 | 803 | Load(RAX, Mem(RBP, slot), 8, false); |
| @@ -799,8 +808,9 @@ | ||
| 799 | 808 | end; |
| 800 | 809 | |
| 801 | 810 | procedure Factor(var x: TItem; want: PType); |
| 802 | -var called, vol: boolean; t: PType; | |
| 811 | +var called, vol: boolean; t: PType; start: TPos; | |
| 803 | 812 | begin |
| 813 | + start := TokPos; | |
| 804 | 814 | case tok of |
| 805 | 815 | sInt, sChar: begin |
| 806 | 816 | { only a hex number can be above high(I64), and it is a U64 } |
| @@ -811,8 +821,8 @@ | ||
| 811 | 821 | sString: begin MakeStr(x); Next end; |
| 812 | 822 | sIdent: begin |
| 813 | 823 | Designator(x, called); |
| 814 | - if x.mode = mNone then Mark('this procedure returns nothing'); | |
| 815 | - if x.typ^.tuple then Mark('several results go only to a, b := ...'); | |
| 824 | + if x.mode = mNone then MarkAt(x.pos, 'this procedure returns nothing'); | |
| 825 | + if x.typ^.tuple then MarkAt(x.pos, 'several results go only to a, b := ...'); | |
| 816 | 826 | end; |
| 817 | 827 | sLparen: begin Next; Expression(x, want); Expect(sRparen, ')') end; |
| 818 | 828 | sNot: begin Next; Factor(x, nil); NotOp(x) end; |
| @@ -829,13 +839,15 @@ | ||
| 829 | 839 | Expect(sRparen, ')'); |
| 830 | 840 | Convert(x, t); |
| 831 | 841 | end; |
| 832 | - else Mark('expression expected'); | |
| 842 | + else MarkAt(MissingPos, 'expression expected'); | |
| 833 | 843 | end; |
| 844 | + x.pos := SpanFrom(start); | |
| 834 | 845 | end; |
| 835 | 846 | |
| 836 | 847 | procedure Term(var x: TItem; want: PType); |
| 837 | -var op: TSym; y: TItem; L: longint; | |
| 848 | +var op: TSym; y: TItem; L: longint; start: TPos; | |
| 838 | 849 | begin |
| 850 | + start := TokPos; | |
| 839 | 851 | Factor(x, want); |
| 840 | 852 | while tok in [sTimes, sSlash, sDiv, sMod, sAnd, sShl, sShr] do begin |
| 841 | 853 | op := tok; |
| @@ -843,15 +855,18 @@ | ||
| 843 | 855 | Op1(op, x, L); |
| 844 | 856 | Factor(y, nil); |
| 845 | 857 | Op2(op, x, y, L); |
| 858 | + x.pos := SpanFrom(start); | |
| 846 | 859 | end; |
| 847 | 860 | end; |
| 848 | 861 | |
| 849 | 862 | procedure SimpleExpr(var x: TItem; want: PType); |
| 850 | -var op: TSym; y: TItem; L: longint; | |
| 863 | +var op: TSym; y: TItem; L: longint; start: TPos; | |
| 851 | 864 | begin |
| 865 | + start := TokPos; | |
| 852 | 866 | if tok = sMinus then begin |
| 853 | 867 | Next; |
| 854 | 868 | Term(x, nil); |
| 869 | + x.pos := SpanFrom(start); | |
| 855 | 870 | Neg(x); |
| 856 | 871 | end else Term(x, want); |
| 857 | 872 | while tok in [sPlus, sMinus, sOr, sXor] do begin |
| @@ -860,6 +875,7 @@ | ||
| 860 | 875 | Op1(op, x, L); |
| 861 | 876 | Term(y, nil); |
| 862 | 877 | Op2(op, x, y, L); |
| 878 | + x.pos := SpanFrom(start); | |
| 863 | 879 | end; |
| 864 | 880 | end; |
| 865 | 881 | |
| @@ -873,6 +889,7 @@ | ||
| 873 | 889 | Op1(op, x, L); |
| 874 | 890 | if op = sIn then SimpleExpr(y, nil) else SimpleExpr(y, x.typ); |
| 875 | 891 | Op2(op, x, y, L); |
| 892 | + x.pos := Join(x.pos, y.pos); | |
| 876 | 893 | end; |
| 877 | 894 | end; |
| 878 | 895 | |
| @@ -963,7 +980,7 @@ | ||
| 963 | 980 | lp: TLoop; old: PLoop; |
| 964 | 981 | begin |
| 965 | 982 | Next; |
| 966 | - if tok <> sIdent then Mark('name expected'); | |
| 983 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 967 | 984 | o := Lookup(id); |
| 968 | 985 | if (o = nil) or (o^.cls <> oVar) or not (o^.typ^.form in [fInt, fEnum]) then |
| 969 | 986 | Mark('a for loop needs an integer or enumeration variable'); |
| @@ -982,7 +999,7 @@ | ||
| 982 | 999 | Next; |
| 983 | 1000 | Expression(s, nil); |
| 984 | 1001 | step := ConstValue(s); |
| 985 | - if step = 0 then Mark('the step can''t be zero'); | |
| 1002 | + if step = 0 then MarkAt(s.pos, 'the step can''t be zero'); | |
| 986 | 1003 | end; |
| 987 | 1004 | Expect(sDo, 'do'); |
| 988 | 1005 | exitL := NoLabel; |
| @@ -1008,7 +1025,7 @@ | ||
| 1008 | 1025 | procedure MatchStatement; |
| 1009 | 1026 | var |
| 1010 | 1027 | x: TItem; t: PType; c, f, o: PObj; p: int64; L, endL, n: longint; |
| 1011 | - seen: array[0..255] of boolean; hasElse: boolean; | |
| 1028 | + seen: array[0..255] of boolean; hasElse: boolean; endAt: TPos; | |
| 1012 | 1029 | begin |
| 1013 | 1030 | Next; |
| 1014 | 1031 | Expression(x, nil); |
| @@ -1027,7 +1044,7 @@ | ||
| 1027 | 1044 | Statements; |
| 1028 | 1045 | hasElse := true; |
| 1029 | 1046 | end else begin |
| 1030 | - if tok <> sIdent then Mark('case expected'); | |
| 1047 | + if tok <> sIdent then MarkAt(MissingPos, 'case expected'); | |
| 1031 | 1048 | c := t^.fields; |
| 1032 | 1049 | while (c <> nil) and (c^.name <> id) do c := c^.next; |
| 1033 | 1050 | if c = nil then Mark(NameOf(id) + ' isn''t a case of ' + TypeName(t)); |
| @@ -1042,7 +1059,7 @@ | ||
| 1042 | 1059 | f := c^.fields; |
| 1043 | 1060 | n := 0; |
| 1044 | 1061 | repeat |
| 1045 | - if tok <> sIdent then Mark('name expected'); | |
| 1062 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 1046 | 1063 | if f = nil then Mark('too many fields'); |
| 1047 | 1064 | o := NewObj(oVar, id, f^.typ); |
| 1048 | 1065 | o^.lev := 1; o^.ind := true; o^.isVar := true; |
| @@ -1064,11 +1081,12 @@ | ||
| 1064 | 1081 | FixLink(L); |
| 1065 | 1082 | end; |
| 1066 | 1083 | end; |
| 1084 | + endAt := TokPos; | |
| 1067 | 1085 | Expect(sEnd, 'end'); |
| 1068 | 1086 | if not hasElse then begin |
| 1069 | 1087 | c := t^.fields; |
| 1070 | 1088 | while c <> nil do begin |
| 1071 | - if (c^.val > High(seen)) or not seen[c^.val] then Mark('no arm for ' + NameOf(c^.name)); | |
| 1089 | + if (c^.val > High(seen)) or not seen[c^.val] then MarkAt(endAt, 'no arm for ' + NameOf(c^.name)); | |
| 1072 | 1090 | c := c^.next; |
| 1073 | 1091 | end; |
| 1074 | 1092 | end; |
| @@ -1083,7 +1101,7 @@ | ||
| 1083 | 1101 | n := 0; |
| 1084 | 1102 | d[0] := x; |
| 1085 | 1103 | repeat |
| 1086 | - if (d[n].mode <> mVar) or not d[n].isVar then Mark('can''t assign to this'); | |
| 1104 | + if (d[n].mode <> mVar) or not d[n].isVar then MarkAt(d[n].pos, 'can''t assign to this'); | |
| 1087 | 1105 | Pin(d[n]); |
| 1088 | 1106 | inc(n); |
| 1089 | 1107 | if tok <> sComma then break; |
| @@ -1094,7 +1112,7 @@ | ||
| 1094 | 1112 | Expect(sBecomes, ':='); |
| 1095 | 1113 | Designator(y, called); |
| 1096 | 1114 | if not called or not y.typ^.tuple or (y.typ^.len <> n) then |
| 1097 | - Mark('needs a call with as many results as variables'); | |
| 1115 | + MarkAt(y.pos, 'needs a call with as many results as variables'); | |
| 1098 | 1116 | f := y.typ^.fields; |
| 1099 | 1117 | for i := 0 to n - 1 do begin |
| 1100 | 1118 | z := y; |
| @@ -1119,11 +1137,12 @@ | ||
| 1119 | 1137 | { defer s: s is compiled where it stands, as a little subroutine of the |
| 1120 | 1138 | procedure, jumped over; each way out of the statement list calls it. } |
| 1121 | 1139 | procedure Defer; |
| 1122 | -var L, pos, oldDepth: longint; oldLoop: PLoop; oldDeferring: boolean; | |
| 1140 | +var L, pos, oldDepth: longint; oldLoop: PLoop; oldDeferring: boolean; start: TPos; | |
| 1123 | 1141 | begin |
| 1142 | + start := TokPos; | |
| 1124 | 1143 | Next; |
| 1125 | - if directDefer then Mark('defer can''t be deferred'); | |
| 1126 | - if numDefers > High(defers) then Mark('too many deferred statements'); | |
| 1144 | + if directDefer then MarkAt(SpanFrom(start), 'defer can''t be deferred'); | |
| 1145 | + if numDefers > High(defers) then MarkAt(SpanFrom(start), 'too many deferred statements'); | |
| 1127 | 1146 | L := NoLabel; |
| 1128 | 1147 | Jmp(L); |
| 1129 | 1148 | pos := pc; |
| @@ -1143,15 +1162,16 @@ | ||
| 1143 | 1162 | end; |
| 1144 | 1163 | |
| 1145 | 1164 | procedure Statement; |
| 1146 | -var x, y: TItem; called: boolean; m: int64; c: TCall; | |
| 1165 | +var x, y: TItem; called: boolean; m: int64; c: TCall; start: TPos; | |
| 1147 | 1166 | begin |
| 1167 | + start := TokPos; | |
| 1148 | 1168 | NoteLine(CurLine); |
| 1149 | 1169 | m := TempMark; |
| 1150 | 1170 | case tok of |
| 1151 | 1171 | sIdent: begin |
| 1152 | 1172 | Designator(x, called); |
| 1153 | 1173 | if tok = sBecomes then begin |
| 1154 | - if (x.mode <> mVar) or not x.isVar then Mark('can''t assign to this'); | |
| 1174 | + if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to this'); | |
| 1155 | 1175 | Save(x); |
| 1156 | 1176 | Next; |
| 1157 | 1177 | Expression(y, x.typ); |
| @@ -1162,7 +1182,7 @@ | ||
| 1162 | 1182 | if (x.mode = mProc) or ((x.mode in [mVar, mReg]) and (x.typ^.form = fProc)) then begin |
| 1163 | 1183 | BeginCall(c, x); |
| 1164 | 1184 | EndCall(c, x); |
| 1165 | - end else Mark('not a statement'); | |
| 1185 | + end else MarkAt(x.pos, 'not a statement'); | |
| 1166 | 1186 | end; |
| 1167 | 1187 | end; |
| 1168 | 1188 | sIf: IfStatement; |
| @@ -1172,7 +1192,7 @@ | ||
| 1172 | 1192 | sMatch: MatchStatement; |
| 1173 | 1193 | sReturn: begin |
| 1174 | 1194 | Next; |
| 1175 | - if deferring then Mark('return can''t leave a deferred statement'); | |
| 1195 | + if deferring then MarkAt(SpanFrom(start), 'return can''t leave a deferred statement'); | |
| 1176 | 1196 | if tok = sSemicolon then begin |
| 1177 | 1197 | RunDefers(0); |
| 1178 | 1198 | ReturnNone; |
| @@ -1193,12 +1213,12 @@ | ||
| 1193 | 1213 | end; |
| 1194 | 1214 | sBreak: begin |
| 1195 | 1215 | Next; |
| 1196 | - if curLoop = nil then Mark('break outside a loop'); | |
| 1216 | + if curLoop = nil then MarkAt(SpanFrom(start), 'break outside a loop'); | |
| 1197 | 1217 | RunDefers(curLoop^.base); |
| 1198 | 1218 | Jmp(curLoop^.brk); |
| 1199 | 1219 | end; |
| 1200 | 1220 | sDefer: Defer; |
| 1201 | - else Mark('statement expected'); | |
| 1221 | + else MarkAt(MissingPos, 'statement expected'); | |
| 1202 | 1222 | end; |
| 1203 | 1223 | ReleaseTemps(m); |
| 1204 | 1224 | end; |
| @@ -1278,30 +1298,31 @@ | ||
| 1278 | 1298 | CloseScope; |
| 1279 | 1299 | end; |
| 1280 | 1300 | |
| 1281 | -procedure CodeBody(p: PObj; sig: PType); | |
| 1282 | -var q: PObj; ni, nf: longint; v: int64; | |
| 1301 | +procedure CodeBody(p: PObj; sig: PType; const at: TPos); | |
| 1302 | +var q: PObj; ni, nf: longint; v: int64; start: TPos; | |
| 1283 | 1303 | begin |
| 1284 | 1304 | ni := 0; nf := 0; |
| 1285 | 1305 | q := sig^.fields; |
| 1286 | 1306 | while q <> nil do begin |
| 1287 | 1307 | if not q^.isVar and not IsScalar(q^.typ) then |
| 1288 | - Mark('a code procedure takes integers, BOOL, reals, pointers and procedures'); | |
| 1308 | + MarkAt(at, 'a code procedure takes integers, BOOL, reals, pointers and procedures'); | |
| 1289 | 1309 | if (q^.typ^.form = fReal) and not q^.isVar then inc(nf) else inc(ni); |
| 1290 | 1310 | q := q^.next; |
| 1291 | 1311 | end; |
| 1292 | - if (ni > 6) or (nf > 8) or sig^.variadic then Mark('too many parameters for a code procedure'); | |
| 1312 | + if (ni > 6) or (nf > 8) or sig^.variadic then MarkAt(at, 'too many parameters for a code procedure'); | |
| 1293 | 1313 | if sig^.base <> nil then |
| 1294 | 1314 | if sig^.base^.tuple then begin |
| 1295 | 1315 | q := sig^.base^.fields; |
| 1296 | 1316 | if (sig^.base^.len <> 2) or (q^.typ^.size <> 8) or (q^.next^.typ^.size <> 8) |
| 1297 | 1317 | or not IsScalar(q^.typ) or not IsScalar(q^.next^.typ) |
| 1298 | 1318 | or (q^.typ^.form = fReal) or (q^.next^.typ^.form = fReal) then |
| 1299 | - Mark('a code procedure returns two results only in rax and rdx'); | |
| 1300 | - end else if not IsScalar(sig^.base) then Mark('a code procedure returns a single value'); | |
| 1319 | + MarkAt(at, 'a code procedure returns two results only in rax and rdx'); | |
| 1320 | + end else if not IsScalar(sig^.base) then MarkAt(at, 'a code procedure returns a single value'); | |
| 1301 | 1321 | BeginChunk(p^.chunk); |
| 1302 | 1322 | repeat |
| 1323 | + start := TokPos; | |
| 1303 | 1324 | v := ConstExpr; |
| 1304 | - if (v < 0) or (v > 255) then Mark('a byte expected'); | |
| 1325 | + if (v < 0) or (v > 255) then MarkAt(SpanFrom(start), 'a byte expected'); | |
| 1305 | 1326 | Put1(v); |
| 1306 | 1327 | if tok <> sComma then break; |
| 1307 | 1328 | Next; |
| @@ -1310,16 +1331,18 @@ | ||
| 1310 | 1331 | end; |
| 1311 | 1332 | |
| 1312 | 1333 | procedure ProcDecl; |
| 1313 | -var n, line: longint; exp: boolean; sig: PType; p: PObj; | |
| 1334 | +var n, line: longint; exp: boolean; sig: PType; p: PObj; at: TPos; | |
| 1314 | 1335 | begin |
| 1315 | 1336 | line := CurLine; |
| 1316 | 1337 | Next; |
| 1338 | + at := TokPos; | |
| 1317 | 1339 | IdentDef(n, exp); |
| 1340 | + at := SpanFrom(at); | |
| 1318 | 1341 | sig := Signature; |
| 1319 | 1342 | Expect(sSemicolon, ';'); |
| 1320 | 1343 | p := Find(TopScope, n); |
| 1321 | 1344 | if (p <> nil) and (p^.cls = oProc) and p^.fwd then begin |
| 1322 | - if not Same(p^.typ, sig) then Mark('not the signature it was declared with'); | |
| 1345 | + if not Same(p^.typ, sig) then MarkAt(at, 'not the signature it was declared with'); | |
| 1323 | 1346 | if tok = sForward then Mark('declared forward twice'); |
| 1324 | 1347 | p^.exported := p^.exported or exp; |
| 1325 | 1348 | end else begin |
| @@ -1339,7 +1362,7 @@ | ||
| 1339 | 1362 | if tok = sCode then begin |
| 1340 | 1363 | Next; |
| 1341 | 1364 | p^.isCode := true; |
| 1342 | - CodeBody(p, sig); | |
| 1365 | + CodeBody(p, sig, at); | |
| 1343 | 1366 | exit; |
| 1344 | 1367 | end; |
| 1345 | 1368 | if checkMode then SkipBody else Body(p, sig, line); |
| @@ -1352,26 +1375,28 @@ | ||
| 1352 | 1375 | { An extern procedure or variable: C's, reached through the quadword |
| 1353 | 1376 | that holds its address. } |
| 1354 | 1377 | procedure ExternDecl; |
| 1355 | -var n: longint; exp: boolean; o, q: PObj; t: PType; | |
| 1378 | +var n: longint; exp: boolean; o, q: PObj; t: PType; at: TPos; | |
| 1356 | 1379 | begin |
| 1357 | 1380 | Next; |
| 1358 | 1381 | curModule^.usesC := true; |
| 1359 | 1382 | if tok = sProc then begin |
| 1360 | 1383 | Next; |
| 1384 | + at := TokPos; | |
| 1361 | 1385 | IdentDef(n, exp); |
| 1386 | + at := SpanFrom(at); | |
| 1362 | 1387 | inExtern := true; |
| 1363 | 1388 | t := Signature; |
| 1364 | 1389 | inExtern := false; |
| 1365 | 1390 | q := t^.fields; |
| 1366 | 1391 | while q <> nil do begin |
| 1367 | 1392 | if q^.isVar or not IsScalar(q^.typ) then |
| 1368 | - Mark('C takes integers, BOOL, reals, pointers and procedures'); | |
| 1393 | + MarkAt(at, 'C takes integers, BOOL, reals, pointers and procedures'); | |
| 1369 | 1394 | q := q^.next; |
| 1370 | 1395 | end; |
| 1371 | - if (t^.base <> nil) and not IsScalar(t^.base) then Mark('C returns a single value'); | |
| 1396 | + if (t^.base <> nil) and not IsScalar(t^.base) then MarkAt(at, 'C returns a single value'); | |
| 1372 | 1397 | o := NewObj(oProc, n, t); |
| 1373 | 1398 | end else begin |
| 1374 | - if tok <> sVar then Mark('proc or var expected'); | |
| 1399 | + if tok <> sVar then MarkAt(MissingPos, 'proc or var expected'); | |
| 1375 | 1400 | Next; |
| 1376 | 1401 | IdentDef(n, exp); |
| 1377 | 1402 | Expect(sColon, ':'); |
| @@ -1389,7 +1414,7 @@ | ||
| 1389 | 1414 | procedure Declarations(top: boolean); |
| 1390 | 1415 | var |
| 1391 | 1416 | n, i, k: longint; exp: boolean; x: TItem; o: PObj; t: PType; |
| 1392 | - names: array[0..63] of longint; exps: array[0..63] of boolean; | |
| 1417 | + names: array[0..63] of longint; exps: array[0..63] of boolean; start: TPos; | |
| 1393 | 1418 | begin |
| 1394 | 1419 | repeat |
| 1395 | 1420 | case tok of |
| @@ -1400,8 +1425,9 @@ | ||
| 1400 | 1425 | t := nil; |
| 1401 | 1426 | if tok = sColon then begin |
| 1402 | 1427 | Next; |
| 1428 | + start := TokPos; | |
| 1403 | 1429 | t := ParseType; |
| 1404 | - if t <> tError then Mark('only an ERROR constant has a type'); | |
| 1430 | + if t <> tError then MarkAt(SpanFrom(start), 'only an ERROR constant has a type'); | |
| 1405 | 1431 | end; |
| 1406 | 1432 | Expect(sEql, '='); |
| 1407 | 1433 | Expression(x, nil); |
| @@ -1510,18 +1536,20 @@ | ||
| 1510 | 1536 | |
| 1511 | 1537 | { The arguments of an instance: types, or procedures named. } |
| 1512 | 1538 | procedure ParseArgs(var args: TArgs); |
| 1513 | -var o: PObj; | |
| 1539 | +var o: PObj; start: TPos; | |
| 1514 | 1540 | begin |
| 1515 | 1541 | Next; |
| 1516 | 1542 | repeat |
| 1517 | 1543 | if args.n > High(args.t) then Mark('too many arguments'); |
| 1518 | 1544 | args.o[args.n] := nil; |
| 1545 | + start := TokPos; | |
| 1519 | 1546 | if tok = sIdent then begin |
| 1520 | 1547 | o := QualIdent; |
| 1521 | 1548 | if o^.cls = oProc then args.o[args.n] := o |
| 1522 | - else if o^.cls <> oType then Mark('a type or a procedure expected'); | |
| 1549 | + else if o^.cls <> oType then MarkAt(SpanFrom(start), 'a type or a procedure expected'); | |
| 1523 | 1550 | args.t[args.n] := o^.typ; |
| 1524 | 1551 | end else args.t[args.n] := ParseType; |
| 1552 | + args.pos[args.n] := SpanFrom(start); | |
| 1525 | 1553 | inc(args.n); |
| 1526 | 1554 | if tok <> sComma then break; |
| 1527 | 1555 | Next; |
| @@ -1532,14 +1560,14 @@ | ||
| 1532 | 1560 | { A generic module's parameters, bound to the instance's arguments: a |
| 1533 | 1561 | type parameter names its type, a procedure parameter its procedure. } |
| 1534 | 1562 | procedure Params(m: PModule); |
| 1535 | -var i: longint; o, a: PObj; sig: PType; s: shortstring; | |
| 1563 | +var i: longint; o, a: PObj; sig: PType; s: shortstring; at: TPos; | |
| 1536 | 1564 | begin |
| 1537 | 1565 | i := 0; |
| 1538 | 1566 | s := NameOf(m^.name) + '('; |
| 1539 | 1567 | Next; |
| 1540 | 1568 | repeat |
| 1541 | - if (tok <> sIdent) or (i >= m^.args.n) or (m^.args.o[i] <> nil) then | |
| 1542 | - Mark('needs a type for each type parameter'); | |
| 1569 | + if (tok <> sIdent) or (i >= m^.args.n) then MarkAt(m^.args.at, 'needs a type for each type parameter'); | |
| 1570 | + if m^.args.o[i] <> nil then MarkAt(m^.args.pos[i], 'needs a type for each type parameter'); | |
| 1543 | 1571 | Declare(NewObj(oType, id, m^.args.t[i])); |
| 1544 | 1572 | s := s + TypeName(m^.args.t[i]) + ','; |
| 1545 | 1573 | inc(i); |
| @@ -1549,23 +1577,27 @@ | ||
| 1549 | 1577 | until false; |
| 1550 | 1578 | while tok = sSemicolon do begin |
| 1551 | 1579 | Next; |
| 1552 | - if tok <> sIdent then Mark('name expected'); | |
| 1580 | + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); | |
| 1581 | + at := TokPos; | |
| 1553 | 1582 | o := NewObj(oProc, id, nil); |
| 1554 | 1583 | Next; |
| 1555 | 1584 | Expect(sColon, ':'); |
| 1556 | 1585 | Expect(sProc, 'proc'); |
| 1557 | 1586 | sig := Signature; |
| 1558 | - if i >= m^.args.n then Mark('needs a procedure for ' + NameOf(o^.name)); | |
| 1587 | + if i >= m^.args.n then MarkAt(m^.args.at, 'needs a procedure for ' + NameOf(o^.name)); | |
| 1559 | 1588 | a := m^.args.o[i]; |
| 1560 | - if (a = nil) or not Same(a^.typ, sig) then | |
| 1561 | - Mark('needs a procedure with the signature of ' + NameOf(o^.name)); | |
| 1589 | + if (a = nil) or not Same(a^.typ, sig) then begin | |
| 1590 | + Error(m^.args.pos[i], 'needs a procedure with the signature of ' + NameOf(o^.name)); | |
| 1591 | + Note(at, NameOf(o^.name) + ' is declared here'); | |
| 1592 | + Finish; | |
| 1593 | + end; | |
| 1562 | 1594 | o^.typ := a^.typ; o^.chunk := a^.chunk; o^.isCode := a^.isCode; o^.ext := a^.ext; |
| 1563 | 1595 | Declare(o); |
| 1564 | 1596 | s := s + NameOf(a^.module^.name) + '.' + NameOf(a^.name) + ','; |
| 1565 | 1597 | inc(i); |
| 1566 | 1598 | end; |
| 1567 | 1599 | Expect(sRparen, ')'); |
| 1568 | - if i <> m^.args.n then Mark('too many arguments'); | |
| 1600 | + if i <> m^.args.n then MarkAt(m^.args.at, 'too many arguments'); | |
| 1569 | 1601 | s[length(s)] := ')'; |
| 1570 | 1602 | m^.sname := Name(s); |
| 1571 | 1603 | end; |
| @@ -1586,7 +1618,7 @@ | ||
| 1586 | 1618 | var |
| 1587 | 1619 | st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint; |
| 1588 | 1620 | oldMod: PModule; oldFile: longint; oldCheck: boolean; m, im: PModule; |
| 1589 | - imp: PImport; lib: PLib; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs; | |
| 1621 | + imp: PImport; lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs; | |
| 1590 | 1622 | begin |
| 1591 | 1623 | SaveScan(st); |
| 1592 | 1624 | SaveScopes(d, saved); |
| @@ -1616,23 +1648,25 @@ | ||
| 1616 | 1648 | if (tok <> sIdent) or (id <> n) then Mark('this file must hold module ' + NameOf(n)); |
| 1617 | 1649 | Next; |
| 1618 | 1650 | if tok = sLparen then Params(m) |
| 1619 | - else if args.n > 0 then Mark(NameOf(n) + ' isn''t generic'); | |
| 1651 | + else if args.n > 0 then MarkAt(args.at, NameOf(n) + ' isn''t generic'); | |
| 1620 | 1652 | Expect(sSemicolon, ';'); |
| 1621 | 1653 | while tok = sImport do begin |
| 1622 | 1654 | Next; |
| 1623 | 1655 | repeat |
| 1624 | - if tok <> sIdent then Mark('module name expected'); | |
| 1656 | + if tok <> sIdent then MarkAt(MissingPos, 'module name expected'); | |
| 1657 | + start := TokPos; | |
| 1625 | 1658 | alias := id; |
| 1626 | 1659 | mname := id; |
| 1627 | 1660 | iargs.n := 0; |
| 1628 | 1661 | Next; |
| 1629 | 1662 | if tok = sBecomes then begin |
| 1630 | 1663 | Next; |
| 1631 | - if tok <> sIdent then Mark('module name expected'); | |
| 1664 | + if tok <> sIdent then MarkAt(MissingPos, 'module name expected'); | |
| 1632 | 1665 | mname := id; |
| 1633 | 1666 | Next; |
| 1634 | 1667 | if tok = sLparen then ParseArgs(iargs); |
| 1635 | 1668 | end; |
| 1669 | + iargs.at := SpanFrom(start); | |
| 1636 | 1670 | im := ImportModule(mname, iargs); |
| 1637 | 1671 | o := NewObj(oModule, alias, nil); |
| 1638 | 1672 | o^.module := im; |
| @@ -1679,7 +1713,7 @@ | ||
| 1679 | 1713 | end else Expect(sEnd, 'end'); |
| 1680 | 1714 | if (tok <> sIdent) or (id <> n) then Mark('end ' + NameOf(n) + ' expected'); |
| 1681 | 1715 | Next; |
| 1682 | - if tok <> sPeriod then Mark('. expected'); | |
| 1716 | + if tok <> sPeriod then MarkAt(MissingPos, '. expected'); | |
| 1683 | 1717 | o := m^.first; |
| 1684 | 1718 | while o <> nil do begin |
| 1685 | 1719 | if (o^.cls = oProc) and o^.fwd then Mark(NameOf(o^.name) + ' is declared forward but never defined'); |
| @@ -1759,7 +1793,7 @@ | ||
| 1759 | 1793 | m := FindModule(name, args); |
| 1760 | 1794 | if m <> nil then exit(m); |
| 1761 | 1795 | for i := 0 to numPending - 1 do |
| 1762 | - if IsModule(pending[i], name, args) then Mark(NameOf(name) + ' imports itself'); | |
| 1796 | + if IsModule(pending[i], name, args) then MarkAt(args.at, NameOf(name) + ' imports itself'); | |
| 1763 | 1797 | for i := -1 to numInc do begin |
| 1764 | 1798 | if i = -1 then dir := mainDir |
| 1765 | 1799 | else if i = numInc then dir := libDir |
| @@ -1773,7 +1807,7 @@ | ||
| 1773 | 1807 | end; |
| 1774 | 1808 | end; |
| 1775 | 1809 | end; |
| 1776 | - Mark('can''t find module ' + NameOf(name)); | |
| 1810 | + MarkAt(args.at, 'can''t find module ' + NameOf(name)); | |
| 1777 | 1811 | ImportModule := nil; |
| 1778 | 1812 | end; |
| 1779 | 1813 | |
| @@ -1789,6 +1823,7 @@ | ||
| 1789 | 1823 | if i > 0 then base := copy(base, 1, i - 1); |
| 1790 | 1824 | if base = '' then Fatal('no module in ' + path); |
| 1791 | 1825 | n := Name(base); |
| 1826 | + none.at := TokPos; | |
| 1792 | 1827 | if n <> nameRt then ImportModule(nameRt, none); |
| 1793 | 1828 | if FindModule(n, none) <> nil then CompileMain := FindModule(n, none) |
| 1794 | 1829 | else CompileMain := CompileFile(path, n, none, false); |
| @@ -41,6 +41,7 @@ | ||
| 41 | 41 | buf: PChar; |
| 42 | 42 | len, pos, line, lineStart: longint; |
| 43 | 43 | tokPos, tokLine, tokLineStart: longint; |
| 44 | + prevEnd: longint; { where the symbol before this one ends } | |
| 44 | 45 | tok: TSym; |
| 45 | 46 | ival: int64; |
| 46 | 47 | rval: double; |
| @@ -66,9 +67,13 @@ | ||
| 66 | 67 | function Open(const path: shortstring): boolean; |
| 67 | 68 | procedure Next; |
| 68 | 69 | procedure Mark(const msg: shortstring); |
| 70 | +procedure MarkAt(const p: TPos; const msg: shortstring); | |
| 69 | 71 | procedure SaveScan(var st: TScanState); |
| 70 | 72 | procedure RestoreScan(const st: TScanState); |
| 71 | 73 | function TokPos: TPos; |
| 74 | +function AfterPrev: TPos; | |
| 75 | +function MissingPos: TPos; | |
| 76 | +function SpanFrom(const p: TPos): TPos; | |
| 72 | 77 | function CurPath: shortstring; |
| 73 | 78 | function CurLine: longint; |
| 74 | 79 | |
| @@ -171,6 +176,34 @@ | ||
| 171 | 176 | TokPos.b := cur.pos; |
| 172 | 177 | end; |
| 173 | 178 | |
| 179 | +{ The place just after the symbol before the current one, where a | |
| 180 | + missing symbol belongs } | |
| 181 | +function AfterPrev: TPos; | |
| 182 | +begin | |
| 183 | + AfterPrev.f := cur.f; | |
| 184 | + AfterPrev.a := cur.prevEnd; | |
| 185 | + AfterPrev.b := cur.prevEnd; | |
| 186 | +end; | |
| 187 | + | |
| 188 | +{ Where to say a symbol is missing: at the current symbol, unless it | |
| 189 | + starts a later line than the symbol before it, which is more likely | |
| 190 | + where the missing one belongs } | |
| 191 | +function MissingPos: TPos; | |
| 192 | +var i: longint; | |
| 193 | +begin | |
| 194 | + MissingPos := TokPos; | |
| 195 | + for i := cur.prevEnd to cur.tokPos - 1 do | |
| 196 | + if cur.buf[i] = #10 then MissingPos := AfterPrev; | |
| 197 | +end; | |
| 198 | + | |
| 199 | +{ From the start of p to the end of the symbol before the current one: | |
| 200 | + the whole of a construct that has just been read } | |
| 201 | +function SpanFrom(const p: TPos): TPos; | |
| 202 | +begin | |
| 203 | + SpanFrom := p; | |
| 204 | + SpanFrom.b := cur.prevEnd; | |
| 205 | +end; | |
| 206 | + | |
| 174 | 207 | function CurPath: shortstring; |
| 175 | 208 | begin |
| 176 | 209 | CurPath := cur.path; |
| @@ -183,7 +216,20 @@ | ||
| 183 | 216 | |
| 184 | 217 | procedure Mark(const msg: shortstring); |
| 185 | 218 | begin |
| 186 | - Error(TokPos, msg); | |
| 219 | + MarkAt(TokPos, msg); | |
| 220 | +end; | |
| 221 | + | |
| 222 | +{ Report at the bytes a to b of the file being read } | |
| 223 | +procedure MarkBytes(a, b: longint; const msg: shortstring); | |
| 224 | +var p: TPos; | |
| 225 | +begin | |
| 226 | + p.f := cur.f; p.a := a; p.b := b; | |
| 227 | + MarkAt(p, msg); | |
| 228 | +end; | |
| 229 | + | |
| 230 | +procedure MarkAt(const p: TPos; const msg: shortstring); | |
| 231 | +begin | |
| 232 | + Error(p, msg); | |
| 187 | 233 | Finish; |
| 188 | 234 | end; |
| 189 | 235 | |
| @@ -298,9 +344,10 @@ | ||
| 298 | 344 | { One character of a character or string literal, at buf[pos]: its code |
| 299 | 345 | point, or for \xHH, minus one minus the byte. } |
| 300 | 346 | function LitChar(inString: boolean): longint; |
| 301 | -var c: char; v, d, n: longint; | |
| 347 | +var c: char; v, d, n, esc: longint; | |
| 302 | 348 | begin |
| 303 | 349 | c := cur.buf[cur.pos]; |
| 350 | + esc := cur.pos; | |
| 304 | 351 | if c = '\' then begin |
| 305 | 352 | inc(cur.pos); |
| 306 | 353 | c := cur.buf[cur.pos]; |
| @@ -312,28 +359,28 @@ | ||
| 312 | 359 | '0': v := 0; |
| 313 | 360 | '\', '''', '"': v := ord(c); |
| 314 | 361 | 'x': begin |
| 315 | - if not inString then Mark('\x only in strings'); | |
| 362 | + if not inString then MarkBytes(esc, cur.pos, '\x only in strings'); | |
| 316 | 363 | d := HexVal(cur.buf[cur.pos]); |
| 317 | 364 | n := HexVal(cur.buf[cur.pos + 1]); |
| 318 | - if (d < 0) or (n < 0) then Mark('\x needs two hex digits'); | |
| 365 | + if (d < 0) or (n < 0) then MarkBytes(esc, cur.pos + 2, '\x needs two hex digits'); | |
| 319 | 366 | inc(cur.pos, 2); |
| 320 | 367 | v := -1 - (d * 16 + n); |
| 321 | 368 | end; |
| 322 | 369 | 'u': begin |
| 323 | - if cur.buf[cur.pos] <> '{' then Mark('\u needs {'); | |
| 370 | + if cur.buf[cur.pos] <> '{' then MarkBytes(esc, cur.pos, '\u needs {'); | |
| 324 | 371 | inc(cur.pos); |
| 325 | 372 | v := 0; n := 0; |
| 326 | 373 | while HexVal(cur.buf[cur.pos]) >= 0 do begin |
| 327 | 374 | v := v * 16 + HexVal(cur.buf[cur.pos]); |
| 328 | 375 | inc(n); inc(cur.pos); |
| 329 | - if n > 6 then Mark('code point too big'); | |
| 376 | + if n > 6 then MarkBytes(esc, cur.pos, 'code point too big'); | |
| 330 | 377 | end; |
| 331 | - if (n = 0) or (cur.buf[cur.pos] <> '}') then Mark('bad \u{...}'); | |
| 378 | + if (n = 0) or (cur.buf[cur.pos] <> '}') then MarkBytes(esc, cur.pos, 'bad \u{...}'); | |
| 332 | 379 | inc(cur.pos); |
| 333 | 380 | if (v > $10FFFF) or ((v >= $D800) and (v <= $DFFF)) then |
| 334 | - Mark('not a code point'); | |
| 381 | + MarkBytes(esc, cur.pos, 'not a code point'); | |
| 335 | 382 | end; |
| 336 | - else Mark('unknown escape'); | |
| 383 | + else MarkBytes(esc, cur.pos, 'unknown escape'); | |
| 337 | 384 | end; |
| 338 | 385 | end else if byte(c) >= $80 then |
| 339 | 386 | v := Utf8(cur.pos) |
| @@ -349,14 +396,15 @@ | ||
| 349 | 396 | { Symbols } |
| 350 | 397 | |
| 351 | 398 | procedure Comment; |
| 352 | -var depth: longint; c: char; | |
| 399 | +var depth, open: longint; c: char; | |
| 353 | 400 | begin |
| 354 | 401 | depth := 1; |
| 402 | + open := cur.pos; | |
| 355 | 403 | inc(cur.pos, 2); |
| 356 | 404 | repeat |
| 357 | 405 | c := cur.buf[cur.pos]; |
| 358 | 406 | if c = #0 then begin |
| 359 | - if cur.pos >= cur.len then Mark('comment not closed'); | |
| 407 | + if cur.pos >= cur.len then MarkBytes(open, open + 2, 'comment not closed'); | |
| 360 | 408 | inc(cur.pos); |
| 361 | 409 | end else if (c = '(') and (cur.buf[cur.pos + 1] = '*') then begin |
| 362 | 410 | inc(depth); inc(cur.pos, 2) |
| @@ -422,6 +470,7 @@ | ||
| 422 | 470 | procedure Next; |
| 423 | 471 | var c: char; start, h, v: longint; |
| 424 | 472 | begin |
| 473 | + cur.prevEnd := cur.pos; | |
| 425 | 474 | repeat |
| 426 | 475 | c := cur.buf[cur.pos]; |
| 427 | 476 | while c in [' ', #9, #13, #10] do begin |
| @@ -509,13 +558,13 @@ | ||
| 509 | 558 | '^': begin inc(cur.pos); tok := sArrow end; |
| 510 | 559 | '|': begin inc(cur.pos); tok := sBar end; |
| 511 | 560 | #0: begin |
| 512 | - if cur.pos < cur.len then Mark('NUL character'); | |
| 561 | + if cur.pos < cur.len then MarkBytes(cur.pos, cur.pos + 1, 'NUL character'); | |
| 513 | 562 | tok := sEof; |
| 514 | 563 | end; |
| 515 | 564 | else |
| 516 | 565 | if byte(c) >= $80 then |
| 517 | 566 | Mark('text outside strings, characters and comments must be ASCII'); |
| 518 | - Mark('unexpected character'); | |
| 567 | + MarkBytes(cur.pos, cur.pos + 1, 'unexpected character'); | |
| 519 | 568 | end; |
| 520 | 569 | end; |
| 521 | 570 |
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | interface |
| 19 | 19 | |
| 20 | -uses scan; | |
| 20 | +uses scan, diag; | |
| 21 | 21 | |
| 22 | 22 | type |
| 23 | 23 | TForm = (fNone, fBool, fInt, fReal, fConst, fNil, fStr, fPtr, fArray, |
| @@ -80,6 +80,8 @@ | ||
| 80 | 80 | n: longint; |
| 81 | 81 | t: array[0..7] of PType; |
| 82 | 82 | o: array[0..7] of PObj; |
| 83 | + pos: array[0..7] of TPos; { where each argument is, for messages } | |
| 84 | + at: TPos; { where the import is } | |
| 83 | 85 | end; |
| 84 | 86 | |
| 85 | 87 | TImport = record |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/Assign.raz:5:11: error: can't use I32 as I64 | |
| 1 | +test/err/Assign.raz:5:10: error: can't use I32 as I64 | |
| 2 | 2 | 5 | a := b; |
| 3 | - | ^ | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtAnd.raz:5:16: error: and, or need two BOOLs | |
| 2 | + 5 | b := b and (x + 1); | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtAnd; | |
| 2 | +proc main*; | |
| 3 | +var b: BOOL; x: I64; | |
| 4 | +begin | |
| 5 | + b := b and (x + 1); | |
| 6 | +end; | |
| 7 | +end AtAnd. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtArgType.raz:7:8: error: can't use BOOL as I64 | |
| 2 | + 7 | Id(b); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,9 @@ | ||
| 1 | +module AtArgType; | |
| 2 | +proc Id(a: I64): I64; | |
| 3 | +begin return a; end; | |
| 4 | +proc main*; | |
| 5 | +var b: BOOL; | |
| 6 | +begin | |
| 7 | + Id(b); | |
| 8 | +end; | |
| 9 | +end AtArgType. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtBinary.raz:5:10: error: can't combine I64 and BOOL | |
| 2 | + 5 | x := (x + 2) * b; | |
| 3 | + | ^^^^^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtBinary; | |
| 2 | +proc main*; | |
| 3 | +var x: I64; b: BOOL; | |
| 4 | +begin | |
| 5 | + x := (x + 2) * b; | |
| 6 | +end; | |
| 7 | +end AtBinary. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtCall.raz:5:10: error: not a procedure | |
| 2 | + 5 | x := x(1); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtCall; | |
| 2 | +proc main*; | |
| 3 | +var x: I64; | |
| 4 | +begin | |
| 5 | + x := x(1); | |
| 6 | +end; | |
| 7 | +end AtCall. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtCondition.raz:5:8: error: a condition is a BOOL | |
| 2 | + 5 | if x + 1 then end; | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtCondition; | |
| 2 | +proc main*; | |
| 3 | +var x: I64; | |
| 4 | +begin | |
| 5 | + if x + 1 then end; | |
| 6 | +end; | |
| 7 | +end AtCondition. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtConstFit.raz:5:10: error: constant doesn't fit I32 | |
| 2 | + 5 | x := 5 + 3000000000; | |
| 3 | + | ^^^^^^^^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtConstFit; | |
| 2 | +proc main*; | |
| 3 | +var x: I32; | |
| 4 | +begin | |
| 5 | + x := 5 + 3000000000; | |
| 6 | +end; | |
| 7 | +end AtConstFit. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtConvert.raz:5:14: error: can't convert BOOL to I64 | |
| 2 | + 5 | x := I64(b); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtConvert; | |
| 2 | +proc main*; | |
| 3 | +var b: BOOL; x: I64; | |
| 4 | +begin | |
| 5 | + x := I64(b); | |
| 6 | +end; | |
| 7 | +end AtConvert. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtDeref.raz:5:10: error: not a pointer | |
| 2 | + 5 | y := x^; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtDeref; | |
| 2 | +proc main*; | |
| 3 | +var x, y: I64; | |
| 4 | +begin | |
| 5 | + y := x^; | |
| 6 | +end; | |
| 7 | +end AtDeref. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtDivZero.raz:5:10: error: division by zero | |
| 2 | + 5 | x := 7 div (3 - 3); | |
| 3 | + | ^^^^^^^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtDivZero; | |
| 2 | +proc main*; | |
| 3 | +var x: I64; | |
| 4 | +begin | |
| 5 | + x := 7 div (3 - 3); | |
| 6 | +end; | |
| 7 | +end AtDivZero. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtIndex.raz:5:12: error: an index is an integer | |
| 2 | + 5 | x := a[b]; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtIndex; | |
| 2 | +proc main*; | |
| 3 | +var a: [4]I64; b: BOOL; x: I64; | |
| 4 | +begin | |
| 5 | + x := a[b]; | |
| 6 | +end; | |
| 7 | +end AtIndex. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtIndexConst.raz:5:12: error: index out of range | |
| 2 | + 5 | x := a[2 + 3]; | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtIndexConst; | |
| 2 | +proc main*; | |
| 3 | +var a: [4]I64; x: I64; | |
| 4 | +begin | |
| 5 | + x := a[2 + 3]; | |
| 6 | +end; | |
| 7 | +end AtIndexConst. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtMany.raz:7:16: error: too many arguments | |
| 2 | + 7 | x := Id(1, 2 * 3); | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,9 @@ | ||
| 1 | +module AtMany; | |
| 2 | +proc Id(a: I64): I64; | |
| 3 | +begin return a; end; | |
| 4 | +proc main*; | |
| 5 | +var x: I64; | |
| 6 | +begin | |
| 7 | + x := Id(1, 2 * 3); | |
| 8 | +end; | |
| 9 | +end AtMany. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtMatch.raz:5:11: error: match needs a variant or an enumeration | |
| 2 | + 5 | match x + 1 do end; | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtMatch; | |
| 2 | +proc main*; | |
| 3 | +var x: I64; | |
| 4 | +begin | |
| 5 | + match x + 1 do end; | |
| 6 | +end; | |
| 7 | +end AtMatch. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtNegate.raz:5:10: error: can't negate BOOL | |
| 2 | + 5 | x := -b; | |
| 3 | + | ^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtNegate; | |
| 2 | +proc main*; | |
| 3 | +var b: BOOL; x: I64; | |
| 4 | +begin | |
| 5 | + x := -b; | |
| 6 | +end; | |
| 7 | +end AtNegate. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtNot.raz:5:14: error: not needs BOOL or an integer | |
| 2 | + 5 | b := not s; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtNot; | |
| 2 | +proc main*; | |
| 3 | +var s: []U8; b: BOOL; | |
| 4 | +begin | |
| 5 | + b := not s; | |
| 6 | +end; | |
| 7 | +end AtNot. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtNotValue.raz:5:10: error: not a value | |
| 2 | + 5 | x := I64 + 1; | |
| 3 | + | ^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtNotValue; | |
| 2 | +proc main*; | |
| 3 | +var x: I64; | |
| 4 | +begin | |
| 5 | + x := I64 + 1; | |
| 6 | +end; | |
| 7 | +end AtNotValue. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPAdr.raz:5:14: error: ADR needs a variable | |
| 2 | + 5 | p := ADR(1); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPAdr; | |
| 2 | +proc main*; | |
| 3 | +var p: ^I64; | |
| 4 | +begin | |
| 5 | + p := ADR(1); | |
| 6 | +end; | |
| 7 | +end AtPAdr. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPArrayLen.raz:2:9: error: bad array length | |
| 2 | + 2 | var a: [0]I64; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,6 @@ | ||
| 1 | +module AtPArrayLen; | |
| 2 | +var a: [0]I64; | |
| 3 | +proc main*; | |
| 4 | +begin | |
| 5 | +end; | |
| 6 | +end AtPArrayLen. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPByte.raz:3:6: error: a byte expected | |
| 2 | + 3 | code 300; | |
| 3 | + | ^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +module AtPByte; | |
| 2 | +proc f(a: I64); | |
| 3 | +code 300; | |
| 4 | +end AtPByte. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPCantAssign.raz:7:8: error: can't assign to this | |
| 2 | + 7 | a, k := two(); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,9 @@ | ||
| 1 | +module AtPCantAssign; | |
| 2 | +const k = 1; | |
| 3 | +proc two: (I64, I64); begin return 1, 2; end; | |
| 4 | +proc main*; | |
| 5 | +var a: I64; | |
| 6 | +begin | |
| 7 | + a, k := two(); | |
| 8 | +end; | |
| 9 | +end AtPCantAssign. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPChar.raz:5:12: error: unexpected character | |
| 2 | + 5 | a := 1 ? 2; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPChar; | |
| 2 | +proc main*; | |
| 3 | +var a: I64; | |
| 4 | +begin | |
| 5 | + a := 1 ? 2; | |
| 6 | +end; | |
| 7 | +end AtPChar. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPComment.raz:5:1: error: comment not closed | |
| 2 | + 5 | (* never closed | |
| 3 | + | ^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,6 @@ | ||
| 1 | +module AtPComment; | |
| 2 | +proc main*; | |
| 3 | +begin | |
| 4 | +end; | |
| 5 | +(* never closed | |
| 6 | +end AtPComment. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPConstExpr.raz:4:9: error: constant expected | |
| 2 | + 4 | var a: [n]I64; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPConstExpr; | |
| 2 | +proc main*; | |
| 3 | +var n: I64; | |
| 4 | +var a: [n]I64; | |
| 5 | +begin | |
| 6 | +end; | |
| 7 | +end AtPConstExpr. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPElems.raz:5:10: error: wrong number of elements | |
| 2 | + 5 | a := [1, 2]; | |
| 3 | + | ^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPElems; | |
| 2 | +proc main*; | |
| 3 | +var a: [3]I64; | |
| 4 | +begin | |
| 5 | + a := [1, 2]; | |
| 6 | +end; | |
| 7 | +end AtPElems. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPEscape.raz:5:12: error: unknown escape | |
| 2 | + 5 | s := "a\q"; | |
| 3 | + | ^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPEscape; | |
| 2 | +proc main*; | |
| 3 | +var s: [8]U8; | |
| 4 | +begin | |
| 5 | + s := "a\q"; | |
| 6 | +end; | |
| 7 | +end AtPEscape. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPInc.raz:5:9: error: INC and DEC need an integer variable | |
| 2 | + 5 | INC(a); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPInc; | |
| 2 | +proc main*; | |
| 3 | +var a: BOOL; | |
| 4 | +begin | |
| 5 | + INC(a); | |
| 6 | +end; | |
| 7 | +end AtPInc. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPLen.raz:5:14: error: LEN needs an array or slice | |
| 2 | + 5 | a := LEN(a); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPLen; | |
| 2 | +proc main*; | |
| 3 | +var a: I64; | |
| 4 | +begin | |
| 5 | + a := LEN(a); | |
| 6 | +end; | |
| 7 | +end AtPLen. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPNewVar.raz:5:9: error: NEW needs a pointer variable | |
| 2 | + 5 | NEW(a, a); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPNewVar; | |
| 2 | +proc main*; | |
| 3 | +var a: I64; | |
| 4 | +begin | |
| 5 | + NEW(a, a); | |
| 6 | +end; | |
| 7 | +end AtPNewVar. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPNoResult.raz:8:10: error: this procedure returns nothing | |
| 2 | + 8 | a := p() + 1; | |
| 3 | + | ^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,10 @@ | ||
| 1 | +module AtPNoResult; | |
| 2 | +proc p; | |
| 3 | +begin | |
| 4 | +end; | |
| 5 | +proc main*; | |
| 6 | +var a: I64; | |
| 7 | +begin | |
| 8 | + a := p() + 1; | |
| 9 | +end; | |
| 10 | +end AtPNoResult. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPNotRecord.raz:5:10: error: not a record | |
| 2 | + 5 | a := a.f; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPNotRecord; | |
| 2 | +proc main*; | |
| 3 | +var a: I64; | |
| 4 | +begin | |
| 5 | + a := a.f; | |
| 6 | +end; | |
| 7 | +end AtPNotRecord. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPNotStmt.raz:5:5: error: not a statement | |
| 2 | + 5 | a; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPNotStmt; | |
| 2 | +proc main*; | |
| 3 | +var a: I64; | |
| 4 | +begin | |
| 5 | + a; | |
| 6 | +end; | |
| 7 | +end AtPNotStmt. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPSetLit.raz:6:14: error: not a name of C | |
| 2 | + 6 | s := {r, 1}; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module AtPSetLit; | |
| 2 | +type C = (r, g, b); | |
| 3 | +proc main*; | |
| 4 | +var s: set of C; | |
| 5 | +begin | |
| 6 | + s := {r, 1}; | |
| 7 | +end; | |
| 8 | +end AtPSetLit. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPStep.raz:5:24: error: the step can't be zero | |
| 2 | + 5 | for i := 1 to 5 by 1 - 1 do end; | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPStep; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; | |
| 4 | +begin | |
| 5 | + for i := 1 to 5 by 1 - 1 do end; | |
| 6 | +end; | |
| 7 | +end AtPStep. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtPtrMinus.raz:5:10: error: different pointer types | |
| 2 | + 5 | x := p - q; | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtPtrMinus; | |
| 2 | +proc main*; | |
| 3 | +var p: ^I64; q: ^I32; x: I64; | |
| 4 | +begin | |
| 5 | + x := p - q; | |
| 6 | +end; | |
| 7 | +end AtPtrMinus. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtReturn.raz:4:12: error: this procedure returns nothing | |
| 2 | + 4 | return 1 + 2; | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,6 @@ | ||
| 1 | +module AtReturn; | |
| 2 | +proc main*; | |
| 3 | +begin | |
| 4 | + return 1 + 2; | |
| 5 | +end; | |
| 6 | +end AtReturn. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtSliceHi.raz:5:15: error: an index is an integer | |
| 2 | + 5 | s := a[0..b]; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtSliceHi; | |
| 2 | +proc main*; | |
| 3 | +var a: [4]I64; b: BOOL; s: []I64; | |
| 4 | +begin | |
| 5 | + s := a[0..b]; | |
| 6 | +end; | |
| 7 | +end AtSliceHi. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtSliceLo.raz:5:12: error: an index is an integer | |
| 2 | + 5 | s := a[b..2]; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtSliceLo; | |
| 2 | +proc main*; | |
| 3 | +var a: [4]I64; b: BOOL; s: []I64; | |
| 4 | +begin | |
| 5 | + s := a[b..2]; | |
| 6 | +end; | |
| 7 | +end AtSliceLo. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtStrCmp.raz:5:12: error: can't compare a string with I64 | |
| 2 | + 5 | if s = x + 1 then end; | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtStrCmp; | |
| 2 | +proc main*; | |
| 3 | +var s: []U8; x: I64; | |
| 4 | +begin | |
| 5 | + if s = x + 1 then end; | |
| 6 | +end; | |
| 7 | +end AtStrCmp. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AtVarArg.raz:7:9: error: a var parameter needs a variable | |
| 2 | + 7 | Inc(1 + 2); | |
| 3 | + | ^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,9 @@ | ||
| 1 | +module AtVarArg; | |
| 2 | +proc Inc(var a: I64); | |
| 3 | +begin a := a + 1; end; | |
| 4 | +proc main*; | |
| 5 | +var x: I64; | |
| 6 | +begin | |
| 7 | + Inc(1 + 2); | |
| 8 | +end; | |
| 9 | +end AtVarArg. |
| @@ -1,4 +1,7 @@ | ||
| 1 | -/home/luis/raz/lib/Map.raz:4:39: error: needs a procedure with the signature of hash | |
| 1 | +test/err/BadProc.raz:2:33: error: needs a procedure with the signature of hash | |
| 2 | + 2 | import Str, M := Map([]U8, I64, Str.cmp, Str.eq); | |
| 3 | + | ^^^^^^^ | |
| 4 | +lib/Map.raz:4:18: note: hash is declared here | |
| 2 | 5 | 4 | module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL); |
| 3 | - | ^ | |
| 6 | + | ^^^^ | |
| 4 | 7 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/BigI64.raz:5:28: error: can't use U64 as I64 | |
| 1 | +test/err/BigI64.raz:5:10: error: can't use U64 as I64 | |
| 2 | 2 | 5 | i := 0FFFFFFFFFFFFFFFFH; |
| 3 | - | ^ | |
| 3 | + | ^^^^^^^^^^^^^^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/Break.raz:4:10: error: break outside a loop | |
| 1 | +test/err/Break.raz:4:5: error: break outside a loop | |
| 2 | 2 | 4 | break; |
| 3 | - | ^ | |
| 3 | + | ^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/mods/CycleB.raz:2:13: error: Cycle imports itself | |
| 1 | +test/err/mods/CycleB.raz:2:8: error: Cycle imports itself | |
| 2 | 2 | 2 | import Cycle; |
| 3 | - | ^ | |
| 3 | + | ^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/DeferBreak.raz:5:20: error: break outside a loop | |
| 1 | +test/err/DeferBreak.raz:5:15: error: break outside a loop | |
| 2 | 2 | 5 | defer break; |
| 3 | - | ^ | |
| 3 | + | ^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/DeferDefer.raz:4:17: error: defer can't be deferred | |
| 1 | +test/err/DeferDefer.raz:4:11: error: defer can't be deferred | |
| 2 | 2 | 4 | defer defer f; |
| 3 | - | ^ | |
| 3 | + | ^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/DeferReturn.raz:4:18: error: return can't leave a deferred statement | |
| 1 | +test/err/DeferReturn.raz:4:11: error: return can't leave a deferred statement | |
| 2 | 2 | 4 | defer return 1; |
| 3 | - | ^ | |
| 3 | + | ^^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/ErrOrder.raz:5:14: error: procedures and errors compare only with = and # | |
| 1 | +test/err/ErrOrder.raz:5:8: error: procedures and errors compare only with = and # | |
| 2 | 2 | 5 | if A < B then end; |
| 3 | - | ^^^^ | |
| 3 | + | ^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/ExternRec.raz:5:20: error: C takes integers, BOOL, reals, pointers and procedures | |
| 1 | +test/err/ExternRec.raz:5:13: error: C takes integers, BOOL, reals, pointers and procedures | |
| 2 | 2 | 5 | extern proc f(r: R); |
| 3 | - | ^ | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/F32Dots.raz:8:23: error: an F32 goes to ... as F64(x) | |
| 1 | +test/err/F32Dots.raz:8:22: error: an F32 goes to ... as F64(x) | |
| 2 | 2 | 8 | C.printf("%f\n", x); |
| 3 | - | ^ | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/Match.raz:9:8: error: no arm for c | |
| 1 | +test/err/Match.raz:9:5: error: no arm for c | |
| 2 | 2 | 9 | end; |
| 3 | - | ^ | |
| 3 | + | ^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/Mixed.raz:6:15: error: different types: F32 and F64 | |
| 1 | +test/err/Mixed.raz:6:10: error: different types: F32 and F64 | |
| 2 | 2 | 6 | y := x + y; |
| 3 | - | ^ | |
| 3 | + | ^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/NegU64.raz:5:12: error: constant doesn't fit U64 | |
| 1 | +test/err/NegU64.raz:5:10: error: constant doesn't fit U64 | |
| 2 | 2 | 5 | u := -1; |
| 3 | - | ^ | |
| 3 | + | ^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -/home/luis/raz/lib/List.raz:2:13: error: needs a type for each type parameter | |
| 2 | - 2 | module List(T); | |
| 3 | - | ^ | |
| 1 | +test/err/NoArgs.raz:2:8: error: needs a type for each type parameter | |
| 2 | + 2 | import List; | |
| 3 | + | ^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -/home/luis/raz/lib/Str.raz:3:11: error: Str isn't generic | |
| 2 | - 3 | module Str; | |
| 3 | - | ^ | |
| 1 | +test/err/NotGeneric.raz:2:8: error: Str isn't generic | |
| 2 | + 2 | import S := Str(I64); | |
| 3 | + | ^^^^^^^^^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/PtrArray.raz:6:7: error: a pointer to an array is indexed as p^[i] | |
| 1 | +test/err/PtrArray.raz:6:5: error: a pointer to an array is indexed as p^[i] | |
| 2 | 2 | 6 | p[1] := 0; |
| 3 | - | ^ | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/Tuple.raz:6:16: error: several results go only to a, b := ... | |
| 1 | +test/err/Tuple.raz:6:10: error: several results go only to a, b := ... | |
| 2 | 2 | 6 | a := two() + 1; |
| 3 | - | ^ | |
| 3 | + | ^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/TwoTypes.raz:6:11: error: can't use List(I32).List as List(I64).List | |
| 1 | +test/err/TwoTypes.raz:6:10: error: can't use List(I32).List as List(I64).List | |
| 2 | 2 | 6 | a := b; |
| 3 | - | ^ | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/Volatile.raz:6:11: error: can't use ^VOLATILE I64 as ^I64 | |
| 1 | +test/err/Volatile.raz:6:10: error: can't use ^VOLATILE I64 as ^I64 | |
| 2 | 2 | 6 | q := p; |
| 3 | - | ^ | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |