/[ascend]/branches/relerrorlist/ascend/compiler/relerr.c
ViewVC logotype

Contents of /branches/relerrorlist/ascend/compiler/relerr.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3195 - (show annotations) (download) (as text)
Fri Apr 21 09:49:22 2017 UTC (19 months ago) by jpye
File MIME type: text/x-csrc
File size: 4592 byte(s)
little bit more improvement on error reporting

1 /* ASCEND modelling environment
2 Copyright (C) 2017 John Pye
3 Copyright (C) 1996 Benjamin Andrew Allan
4 Copyright (C) 1994, 1995 Kirk Andre' Abbott
5 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *//** @file Error-reporting functions for the compiler
20 */
21
22 #include "relerr.h"
23 #include "statio.h"
24 #include "nameio.h"
25 #include <ascend/general/ascMalloc.h>
26 #include <ascend/general/panic.h>
27 #include <ascend/utilities/error.h>
28
29 rel_errorlist *rel_errorlist_new(){
30 rel_errorlist *err = ASC_NEW_CLEAR(rel_errorlist);
31 err->errcode = okay;
32 err->lrcode = lokay;
33 err->ferr = correct_instance;
34 return err;
35 }
36
37
38 void rel_errorlist_destroy(rel_errorlist *err){
39 rel_errorlist_destroy_contents(err);
40 ASC_FREE(err);
41 }
42
43 void rel_errorlist_destroy_contents(rel_errorlist *err){
44 (void)0;
45 }
46
47
48 int rel_errorlist_set_find_error(rel_errorlist *err, enum find_errors ferr){
49 assert(err!=NULL);
50 err->ferr = ferr;
51 err->data.name = NULL;
52 return 0;
53 }
54
55 int rel_errorlist_set_find_error_name(rel_errorlist *err, enum find_errors ferr, const struct Name *errname){
56 assert(err!=NULL);
57 err->ferr = ferr;
58 err->data.name = errname;
59 return 0;
60 }
61
62 int rel_errorlist_set_name(rel_errorlist *err, const struct Name *errname){
63 assert(err!=NULL);
64 assert(err->ferr != correct_instance);
65 err->data.name = errname;
66 return 0;
67 }
68
69 int rel_errorlist_get_find_error(rel_errorlist *err){
70 assert(err!=NULL);
71 return err->ferr;
72 }
73
74
75 int rel_errorlist_set_find_errpos(rel_errorlist *err,unsigned long ferrpos){
76 assert(err!=NULL);
77 err->ferrpos = ferrpos;
78 return 0;
79 }
80
81
82 int rel_errorlist_set_lrcode(rel_errorlist *err, enum logrelation_errorsx lrcode){
83 assert(err!=NULL);
84 err->lrcode = lrcode;
85 return 0;
86 }
87
88
89 int rel_errorlist_get_lrcode(rel_errorlist *err){
90 assert(err!=NULL);
91 return err->lrcode;
92 }
93
94
95 int rel_errorlist_set_code(rel_errorlist *err, enum relation_errorsx errcode){
96 assert(err!=NULL);
97 err->errcode = errcode;
98 return 0;
99 }
100
101
102 int rel_errorlist_get_code(rel_errorlist *err){
103 assert(err!=NULL);
104 return err->errcode;
105 }
106
107 int rel_errorlist_report_error(rel_errorlist *err,struct Statement *stat){
108 char *namestr;
109 //CONSOLE_DEBUG("Reporting error");
110
111 switch(rel_errorlist_get_code(err)){
112
113 case incorrect_structure:
114 WSSM(ASCERR,stat, "Bad relation expression",3);
115 return 1;
116
117 case incorrect_inst_type:
118 WSSM(ASCERR,stat, "Incorrect instance types in relation",3);
119 return 1;
120
121 case incorrect_boolean_inst_type:
122 WSSM(ASCERR,stat, "Incorrect boolean instance in relation",3);
123 return 1;
124
125 case incorrect_integer_inst_type:
126 WSSM(ASCERR,stat, "Incorrect integer instance in relation",3);
127 return 1;
128
129 case incorrect_symbol_inst_type:
130 WSSM(ASCERR,stat, "Incorrect symbol instance in relation",3);
131 return 1;
132
133 case incorrect_real_inst_type:
134 WSSM(ASCERR,stat,
135 "Incorrect real child of atom instance in relation",3);
136 return 1;
137
138 case find_error:
139 switch(rel_errorlist_get_find_error(err)){
140 case unmade_instance:
141 case undefined_instance:
142 if(NULL != err->data.name){
143 namestr = WriteNameString(err->data.name);
144 WriteStatementError(ASC_USER_ERROR,stat,0,"Unmade or undefined instance '%s' in relation.",namestr);
145 ASC_FREE(namestr);
146 }else{
147 WriteStatementError(ASC_USER_ERROR,stat,0,"%s instance in relation (name not reported).",(rel_errorlist_get_find_error(err)==unmade_instance?"Unmade":"Undefined"));
148 }
149 return 1;
150 case impossible_instance:
151 WriteStatementError(ASC_USER_ERROR,stat,1,"Relation contains an impossible instance");
152 return 1;
153 case correct_instance:
154 ASC_PANIC("Incorrect error response.\n");/*NOTREACHED*/
155 default:
156 ASC_PANIC("Unknown error response.\n");/*NOTREACHED*/
157 }
158 case integer_value_undefined:
159 case real_value_wild:
160 case real_value_undefined:
161 WriteStatementError(3,stat,1,"Unassigned constants or wild dimensioned real constant in relation");
162 return 1;
163 case okay:
164 ASC_PANIC("Incorrect 'okay' error response.\n");/*NOTREACHED*/
165 }
166 ASC_PANIC("Unknown error response.\n");/*NOTREACHED*/
167 return -1;
168 }
169
170

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22