PageRenderTime 30ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/hadoop-1.1.2/src/core/org/apache/hadoop/record/compiler/generated/SimpleCharStream.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 439 lines | 347 code | 67 blank | 25 comment | 42 complexity | 9d86e98ad897b66e6e04bd9857dbf15f MD5 | raw file
  1. /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */
  2. /**
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. package org.apache.hadoop.record.compiler.generated;
  20. /**
  21. * An implementation of interface CharStream, where the stream is assumed to
  22. * contain only ASCII characters (without unicode processing).
  23. */
  24. public class SimpleCharStream
  25. {
  26. public static final boolean staticFlag = false;
  27. int bufsize;
  28. int available;
  29. int tokenBegin;
  30. public int bufpos = -1;
  31. protected int bufline[];
  32. protected int bufcolumn[];
  33. protected int column = 0;
  34. protected int line = 1;
  35. protected boolean prevCharIsCR = false;
  36. protected boolean prevCharIsLF = false;
  37. protected java.io.Reader inputStream;
  38. protected char[] buffer;
  39. protected int maxNextCharInd = 0;
  40. protected int inBuf = 0;
  41. protected int tabSize = 8;
  42. protected void setTabSize(int i) { tabSize = i; }
  43. protected int getTabSize(int i) { return tabSize; }
  44. protected void ExpandBuff(boolean wrapAround)
  45. {
  46. char[] newbuffer = new char[bufsize + 2048];
  47. int newbufline[] = new int[bufsize + 2048];
  48. int newbufcolumn[] = new int[bufsize + 2048];
  49. try
  50. {
  51. if (wrapAround)
  52. {
  53. System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
  54. System.arraycopy(buffer, 0, newbuffer,
  55. bufsize - tokenBegin, bufpos);
  56. buffer = newbuffer;
  57. System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
  58. System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
  59. bufline = newbufline;
  60. System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
  61. System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
  62. bufcolumn = newbufcolumn;
  63. maxNextCharInd = (bufpos += (bufsize - tokenBegin));
  64. }
  65. else
  66. {
  67. System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
  68. buffer = newbuffer;
  69. System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
  70. bufline = newbufline;
  71. System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
  72. bufcolumn = newbufcolumn;
  73. maxNextCharInd = (bufpos -= tokenBegin);
  74. }
  75. }
  76. catch (Throwable t)
  77. {
  78. throw new Error(t.getMessage());
  79. }
  80. bufsize += 2048;
  81. available = bufsize;
  82. tokenBegin = 0;
  83. }
  84. protected void FillBuff() throws java.io.IOException
  85. {
  86. if (maxNextCharInd == available)
  87. {
  88. if (available == bufsize)
  89. {
  90. if (tokenBegin > 2048)
  91. {
  92. bufpos = maxNextCharInd = 0;
  93. available = tokenBegin;
  94. }
  95. else if (tokenBegin < 0)
  96. bufpos = maxNextCharInd = 0;
  97. else
  98. ExpandBuff(false);
  99. }
  100. else if (available > tokenBegin)
  101. available = bufsize;
  102. else if ((tokenBegin - available) < 2048)
  103. ExpandBuff(true);
  104. else
  105. available = tokenBegin;
  106. }
  107. int i;
  108. try {
  109. if ((i = inputStream.read(buffer, maxNextCharInd,
  110. available - maxNextCharInd)) == -1)
  111. {
  112. inputStream.close();
  113. throw new java.io.IOException();
  114. }
  115. else
  116. maxNextCharInd += i;
  117. return;
  118. }
  119. catch(java.io.IOException e) {
  120. --bufpos;
  121. backup(0);
  122. if (tokenBegin == -1)
  123. tokenBegin = bufpos;
  124. throw e;
  125. }
  126. }
  127. public char BeginToken() throws java.io.IOException
  128. {
  129. tokenBegin = -1;
  130. char c = readChar();
  131. tokenBegin = bufpos;
  132. return c;
  133. }
  134. protected void UpdateLineColumn(char c)
  135. {
  136. column++;
  137. if (prevCharIsLF)
  138. {
  139. prevCharIsLF = false;
  140. line += (column = 1);
  141. }
  142. else if (prevCharIsCR)
  143. {
  144. prevCharIsCR = false;
  145. if (c == '\n')
  146. {
  147. prevCharIsLF = true;
  148. }
  149. else
  150. line += (column = 1);
  151. }
  152. switch (c)
  153. {
  154. case '\r' :
  155. prevCharIsCR = true;
  156. break;
  157. case '\n' :
  158. prevCharIsLF = true;
  159. break;
  160. case '\t' :
  161. column--;
  162. column += (tabSize - (column % tabSize));
  163. break;
  164. default :
  165. break;
  166. }
  167. bufline[bufpos] = line;
  168. bufcolumn[bufpos] = column;
  169. }
  170. public char readChar() throws java.io.IOException
  171. {
  172. if (inBuf > 0)
  173. {
  174. --inBuf;
  175. if (++bufpos == bufsize)
  176. bufpos = 0;
  177. return buffer[bufpos];
  178. }
  179. if (++bufpos >= maxNextCharInd)
  180. FillBuff();
  181. char c = buffer[bufpos];
  182. UpdateLineColumn(c);
  183. return (c);
  184. }
  185. public int getEndColumn() {
  186. return bufcolumn[bufpos];
  187. }
  188. public int getEndLine() {
  189. return bufline[bufpos];
  190. }
  191. public int getBeginColumn() {
  192. return bufcolumn[tokenBegin];
  193. }
  194. public int getBeginLine() {
  195. return bufline[tokenBegin];
  196. }
  197. public void backup(int amount) {
  198. inBuf += amount;
  199. if ((bufpos -= amount) < 0)
  200. bufpos += bufsize;
  201. }
  202. public SimpleCharStream(java.io.Reader dstream, int startline,
  203. int startcolumn, int buffersize)
  204. {
  205. inputStream = dstream;
  206. line = startline;
  207. column = startcolumn - 1;
  208. available = bufsize = buffersize;
  209. buffer = new char[buffersize];
  210. bufline = new int[buffersize];
  211. bufcolumn = new int[buffersize];
  212. }
  213. public SimpleCharStream(java.io.Reader dstream, int startline,
  214. int startcolumn)
  215. {
  216. this(dstream, startline, startcolumn, 4096);
  217. }
  218. public SimpleCharStream(java.io.Reader dstream)
  219. {
  220. this(dstream, 1, 1, 4096);
  221. }
  222. public void ReInit(java.io.Reader dstream, int startline,
  223. int startcolumn, int buffersize)
  224. {
  225. inputStream = dstream;
  226. line = startline;
  227. column = startcolumn - 1;
  228. if (buffer == null || buffersize != buffer.length)
  229. {
  230. available = bufsize = buffersize;
  231. buffer = new char[buffersize];
  232. bufline = new int[buffersize];
  233. bufcolumn = new int[buffersize];
  234. }
  235. prevCharIsLF = prevCharIsCR = false;
  236. tokenBegin = inBuf = maxNextCharInd = 0;
  237. bufpos = -1;
  238. }
  239. public void ReInit(java.io.Reader dstream, int startline,
  240. int startcolumn)
  241. {
  242. ReInit(dstream, startline, startcolumn, 4096);
  243. }
  244. public void ReInit(java.io.Reader dstream)
  245. {
  246. ReInit(dstream, 1, 1, 4096);
  247. }
  248. public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
  249. int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
  250. {
  251. this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  252. }
  253. public SimpleCharStream(java.io.InputStream dstream, int startline,
  254. int startcolumn, int buffersize)
  255. {
  256. this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  257. }
  258. public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
  259. int startcolumn) throws java.io.UnsupportedEncodingException
  260. {
  261. this(dstream, encoding, startline, startcolumn, 4096);
  262. }
  263. public SimpleCharStream(java.io.InputStream dstream, int startline,
  264. int startcolumn)
  265. {
  266. this(dstream, startline, startcolumn, 4096);
  267. }
  268. public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
  269. {
  270. this(dstream, encoding, 1, 1, 4096);
  271. }
  272. public SimpleCharStream(java.io.InputStream dstream)
  273. {
  274. this(dstream, 1, 1, 4096);
  275. }
  276. public void ReInit(java.io.InputStream dstream, String encoding, int startline,
  277. int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
  278. {
  279. ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  280. }
  281. public void ReInit(java.io.InputStream dstream, int startline,
  282. int startcolumn, int buffersize)
  283. {
  284. ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  285. }
  286. public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
  287. {
  288. ReInit(dstream, encoding, 1, 1, 4096);
  289. }
  290. public void ReInit(java.io.InputStream dstream)
  291. {
  292. ReInit(dstream, 1, 1, 4096);
  293. }
  294. public void ReInit(java.io.InputStream dstream, String encoding, int startline,
  295. int startcolumn) throws java.io.UnsupportedEncodingException
  296. {
  297. ReInit(dstream, encoding, startline, startcolumn, 4096);
  298. }
  299. public void ReInit(java.io.InputStream dstream, int startline,
  300. int startcolumn)
  301. {
  302. ReInit(dstream, startline, startcolumn, 4096);
  303. }
  304. public String GetImage()
  305. {
  306. if (bufpos >= tokenBegin)
  307. return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
  308. else
  309. return new String(buffer, tokenBegin, bufsize - tokenBegin) +
  310. new String(buffer, 0, bufpos + 1);
  311. }
  312. public char[] GetSuffix(int len)
  313. {
  314. char[] ret = new char[len];
  315. if ((bufpos + 1) >= len)
  316. System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
  317. else
  318. {
  319. System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
  320. len - bufpos - 1);
  321. System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
  322. }
  323. return ret;
  324. }
  325. public void Done()
  326. {
  327. buffer = null;
  328. bufline = null;
  329. bufcolumn = null;
  330. }
  331. /**
  332. * Method to adjust line and column numbers for the start of a token.
  333. */
  334. public void adjustBeginLineColumn(int newLine, int newCol)
  335. {
  336. int start = tokenBegin;
  337. int len;
  338. if (bufpos >= tokenBegin)
  339. {
  340. len = bufpos - tokenBegin + inBuf + 1;
  341. }
  342. else
  343. {
  344. len = bufsize - tokenBegin + bufpos + 1 + inBuf;
  345. }
  346. int i = 0, j = 0, k = 0;
  347. int nextColDiff = 0, columnDiff = 0;
  348. while (i < len &&
  349. bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
  350. {
  351. bufline[j] = newLine;
  352. nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
  353. bufcolumn[j] = newCol + columnDiff;
  354. columnDiff = nextColDiff;
  355. i++;
  356. }
  357. if (i < len)
  358. {
  359. bufline[j] = newLine++;
  360. bufcolumn[j] = newCol + columnDiff;
  361. while (i++ < len)
  362. {
  363. if (bufline[j = start % bufsize] != bufline[++start % bufsize])
  364. bufline[j] = newLine++;
  365. else
  366. bufline[j] = newLine;
  367. }
  368. }
  369. line = bufline[j];
  370. column = bufcolumn[j];
  371. }
  372. }