-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patherror.c
1791 lines (1631 loc) · 62.2 KB
/
error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
$Id: error.c 3136 2024-05-11 09:05:50Z soci $
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "error.h"
#include <string.h>
#include <errno.h>
#include "file.h"
#include "64tass.h"
#include "unicode.h"
#include "eval.h"
#include "arguments.h"
#include "opcodes.h"
#include "section.h"
#include "macro.h"
#include "strobj.h"
#include "addressobj.h"
#include "registerobj.h"
#include "namespaceobj.h"
#include "operobj.h"
#include "typeobj.h"
#include "labelobj.h"
#include "errorobj.h"
#include "noneobj.h"
#include "symbolobj.h"
#include "anonsymbolobj.h"
#include "console.h"
struct file_list_s *current_file_list;
struct file_list_s *commandline_file_list;
const struct file_list_s *dummy_file_list;
#define ALIGN(v) (((v) + (sizeof(int *) - 1)) & ~(sizeof(int *) - 1))
static unsigned int errors = 0, warnings = 0;
struct file_listnode_s {
struct file_list_s flist;
struct file_listnode_s *parent;
struct avltree_node node;
struct avltree members;
uint8_t pass;
};
static struct file_listnode_s file_list;
static const struct file_listnode_s *included_from = &file_list;
static const char *prgname = "64tass";
struct errorbuffer_s {
size_t max;
size_t len;
size_t header_pos;
size_t header_stop;
uint8_t *data;
struct avltree members;
};
static struct errorbuffer_s error_list;
static struct avltree notdefines;
typedef enum Severity_types {
SV_NOTE, SV_WARNING, SV_NONEERROR, SV_ERROR, SV_FATAL
} Severity_types;
struct errorentry_s {
Severity_types severity;
size_t error_len;
size_t line_len;
const struct file_list_s *file_list;
struct linepos_s epoint;
linecpos_t caret;
struct avltree_node node;
};
struct notdefines_s {
str_t cfname;
const struct file_list_s *file_list;
struct linepos_s epoint;
uint8_t pass;
struct avltree_node node;
};
static FAST_CALL int duplicate_compare(const struct avltree_node *aa, const struct avltree_node *bb)
{
const struct errorentry_s *a = cavltree_container_of(aa, struct errorentry_s, node);
const struct errorentry_s *b = cavltree_container_of(bb, struct errorentry_s, node);
const uint8_t *aerr, *berr;
if (a->severity != b->severity) return (int)a->severity - (int)b->severity;
if (a->file_list != b->file_list) return a->file_list > b->file_list ? 1 : -1;
if (a->error_len != b->error_len) return a->error_len > b->error_len ? 1 : -1;
if (a->epoint.line != b->epoint.line) return a->epoint.line > b->epoint.line ? 1 : -1;
if (a->epoint.pos != b->epoint.pos) return a->epoint.pos > b->epoint.pos ? 1 : -1;
aerr = (const uint8_t *)(a + 1);
berr = (const uint8_t *)(b + 1);
if ((a->line_len | b->line_len) != 0) {
int i;
const uint8_t *aline, *bline;
if (a->line_len != 0) {
aline = aerr;
aerr += a->line_len;
} else if (a->epoint.line == 0) {
aline = (const uint8_t *)"";
} else {
aline = &a->file_list->file->source.data[a->file_list->file->line[a->epoint.line - 1]];
}
if (b->line_len != 0) {
bline = berr;
berr += b->line_len;
} else if (a->epoint.line == 0) {
bline = (const uint8_t *)"";
} else {
bline = &a->file_list->file->source.data[a->file_list->file->line[a->epoint.line - 1]];
}
i = strcmp((const char *)aline, (const char *)bline);
if (i != 0) return i;
}
return memcmp(aerr, berr, a->error_len);
}
static bool close_error_duplicate;
static void close_error(void) {
if (error_list.header_pos < error_list.len) {
struct errorentry_s *err = (struct errorentry_s *)&error_list.data[error_list.header_pos];
err->error_len = error_list.len - error_list.header_pos - (sizeof *err) - err->line_len;
switch (err->severity) {
case SV_NOTE:
if (!close_error_duplicate) memset(&err->node, 0, sizeof err->node);
break;
default:
close_error_duplicate = avltree_insert(&err->node, &error_list.members, duplicate_compare) != NULL;
}
if (close_error_duplicate) {
error_list.len = error_list.header_pos;
}
error_list.header_pos = ALIGN(error_list.len);
}
}
static NO_RETURN void err_msg_out_of_memory2(void)
{
fatal_error("out of memory");
fatal_error(NULL);
exit(EXIT_FAILURE);
}
static void error_extend(void) {
struct errorentry_s *err;
uint8_t *data;
size_t diff, pos;
bool dir;
if (add_overflow(error_list.len, 0x200, &error_list.max)) err_msg_out_of_memory2();
data = reallocate_array(error_list.data, error_list.max);
if (data == NULL) err_msg_out_of_memory2();
dir = data >= error_list.data;
diff = dir ? (size_t)(data - error_list.data) : (size_t)(error_list.data - data);
error_list.data = data;
if (diff == 0) return;
for (pos = 0; pos < error_list.header_pos; pos = ALIGN(pos + (sizeof *err) + err->line_len + err->error_len)) {
err = (struct errorentry_s *)&data[pos];
if (err->node.left != NULL) err->node.left = (struct avltree_node *)((dir ? ((uint8_t *)err->node.left + diff) : ((uint8_t *)err->node.left - diff)));
if (err->node.right != NULL) err->node.right = (struct avltree_node *)((dir ? ((uint8_t *)err->node.right + diff) : ((uint8_t *)err->node.right - diff)));
if (err->node.parent != NULL) err->node.parent = (struct avltree_node *)((dir ? ((uint8_t *)err->node.parent + diff) : ((uint8_t *)err->node.parent - diff)));
}
if (error_list.members.root != NULL) error_list.members.root = (struct avltree_node *)((dir ? ((uint8_t *)error_list.members.root + diff) : ((uint8_t *)error_list.members.root - diff)));
}
static struct errorentry_s *new_error_msg_common(const uint8_t *line) {
struct errorentry_s *err;
size_t line_len;
close_error();
if (add_overflow(error_list.header_pos, sizeof *err, &error_list.len)) err_msg_out_of_memory2();
if (line == NULL) {
line_len = 0;
} else {
line_len = strlen((const char *)line) + 1;
if (inc_overflow(&error_list.len, line_len)) err_msg_out_of_memory2();
}
if (error_list.len > error_list.max) error_extend();
if (line_len != 0) memcpy(&error_list.data[error_list.header_pos + sizeof *err], line, line_len);
err = (struct errorentry_s *)&error_list.data[error_list.header_pos];
err->line_len = line_len;
err->error_len = 0;
return err;
}
static void adderror2(const uint8_t *s, size_t len) {
size_t pos = error_list.len;
if (inc_overflow(&error_list.len, len)) err_msg_out_of_memory2();
if (error_list.len > error_list.max) error_extend();
memcpy(error_list.data + pos, s, len);
}
static void adderror(const char *s) {
adderror2((const uint8_t *)s, strlen(s));
}
static struct {
Severity_types severity;
const struct file_list_s *flist;
linepos_t epoint;
} new_error_msg_more_param;
static void new_error_msg_more(void) {
struct errorentry_s *err = new_error_msg_common((new_error_msg_more_param.severity != SV_NOTE && (new_error_msg_more_param.epoint->line == lpoint.line) && not_in_file(pline, new_error_msg_more_param.flist->file)) ? pline : NULL);
err->severity = SV_NOTE;
err->file_list = new_error_msg_more_param.flist;
err->epoint.line = new_error_msg_more_param.epoint->line;
err->epoint.pos = macro_error_translate2(new_error_msg_more_param.epoint->pos);
err->caret = new_error_msg_more_param.epoint->pos;
adderror("original location in an expanded macro was here");
}
static bool new_error_msg(Severity_types severity, const struct file_list_s *flist, linepos_t epoint) {
struct errorentry_s *err;
if (in_macro && flist == current_file_list && epoint->line == lpoint.line) {
struct linepos_s opoint;
const struct file_list_s *eflist = macro_error_translate(&opoint, epoint->pos);
if (eflist != NULL) {
err = new_error_msg_common(NULL);
err->file_list = eflist;
err->epoint = opoint;
err->caret = opoint.pos;
err->severity = severity;
new_error_msg_more_param.severity = severity;
new_error_msg_more_param.flist = flist;
new_error_msg_more_param.epoint = epoint;
return true;
}
}
err = new_error_msg_common((severity != SV_NOTE && (epoint->line == lpoint.line) && not_in_file(pline, flist->file)) ? pline : NULL);
err->severity = severity;
err->file_list = flist;
err->epoint.line = epoint->line;
err->caret = epoint->pos;
err->epoint.pos = macro_error_translate2(epoint->pos);
return false;
}
static bool new_error_msg_err(const Error *err) {
struct errorentry_s *tmp;
if (in_macro && err->file_list == current_file_list && err->epoint.line == lpoint.line) {
struct linepos_s opoint;
const struct file_list_s *eflist = macro_error_translate(&opoint, err->caret);
if (eflist != NULL) {
tmp = new_error_msg_common(NULL);
tmp->severity = SV_ERROR;
tmp->file_list = eflist;
tmp->epoint = opoint;
tmp->caret = opoint.pos;
return true;
}
}
tmp = new_error_msg_common(err->line);
tmp->severity = SV_ERROR;
tmp->file_list = err->file_list;
tmp->epoint = err->epoint;
tmp->caret = (err->line == NULL) ? err->epoint.pos : err->caret;
return false;
}
static void new_error_msg2(bool type, linepos_t epoint) {
Severity_types severity = type ? SV_ERROR : SV_WARNING;
bool more = new_error_msg(severity, current_file_list, epoint);
if (more) new_error_msg_more();
}
static FAST_CALL int file_list_compare(const struct avltree_node *aa, const struct avltree_node *bb)
{
const struct file_list_s *a = &cavltree_container_of(aa, struct file_listnode_s, node)->flist;
const struct file_list_s *b = &cavltree_container_of(bb, struct file_listnode_s, node)->flist;
if (a->epoint.line != b->epoint.line) return a->epoint.line > b->epoint.line ? 1 : -1;
if (a->epoint.pos != b->epoint.pos) return a->epoint.pos > b->epoint.pos ? 1 : -1;
return a->file->uid - b->file->uid;
}
static struct file_lists_s {
struct file_listnode_s file_lists[90];
struct file_lists_s *next;
} *file_lists = NULL;
const struct file_list_s *parent_file_list(const struct file_list_s *cflist) {
return &((const struct file_listnode_s *)cflist)->parent->flist;
}
static struct file_listnode_s *lastfl;
static int file_listsp;
void enterfile(struct file_s *file, linepos_t epoint) {
struct avltree_node *b;
struct file_listnode_s *cflist = (struct file_listnode_s *)current_file_list;
lastfl->flist.file = file;
lastfl->flist.epoint = *epoint;
b = avltree_insert(&lastfl->node, &cflist->members, file_list_compare);
if (b == NULL) {
lastfl->parent = cflist;
avltree_init(&lastfl->members);
cflist = lastfl;
if (file_listsp == 89) {
struct file_lists_s *old = file_lists;
new_instance(&file_lists);
file_lists->next = old;
file_listsp = 0;
} else file_listsp++;
lastfl = &file_lists->file_lists[file_listsp];
} else {
cflist = avltree_container_of(b, struct file_listnode_s, node);
}
cflist->pass = pass;
current_file_list = &cflist->flist;
}
void exitfile(void) {
struct file_listnode_s *cflist = (struct file_listnode_s *)current_file_list;
if (cflist->parent != NULL) current_file_list = &cflist->parent->flist;
}
static const char *const terr_warning[] = {
"deprecated modulo operator, use '%' instead",
"deprecated not equal operator, use '!=' instead",
"deprecated directive, only for TASM compatible mode",
"please use format(\"%d\", ...) as '^' will change it's meaning",
"please separate @b, @w or @l from label or number for future compatibility",
"constant result, possibly changeable to 'lda'",
"independent result, possibly changeable to 'lda'",
#ifdef _WIN32
"the file's real name is not '",
#endif
#if defined _WIN32 || defined __MSDOS__ || defined __DOS__
"use '/' as path separation '",
#else
"this name uses reserved characters '",
#endif
"use relative path for '"
};
static const char *const terr_error[] = {
"double defined range",
"double defined escape",
"extra characters on line",
"more than two characters ",
"floating point overflow",
"general syntax",
"expression syntax",
"label required",
"division by zero ",
"zero value not allowed",
"most significiant bit must be clear in byte",
"at least one byte is needed",
"last byte must not be gap",
"address in different program bank ",
"address out of section",
"negative number raised on fractional power",
"zero raised to negative power ",
"square root of negative number ",
"logarithm of non-positive number ",
"not in range -1.0 to 1.0 ",
"empty range not allowed",
"empty string not allowed",
"empty list not allowed",
"more than a single character ",
"requirements not met",
"conflict",
"index out of range ",
"key not in dictionary ",
"offset out of range ",
"not hashable ",
"not a key and value pair ",
"too large for a %u bit signed integer ",
"too large for a %u bit unsigned integer ",
"too large for a %u byte signed integer ",
"too large for a %u byte unsigned integer ",
"value needs to be non-negative ",
"can't get sign of ",
"can't get absolute value of ",
"can't get integer value of ",
"can't get length of ",
"can't get size of ",
"can't get boolean value of ",
"not iterable ",
"no byte sized",
"no word sized",
"no long sized",
"not a direct page address ",
"not a data bank address ",
"not a bank 0 address ",
"out of memory",
"addressing mode too complex",
"closing directive '",
"opening directive '",
"must be used within a loop",
"not measurable as start offset beyond size of original",
"must be defined later"
};
static const char *const terr_fatal[] = {
"can't open file",
"error reading file",
"can't write object file",
"can't write listing file",
"can't write label file",
"can't write make file",
"can't write error file",
"can't write map file",
"file recursion",
"macro recursion too deep",
"function recursion too deep",
"weak recursion too deep",
"too many passes"
};
static void err_msg_variable(Obj *val) {
Obj *err;
adderror(val->obj->name);
err = val->obj->str(val, NULL, 40);
if (err != NULL) {
if (err->obj == STR_OBJ) {
Str *str = Str(err);
adderror(" '");
adderror2(str->data, str->len);
adderror("'");
}
val_destroy(err);
}
}
static void str_name(const uint8_t *data, size_t len) {
adderror(" '");
if (len != 0) {
if (data[0] == '-') {
adderror("-");
} else if (data[0] == '+') {
adderror("+");
} else if (data[0] == '.' || data[0] == '#') {
adderror("<anonymous>");
} else adderror2(data, len);
}
adderror("'");
}
static void err_opcode(uint32_t);
void err_msg2(Error_types no, const void *prm, linepos_t epoint) {
bool more;
if (no < 0x40) {
switch (no) {
case ERROR___OPTIMIZABLE:
new_error_msg2(diagnostic_errors.optimize, epoint);
adderror("could be shorter by using '");
adderror((const char *)prm);
adderror("' instead");
adderror(" [-Woptimize]");
break;
case ERROR______SIMPLIFY:
new_error_msg2(diagnostic_errors.optimize, epoint);
adderror("could be simpler by using '");
adderror((const char *)prm);
adderror("' instead");
adderror(" [-Woptimize]");
break;
case ERROR_____REDUNDANT:
new_error_msg2(diagnostic_errors.optimize, epoint);
adderror("possibly redundant ");
adderror((const char *)prm);
adderror(" [-Woptimize]");
break;
case ERROR__CONST_RESULT:
new_error_msg2(diagnostic_errors.optimize, epoint);
adderror(terr_warning[no]);
adderror(" [-Woptimize]");
break;
case ERROR_______OLD_NEQ:
case ERROR____OLD_MODULO:
case ERROR____OLD_STRING:
case ERROR________OLD_AT:
new_error_msg2(diagnostic_errors.deprecated, epoint);
adderror(terr_warning[no]);
adderror(" [-Wdeprecated]");
break;
case ERROR_____OLD_EQUAL:
new_error_msg2(diagnostic_errors.old_equal, epoint);
adderror("deprecated equal operator, use '==' instead [-Wold-equal]");
break;
case ERROR_NONIMMEDCONST:
new_error_msg2(diagnostic_errors.immediate, epoint);
adderror("immediate addressing mode suggested [-Wimmediate]");
break;
case ERROR_LEADING_ZEROS:
new_error_msg2(diagnostic_errors.leading_zeros, epoint);
adderror("leading zeros ignored [-Wleading-zeros]");
break;
case ERROR_DIRECTIVE_IGN:
new_error_msg2(diagnostic_errors.ignored, epoint);
adderror("directive ignored [-Wignored]");
break;
case ERROR_FLOAT_COMPARE:
new_error_msg2(diagnostic_errors.float_compare, epoint);
adderror("approximate floating point ");
adderror((const char *)prm);
adderror("' [-Wfloat-compare]");
break;
case ERROR___FLOAT_ROUND:
new_error_msg2(diagnostic_errors.float_round, epoint);
adderror("implicit floating point rounding [-Wfloat-round]");
break;
case ERROR___LONG_BRANCH:
new_error_msg2(diagnostic_errors.long_branch, epoint);
adderror("long branch used [-Wlong-branch]");
break;
case ERROR_WUSER_DEFINED:
more = new_error_msg(SV_WARNING, current_file_list, epoint);
adderror2(((const Str *)prm)->data, ((const Str *)prm)->len);
if (more) new_error_msg_more();
break;
#ifdef _WIN32
case ERROR___INSENSITIVE:
#endif
#if defined _WIN32 || defined __MSDOS__ || defined __DOS__
case ERROR_____BACKSLASH:
#else
case ERROR__RESERVED_CHR:
#endif
case ERROR_ABSOLUTE_PATH:
new_error_msg2(diagnostic_errors.portable, epoint);
adderror(terr_warning[no]);
adderror2(((const str_t *)prm)->data, ((const str_t *)prm)->len);
adderror("' [-Wportable]");
break;
default:
more = new_error_msg(SV_WARNING, current_file_list, epoint);
adderror(terr_warning[no]);
if (more) new_error_msg_more();
break;
}
return;
}
if (no < 0xc0) {
char line[1024];
more = new_error_msg(SV_ERROR, current_file_list, epoint);
switch (no) {
case ERROR_BRANCH_TOOFAR:
sprintf(line,"branch too far by %+d bytes", *(const int *)prm); adderror(line);
break;
case ERROR____PTEXT_LONG:
sprintf(line,"ptext too long by %" PRIuSIZE " bytes", *(const size_t *)prm - 0x100); adderror(line);
break;
case ERROR____ALIGN_LONG:
sprintf(line,"block to long for alignment by %" PRIuaddress " bytes", *(const address_t *)prm); adderror(line);
break;
case ERROR__BRANCH_CROSS:
sprintf(line,"branch crosses page by %+d bytes", *(const int *)prm); adderror(line);
break;
case ERROR__USER_DEFINED:
adderror2(((const Str *)prm)->data, ((const Str *)prm)->len);
break;
case ERROR______EXPECTED:
adderror((const char *)prm);
adderror(" expected");
break;
case ERROR__MISSING_OPEN:
case ERROR_MISSING_CLOSE:
adderror(terr_error[no - 0x40]);
adderror((const char *)prm);
adderror("' not found");
break;
case ERROR_RESERVED_LABL:
adderror("reserved symbol name '");
adderror2(((const str_t *)prm)->data, ((const str_t *)prm)->len);
adderror("'");
break;
case ERROR_____NOT_BANK0:
case ERROR____NOT_DIRECT:
case ERROR__NOT_DATABANK:
case ERROR_CANT_CROSS_BA:
case ERROR__OFFSET_RANGE:
case ERROR_NOT_TWO_CHARS:
case ERROR__NOT_ONE_CHAR:
case ERROR______NOT_UVAL:
adderror(terr_error[no - 0x40]);
if (prm != NULL) err_msg_variable((Obj *)prm);
break;
case ERROR___UNKNOWN_CPU:
adderror("unknown processor '");
adderror2(((const str_t *)prm)->data, ((const str_t *)prm)->len);
adderror("'");
break;
case ERROR__NO_BYTE_ADDR:
case ERROR__NO_WORD_ADDR:
case ERROR__NO_LONG_ADDR:
adderror(terr_error[no - 0x40]);
err_opcode(*(const uint32_t *)prm);
break;
default:
adderror(terr_error[no - 0x40]);
}
if (more) new_error_msg_more();
return;
}
more = new_error_msg(SV_FATAL, current_file_list, epoint);
switch (no) {
case ERROR_UNKNOWN_OPTIO:
adderror("unknown option '");
adderror2(((const str_t *)prm)->data, ((const str_t *)prm)->len);
adderror("'");
break;
case ERROR__SECTION_ROOT:
adderror("section '");
adderror2(((const str_t *)prm)->data, ((const str_t *)prm)->len);
adderror("' for output not found");
break;
default:
adderror(terr_fatal[no - 0xc0]);
}
if (more) new_error_msg_more();
}
void err_msg(Error_types no, const void* prm) {
err_msg2(no, prm, &lpoint);
}
static void err_msg_str_name(const char *msg, const str_t *name, linepos_t epoint) {
bool more = new_error_msg(SV_ERROR, current_file_list, epoint);
adderror(msg);
if (name != NULL) str_name(name->data, name->len);
if (more) new_error_msg_more();
}
void err_msg_enc_large(uval_t v, linepos_t epoint) {
char msg2[256];
bool more = new_error_msg(SV_ERROR, current_file_list, epoint);
sprintf(msg2, "encoded value %" PRIuval " larger than 8 bit", v);
adderror(msg2);
if (more) new_error_msg_more();
}
void err_msg_big_address(linepos_t epoint) {
Obj *val = get_star_value(current_address->l_address, current_address->l_address_val);
bool more = new_error_msg(SV_ERROR, current_file_list, epoint);
adderror("address not in processor address space ");
err_msg_variable(val);
val_destroy(val);
if (more) new_error_msg_more();
}
static bool err_msg_big_integer(const Error *err) {
char msg2[256];
bool more = new_error_msg_err(err);
sprintf(msg2, terr_error[err->num - 0x40], err->u.intconv.bits);
adderror(msg2);
err_msg_variable(err->u.intconv.val);
return more;
}
static void new_error_msg_err_more(const Error *err) {
struct errorentry_s *tmp = new_error_msg_common(err->line);
tmp->severity = SV_NOTE;
tmp->file_list = err->file_list;
tmp->epoint = err->epoint;
tmp->caret = (err->line == NULL) ? err->epoint.pos : err->caret;
adderror("original location in an expanded macro was here");
}
static bool err_msg_invalid_conv(const Error *err) {
bool more;
Obj *v1 = err->u.conv.val;
if (v1->obj == ERROR_OBJ) {
err_msg_output(Error(v1));
return false;
}
more = new_error_msg_err(err);
adderror("conversion of ");
err_msg_variable(v1);
adderror(" to ");
adderror(err->u.conv.t->name);
adderror(" is not possible");
return more;
}
static FAST_CALL int notdefines_compare(const struct avltree_node *aa, const struct avltree_node *bb)
{
const struct notdefines_s *a = cavltree_container_of(aa, struct notdefines_s, node);
const struct notdefines_s *b = cavltree_container_of(bb, struct notdefines_s, node);
if (a->file_list != b->file_list) return a->file_list > b->file_list ? 1 : -1;
if (a->epoint.line != b->epoint.line) return a->epoint.line > b->epoint.line ? 1 : -1;
if (a->epoint.pos != b->epoint.pos) return a->epoint.pos > b->epoint.pos ? 1 : -1;
return str_cmp(&a->cfname, &b->cfname);
}
static void notdefines_free(struct avltree_node *aa) {
struct notdefines_s *a = avltree_container_of(aa, struct notdefines_s, node);
free((uint8_t *)a->cfname.data);
free(a);
}
static struct notdefines_s *lastnd;
static void err_msg_not_defined3(const Error *err) {
Namespace *l = err->u.notdef.names;
struct notdefines_s *tmp2;
struct avltree_node *b;
bool more;
if (constcreated && pass < max_pass) return;
if (lastnd == NULL) new_instance(&lastnd);
if (err->u.notdef.symbol->obj == SYMBOL_OBJ) {
const str_t *name = &Symbol(err->u.notdef.symbol)->name;
str_cfcpy(&lastnd->cfname, name);
lastnd->file_list = l->file_list;
lastnd->epoint = l->epoint;
lastnd->pass = pass;
b = avltree_insert(&lastnd->node, ¬defines, notdefines_compare);
if (b != NULL) {
tmp2 = avltree_container_of(b, struct notdefines_s, node);
if (tmp2->pass == pass) {
return;
}
tmp2->pass = pass;
} else {
if (lastnd->cfname.data == name->data) str_cpy(&lastnd->cfname, name);
else str_cfcpy(&lastnd->cfname, NULL);
lastnd = NULL;
}
}
more = new_error_msg_err(err);
adderror("not defined ");
err_msg_variable(err->u.notdef.symbol);
if (more) new_error_msg_err_more(err);
if (l->file_list == NULL) {
struct linepos_s nopoint = {0, 0};
new_error_msg(SV_NOTE, err->file_list, &nopoint);
adderror("searched in the global scope");
} else {
new_error_msg(SV_NOTE, l->file_list, &l->epoint);
if (err->u.notdef.down) adderror("searched in this scope and in all it's parents");
else adderror("searched in this object only");
}
}
void err_msg_not_defined2(const str_t *name, Namespace *l, bool down, linepos_t epoint) {
Error *err = new_error(ERROR___NOT_DEFINED, epoint);
err->u.notdef.down = down;
err->u.notdef.names = ref_namespace(l);
err->u.notdef.symbol = new_symbol(name, epoint);
err_msg_not_defined3(err);
val_destroy(Obj(err));
}
void err_msg_not_defined2a(ssize_t count, Namespace *l, bool down, linepos_t epoint) {
Error *err = new_error(ERROR___NOT_DEFINED, epoint);
err->u.notdef.down = down;
err->u.notdef.names = ref_namespace(l);
err->u.notdef.symbol = new_anonsymbol(count);
err_msg_not_defined3(err);
val_destroy(Obj(err));
}
static void err_opcode(uint32_t cod) {
adderror(" addressing mode ");
if (cod != 0) {
char tmp[17];
memcpy(tmp, "for opcode 'xxx'", sizeof tmp);
tmp[12] = (char)(cod >> 16);
tmp[13] = (char)(cod >> 8);
tmp[14] = (char)cod;
adderror(tmp);
} else adderror("accepted");
}
static void err_msg_no_addressing(atype_t addrtype, uint32_t cod) {
adderror("no");
if (addrtype == A_NONE) adderror(" implied");
for (; (addrtype & MAX_ADDRESS_MASK) != 0; addrtype <<= 4) {
const char *txt;
switch ((Address_types)((addrtype & 0xf000) >> 12)) {
case A_NONE: continue;
case A_IMMEDIATE: txt = " immediate"; break;
case A_IMMEDIATE_SIGNED: txt = " signed immediate"; break;
case A_XR: txt = " x indexed"; break;
case A_YR: txt = " y indexed"; break;
case A_ZR: txt = " z indexed"; break;
case A_SR: txt = " stack"; break;
case A_RR: txt = " data stack"; break;
case A_DR: txt = " direct page"; break;
case A_BR: txt = " data bank"; break;
case A_KR: txt = " program bank"; break;
case A_I: txt = " indirect"; break;
case A_LI: txt = " long indirect"; break;
default: txt = "?"; break;
}
adderror(txt);
}
err_opcode(cod);
}
static bool err_msg_no_register(const Error *err) {
bool more = new_error_msg_err(err);
Register *val = err->u.reg.reg;
adderror("no register '");
adderror2(val->data, val->len);
adderror("'");
err_opcode(err->u.reg.cod);
return more;
}
static bool err_msg_no_lot_operand(const Error *err) {
char msg2[256];
bool more = new_error_msg_err(err);
sprintf(msg2, "no %" PRIuSIZE " operand", err->u.opers.num);
adderror(msg2);
err_opcode(err->u.opers.cod);
return more;
}
static bool err_msg_cant_broadcast(const Error *err) {
char msg2[256];
bool more = new_error_msg_err(err);
sprintf(msg2, "operands could not be broadcast together with shapes %" PRIuSIZE " and %" PRIuSIZE, err->u.broadcast.v1, err->u.broadcast.v2);
adderror(msg2);
return more;
}
static void err_msg_invalid_oper2(Oper_types op, Obj *v1, Obj *v2) {
adderror(operators[op].name);
adderror("' of ");
err_msg_variable(v1);
if (v2 != NULL) {
adderror(" and ");
err_msg_variable(v2);
}
adderror(" not possible");
}
static void err_msg_invalid_oper3(const Error *err) {
Obj *v1 = err->u.invoper.v1, *v2;
bool more;
if (v1->obj == ERROR_OBJ) {
err_msg_output(Error(v1));
return;
}
v2 = err->u.invoper.v2;
if (v2 != NULL && v2->obj == ERROR_OBJ) {
err_msg_output(Error(v2));
return;
}
more = new_error_msg_err(err);
err_msg_invalid_oper2(err->u.invoper.op, v1, v2);
if (more) new_error_msg_err_more(err);
}
static bool err_msg_still_none2(const Error *err) {
struct errorentry_s *e;
bool more;
if ((constcreated || !fixeddig) && pass < max_pass) return false;
more = new_error_msg_err(err);
e = (struct errorentry_s *)&error_list.data[error_list.header_pos];
e->severity = SV_NONEERROR;
adderror("can't calculate this");
return more;
}
static void err_msg_argnum2(argcount_t num, argcount_t min, argcount_t max) {
argcount_t n;
char line[1024];
adderror("expected ");
n = min;
if (min == max) { if (min != 0) adderror("exactly "); }
else if (num < min) adderror("at least ");
else {n = max; adderror("at most "); }
switch (n) {
case 0: adderror("no arguments"); break;
case 1: adderror("one argument"); break;
default: sprintf(line, "%" PRIuargcount " arguments", n); adderror(line); break;
}
if (num != 0) {
sprintf(line, ", got %" PRIuargcount, num);
adderror(line);
}
}
static void err_msg_wrong_type(const Type *typ, const Type *expected, linepos_t epoint) {
bool more = new_error_msg(SV_ERROR, current_file_list, epoint);
adderror("wrong type '");
adderror(typ->name);
if (expected != NULL) {
adderror("', expected '");
adderror(expected->name);
}
adderror("'");
if (more) new_error_msg_more();
}
void err_msg_output(const Error *val) {
bool more = false;
switch (val->num) {
case ERROR___NOT_DEFINED: err_msg_not_defined3(val);break;
case ERROR__INVALID_CONV: more = err_msg_invalid_conv(val);break;
case ERROR__INVALID_OPER: err_msg_invalid_oper3(val);break;
case ERROR____STILL_NONE: more = err_msg_still_none2(val); break;
case ERROR____CANT_IVAL2:
case ERROR____CANT_UVAL2:
case ERROR_____CANT_IVAL:
case ERROR_____CANT_UVAL: more = err_msg_big_integer(val); break;
case ERROR_REQUIREMENTS_:
case ERROR______CONFLICT:
case ERROR_NUMERIC_OVERF:
case ERROR_NEGFRAC_POWER:
case ERROR___EMPTY_RANGE:
case ERROR__EMPTY_STRING:
case ERROR____EMPTY_LIST:
case ERROR__BYTES_NEEDED:
case ERROR___NO_LAST_GAP:
case ERROR_NO_ZERO_VALUE:
case ERROR_OUT_OF_MEMORY:
case ERROR__ADDR_COMPLEX:
case ERROR_NEGATIVE_SIZE: more = new_error_msg_err(val); adderror(terr_error[val->num - 0x40]); break;
case ERROR_NO_ADDRESSING: more = new_error_msg_err(val); err_msg_no_addressing(val->u.addressing.am, val->u.addressing.cod);break;
case ERROR___NO_REGISTER: more = err_msg_no_register(val);break;
case ERROR___NO_LOT_OPER: more = err_msg_no_lot_operand(val);break;
case ERROR_CANT_BROADCAS: more = err_msg_cant_broadcast(val);break;
case ERROR__NO_BYTE_ADDR:
case ERROR__NO_WORD_ADDR:
case ERROR__NO_LONG_ADDR: more = new_error_msg_err(val); adderror(terr_error[val->num - 0x40]); err_opcode(val->u.addresssize.cod); break;
case ERROR______NOT_UVAL:
case ERROR__NOT_ONE_CHAR:
case ERROR_DIVISION_BY_Z:
case ERROR_ZERO_NEGPOWER:
case ERROR__NOT_KEYVALUE:
case ERROR__NOT_HASHABLE:
case ERROR_____CANT_SIGN:
case ERROR______CANT_ABS:
case ERROR______CANT_INT:
case ERROR______CANT_LEN:
case ERROR_____CANT_SIZE:
case ERROR_____CANT_BOOL:
case ERROR______NOT_ITER:
case ERROR___MATH_DOMAIN:
case ERROR_LOG_NON_POSIT:
case ERROR_SQUARE_ROOT_N:
case ERROR___INDEX_RANGE:
case ERROR_____KEY_ERROR: more = new_error_msg_err(val); adderror(terr_error[val->num - 0x40]); err_msg_variable(val->u.obj);break;
case ERROR__WRONG_ARGNUM: more = new_error_msg_err(val); err_msg_argnum2(val->u.argnum.num, val->u.argnum.min, val->u.argnum.max); break;
case ERROR____WRONG_TYPE: err_msg_wrong_type(val->u.otype.t1, val->u.otype.t2, &val->epoint); break;
default: break;
}
if (more) new_error_msg_err_more(val);
}
void err_msg_output_and_destroy(Error *val) {
err_msg_output(val);
val_destroy(Obj(val));
}
void err_msg_wrong_type2(const Obj *val, Type *expected, linepos_t epoint) {
if (val->obj == ERROR_OBJ) err_msg_output(Error(val));
else if (val == none_value) err_msg_still_none(NULL, epoint);
else err_msg_wrong_type(val->obj, expected, epoint);
}
void err_msg_invalid_namespace_conv(const struct values_s *vs) {
Obj *val = vs->val;
if (val->obj == ERROR_OBJ) err_msg_output(Error(val));
else if (val == none_value) err_msg_still_none(NULL, &vs->epoint);
else err_msg_output_and_destroy(Error(new_error_conv(val, NAMESPACE_OBJ, &vs->epoint)));
}
void err_msg_cant_unpack(size_t expect, size_t got, linepos_t epoint) {
char line[1024];
bool more = new_error_msg(SV_ERROR, current_file_list, epoint);
sprintf(line, "expected %" PRIuSIZE " values but got %" PRIuSIZE " to unpack", expect, got);
adderror(line);
if (more) new_error_msg_more();
}
void err_msg_cant_calculate(const str_t *name, linepos_t epoint) {
err_msg_str_name("can't calculate stable value", name, epoint);