File: GrcErrorList.h

package info (click to toggle)
grcompiler 4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,076 kB
  • ctags: 5,163
  • sloc: cpp: 45,565; sh: 4,451; ansic: 4,377; makefile: 185; xml: 175; perl: 127
file content (339 lines) | stat: -rw-r--r-- 12,333 bytes parent folder | download | duplicates (4)
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
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: GrcErrorList.h
Responsibility: Sharon Correll
Last reviewed: Not yet.

Description:
    Classes to implement the list of errors accumulated during the post-parser and pre-compiler.
-------------------------------------------------------------------------------*//*:End Ignore*/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef ERRORS_INCLUDED
#define ERRORS_INCLUDED

/*----------------------------------------------------------------------------------------------
Class: GrcErrorItem
Description: An error generated during the post-parser or pre-compiler.
Hungarian: err
----------------------------------------------------------------------------------------------*/

class GrcErrorItem
{
	friend class GrcErrorList;

public:
	GrcErrorItem(bool fFatal, int nID, GrpLineAndFile & lnf, std::string staMsg, GdlObject * pgdlObj)
		:	m_nID(nID),
			m_pgdlObject(pgdlObj),
			m_staMsg(staMsg),
			m_fFatal(fFatal),
			m_fMsgIncludesFatality(false),
			m_lnf(lnf)
	{
	}

	bool Equivalent(GrcErrorItem * perr)
	{
		return ( //// m_pgdlObject == perr->m_pgdlObject &&
			m_nID == perr->m_nID
			&& m_staMsg == perr->m_staMsg
			&& m_lnf == perr->m_lnf
			&& m_fFatal == perr->m_fFatal);
	}

	int PreProcessedLine()
	{
		return m_lnf.PreProcessedLine();
	}

protected:
	//	instance variables:
	int				m_nID;
	GdlObject *		m_pgdlObject;
	std::string		m_staMsg;
	bool			m_fFatal;
	bool			m_fMsgIncludesFatality;		// don't add label "warning" or "error--the
												// message itself includes the information
	GrpLineAndFile	m_lnf;
};

/*----------------------------------------------------------------------------------------------
Class: GrcErrorList
Description: Database of errors accumulated during post-parser and pre-compiler. There is only
	a single instance of this class.
Hungarian: 
----------------------------------------------------------------------------------------------*/

class GrcErrorList
{
	friend class GrcErrorItem;

public:
	GrcErrorList()
	{
		m_fFatalError = false;
	}

