Imported Upstream version 1.8.8
[platform/upstream/doxygen.git] / vhdlparser / ParseException.cc
1 /* Generated By:JavaCC: Do not edit this line. ParseException.cc Version 6.0 */
2 /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3 #include "ParseException.h"
4
5
6 namespace vhdl {
7 namespace parser {
8 /**
9  * This exception is thrown when parse errors are encountered.
10  * You can explicitly create objects of this exception type by
11  * calling the method generate_ParseException in the generated
12  * parser.
13  *
14  * You can modify this class to customize your error reporting
15  * mechanisms so long as you retain the fields.
16  */
17
18   /**
19    * This constructor is used by the method "generate_ParseException"
20    * in the generated parser.  Calling this constructor generates
21    * a new object of this type with the fields "currentToken",
22    * "expectedTokenSequences", and "tokenImage" set.
23    */
24   ParseException::ParseException(Token currentTokenVal,
25                         int** expectedTokenSequencesVal,
26                         JAVACC_STRING_TYPE* tokenImageVal
27                        )
28   {
29     initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal);
30     currentToken = currentTokenVal;
31     expectedTokenSequences = expectedTokenSequencesVal;
32     tokenImage = tokenImageVal;
33   }
34
35   /**
36    * The following constructors are for use by you for whatever
37    * purpose you can think of.  Constructing the exception in this
38    * manner makes the exception behave in the normal way - i.e., as
39    * documented in the class "Throwable".  The fields "errorToken",
40    * "expectedTokenSequences", and "tokenImage" do not contain
41    * relevant information.  The JavaCC generated code does not use
42    * these constructors.
43    */
44
45   ParseException::ParseException() {
46   }
47
48   /** Constructor with message. */
49   ParseException::ParseException(JAVACC_STRING_TYPE message) {
50   }
51
52
53   /**
54    * This is the last token that has been consumed successfully.  If
55    * this object has been created due to a parse error, the token
56    * followng this token will (therefore) be the first error token.
57    */
58   Token currentToken;
59
60   /**
61    * Each entry in this array is an array of integers.  Each array
62    * of integers represents a sequence of tokens (by their ordinal
63    * values) that is expected at this point of the parse.
64    */
65   int** expectedTokenSequences;
66
67   /**
68    * This is a reference to the "tokenImage" array of the generated
69    * parser within which the parse error occurred.  This array is
70    * defined in the generated ...Constants class.
71    */
72   JAVACC_STRING_TYPE* tokenImage;
73
74   /**
75    * It uses "currentToken" and "expectedTokenSequences" to generate a parse
76    * error message and returns it.  If this object has been created
77    * due to a parse error, and you do not catch it (it gets thrown
78    * from the parser) the correct error message
79    * gets displayed.
80    */
81   JAVACC_STRING_TYPE ParseException::initialise(Token currentToken,
82                            int** expectedTokenSequences,
83                            JAVACC_STRING_TYPE* tokenImage) {
84 #if 0
85     //JAVACC_STRING_TYPE eol = System.getProperty("line.separator", "\n");
86      expected = new JAVACC_STRING_TYPE();
87     int maxSize = 0;
88     for (int i = 0; i < expectedTokenSequences.length; i++) {
89       if (maxSize < expectedTokenSequences[i].length) {
90         maxSize = expectedTokenSequences[i].length;
91       }
92       for (int j = 0; j < expectedTokenSequences[i].length; j++) {
93         expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
94       }
95       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
96         expected.append((JAVACC_CHAR_TYPE*)"...");
97       }
98       expected.append(eol).append("    ");
99     }
100     JAVACC_STRING_TYPE retval = (JAVACC_CHAR_TYPE*)"Encountered \"";
101     Token tok = currentToken.next;
102     for (int i = 0; i < maxSize; i++) {
103       if (i != 0) retval += (JAVACC_CHAR_TYPE*)" ";
104       if (tok.kind == 0) {
105         retval += tokenImage[0];
106         break;
107       }
108       retval += (JAVACC_CHAR_TYPE*)" " + tokenImage[tok.kind];
109       retval += (JAVACC_CHAR_TYPE*)" \"";
110       retval += add_escapes(tok.image);
111       retval += (JAVACC_CHAR_TYPE*)" \"";
112       tok = tok.next;
113     }
114     retval += (JAVACC_CHAR_TYPE*)"\" at line " + currentToken.next.beginLine + (JAVACC_CHAR_TYPE*)", column " + currentToken.next.beginColumn;
115     retval += (JAVACC_CHAR_TYPE*)"." + eol;
116     if (expectedTokenSequences.length == 1) {
117       retval += (JAVACC_CHAR_TYPE*)"Was expecting:" + eol + (JAVACC_CHAR_TYPE*)"    ";
118     } else {
119       retval += (JAVACC_CHAR_TYPE*)"Was expecting one of:" + eol + (JAVACC_CHAR_TYPE*)"    ";
120     }
121     retval += expected.toString();
122     return retval;
123 #endif
124     return (JAVACC_CHAR_TYPE*)"Parse exception";
125   }
126
127   /**
128    * The end of line JAVACC_STRING_TYPE for this machine.
129    */
130 #define eol "\n"
131
132   /**
133    * Used to convert raw characters to their escaped version
134    * when these raw version cannot be used as part of an ASCII
135    * string literal.
136    */
137    JAVACC_STRING_TYPE ParseException::add_escapes(JAVACC_STRING_TYPE str) {
138 /*
139       JAVACC_STRING_TYPE *retval = new JAVACC_STRING_TYPE();
140       JAVACC_CHAR_TYPE ch;
141       for (int i = 0; i < str.length(); i++) {
142         switch (str.charAt(i))
143         {
144            case 0 :
145               continue;
146            case '\b':
147               retval.append("\\b");
148               continue;
149            case '\t':
150               retval.append("\\t");
151               continue;
152            case '\n':
153               retval.append("\\n");
154               continue;
155            case '\f':
156               retval.append("\\f");
157               continue;
158            case '\r':
159               retval.append("\\r");
160               continue;
161            case '\"':
162               retval.append("\\\"");
163               continue;
164            case '\'':
165               retval.append("\\\'");
166               continue;
167            case '\\':
168               retval.append("\\\\");
169               continue;
170            default:
171               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
172                  JAVACC_STRING_TYPE s = "0000" + Integer.toString(ch, 16);
173                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
174               } else {
175                  retval.append(ch);
176               }
177               continue;
178         }
179       }
180       return retval.toString();
181 */ return str;
182    }
183
184 }
185 }
186 /* JavaCC - OriginalChecksum=99d488e13335cf377284c90700f070ed (do not edit this line) */