	~GrcErrorList()
	{
		for (size_t i = 0; i < m_vperr.size(); ++i)
			delete m_vperr[i];
	}

	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, staMsg);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, &staMsg, &sta2, NULL, NULL, NULL, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, NULL, NULL, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, NULL, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5,
		GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5, std::string sta6,
		GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5, std::string sta6, std::string sta7,
		GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5, std::string sta6, std::string sta7, std::string sta8,
		GrpLineAndFile const& lnf)
	{
		AddItem(true, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, &sta8);
	}


	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg)
	{
		AddItem(true, nID, pgdlobj, NULL, staMsg);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2)
	{
		AddItem(true, nID, pgdlobj, NULL, &staMsg, &sta2, NULL, NULL, NULL, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3)
	{
		AddItem(true, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, NULL, NULL, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4)
	{
		AddItem(true, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, NULL, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5)
	{
		AddItem(true, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, NULL, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5, std::string sta6)
	{
		AddItem(true, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, NULL, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5, std::string sta6, std::string sta7)
	{
		AddItem(true, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, NULL);
	}
	void AddError(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3, std::string sta4,
		std::string sta5, std::string sta6, std::string sta7, std::string sta8)
	{
		AddItem(true, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, &sta8);
	}


	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, GrpLineAndFile const& lnf)
	{
		AddItem(false,nID,  pgdlobj, &lnf, staMsg);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, GrpLineAndFile const& lnf)
	{
		AddItem(false, nID, pgdlobj, &lnf, &staMsg, &sta2, NULL, NULL, NULL, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		GrpLineAndFile const& lnf)
	{
		AddItem(false, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, NULL, NULL, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4,
		GrpLineAndFile const& lnf)
	{
		AddItem(false, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, NULL, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5,
		GrpLineAndFile const& lnf)
	{
		AddItem(false, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5, std::string sta6,
		GrpLineAndFile const& lnf)
	{
		AddItem(false, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5, std::string sta6, std::string sta7,
		GrpLineAndFile const& lnf)
	{
		AddItem(false, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5, std::string sta6, std::string sta7, std::string sta8,
		GrpLineAndFile const& lnf)
	{
		AddItem(false, nID, pgdlobj, &lnf, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, &sta8);
	}


	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg)
	{
		AddItem(false, nID, pgdlobj, NULL, staMsg);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2)
	{
		AddItem(false, nID, pgdlobj, NULL, &staMsg, &sta2, NULL, NULL, NULL, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3)
	{
		AddItem(false, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, NULL, NULL, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4)
	{
		AddItem(false, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, NULL, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5)
	{
		AddItem(false, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, NULL, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5, std::string sta6)
	{
		AddItem(false, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, NULL, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5, std::string sta6, std::string sta7)
	{
		AddItem(false, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, NULL);
	}
	void AddWarning(int nID, GdlObject * pgdlobj, std::string staMsg, std::string sta2, std::string sta3,
		std::string sta4, std::string sta5, std::string sta6, std::string sta7, std::string sta8)
	{
		AddItem(false, nID, pgdlobj, NULL, &staMsg, &sta2, &sta3, &sta4, &sta5, &sta6, &sta7, &sta8);
	}

	void AddItem(bool fFatal, int nID, GdlObject * pgdlobj, const GrpLineAndFile *, std::string staMsg);
	void AddItem(bool fFatal, int nID, GdlObject * pgdlobj, const GrpLineAndFile *,
		std::string * psta1, std::string * psta2, std::string * psta3, std::string * psta4,
		std::string * psta5, std::string * psta6, std::string * psta7, std::string * psta8);

	void SortErrors();
	int NumberOfErrors()
	{
		return m_vperr.size();
	}
	int ErrorsAtLine(int nLine);
	int ErrorsAtLine(int nLine, int * piperrFirst);

	bool AnyFatalErrors()
	{
		return m_fFatalError;
	}

	int NumberOfWarnings();
	int NumberOfWarningsGiven();

	bool IsFatal(int iperr)
	{
		return m_vperr[iperr]->m_fFatal;
	}

	void SetIgnoreWarning(int nID, bool f = true);
	bool IgnoreWarning(int nID);
	void ClearIgnoreWarnings();

	void SetLastMsgIncludesFatality(bool f)
	{
		m_vperr.back()->m_fMsgIncludesFatality = f;
	}

	void WriteErrorsToFile(std::string staGdlFile, std::string staInputFontFile,
		std::string staOutputFile, std::string staOutputFamily, std::string staVersion, int fSepCtrlFile)
	{
		WriteErrorsToFile(m_strErrFile, staGdlFile, staInputFontFile, staOutputFile, staOutputFamily,
			staVersion, fSepCtrlFile);
	}
	void WriteErrorsToFile(std::string staErrFile, std::string staGdlFile, std::string staInputFontFile,
		std::string staOutputFile, std::string staOutputFamily,
		std::string staVersion, bool fSepCtrlFile);
	void WriteErrorsToStream(std::ostream&, std::string staGdlFile, std::string staInputFontFile,
		std::string staOutputFile, std::string staOutputFamily,
		std::string staVersion, bool fSepCtrlFile);

	void SetFileNameFromGdlFile(char * pchGdlFile);

	void WriteTableVersionsGenerated(std::ostream& strmOut);

protected:
	//	instance variables:
	bool m_fFatalError;

	std::vector<GrcErrorItem *> m_vperr;

	std::vector<int> m_vnIgnoreWarnings;

	std::string m_strErrFile;

public:
	//	For test procedures:
	bool test_ErrorIs(int iperr, std::string staMsg)
	{
		return (m_vperr[iperr]->m_staMsg == staMsg);
	}

	void test_Clear()
	{
		for (size_t i = 0; i < m_vperr.size(); ++i)
		{
			delete m_vperr[i];
		}
		m_vperr.clear();
		m_fFatalError = false;
	}
};


void AddGlobalError(bool fFatal, int nID, std::string msg, int nLine);
void AddGlobalError(bool fFatal, int nID, std::string msg, GrpLineAndFile const&);


#endif // ERRORS_INCLUDED