/NuSCRtoFBD/src/basefbd/CombineEngine.java

http://fbdtoverilog.googlecode.com/ · Java · 360 lines · 273 code · 33 blank · 54 comment · 158 complexity · a38f33995323b7f8b66315c0443979f7 MD5 · raw file

  1. package basefbd;
  2. import java.util.LinkedList;
  3. import java.util.Queue;
  4. import java.util.Stack;
  5. //import sun.io.Converters;
  6. public class CombineEngine {
  7. public Queue<CondInformation> condsQueue = new LinkedList<CondInformation>();
  8. public Queue<CondInformation> condsQueueSecond = new LinkedList<CondInformation>();
  9. int number = 1;
  10. public void MakeCond(String[] conditions,
  11. Queue<CondInformation> condsQueueLast) {
  12. // condsQueueLast1 = this.condsQueueLast;
  13. for (String condition : conditions) // conditionstring? ??? ??? cond???
  14. // ????.
  15. {
  16. String temp = "";
  17. char c;
  18. boolean isCheckingTimeCondtion = false;
  19. int openCount = 0;
  20. for (int i = 0; i < condition.length(); i++) {
  21. c = condition.charAt(i);
  22. if (condition.charAt(i) == '[') // timecondition? ?? ()?? ???.
  23. {
  24. isCheckingTimeCondtion = true;
  25. while (true) // ??? ? ????? ???.
  26. {
  27. if (condition.charAt(i) == ' '
  28. || condition.charAt(i) == '\n'
  29. || condition.charAt(i) == '\r'
  30. || condition.charAt(i) == '\t') {
  31. i++;
  32. continue;
  33. }
  34. if (condition.charAt(i) == '(')
  35. openCount++;
  36. else if (condition.charAt(i) == ')')
  37. openCount--;
  38. temp += Character.toString(condition.charAt(i));
  39. if (openCount == 0 && condition.charAt(i) == ')')
  40. break;
  41. i++;
  42. if (i >= condition.length())
  43. break;
  44. }
  45. while (i < condition.length()
  46. && (condition.charAt(i) != '|' && condition
  47. .charAt(i) != '&'))
  48. i++;
  49. }
  50. if (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '!')
  51. continue;
  52. if ((c == '(' || c == ')') && i != condition.length() - 1
  53. && isCheckingTimeCondtion == false) // timeconditon? ???
  54. // ( )?? ??
  55. continue;
  56. if ((c != '&' && c != '|' && isCheckingTimeCondtion == false)
  57. && i < condition.length()) // &? |? ????? ??
  58. // timecondition? ??????
  59. // ???.
  60. {
  61. temp += Character.toString(c);
  62. if (!(i == condition.length() - 1 && temp.equals("") == false))
  63. continue;
  64. }
  65. if (temp.equals("") == false && temp.charAt(0) != '[')
  66. temp.replace(")", "");
  67. if (condsQueue.size() == 0) // queue? ?? ??? numbering? 1? ??
  68. // queue? ???.
  69. {
  70. CondInformation cond = new CondInformation();
  71. cond.name = "cond_" + Integer.toString(number);
  72. cond.number = number++;
  73. cond.content = temp;
  74. condsQueue.add(cond);
  75. temp = "";
  76. isCheckingTimeCondtion = false;
  77. } else {
  78. boolean flag = false;
  79. if (temp.equals("") == false && temp.charAt(0) != '[')
  80. temp = temp.replace(")", "");
  81. // queue ?? ?? ???? ??? ??
  82. for (CondInformation condInformation : condsQueue) {
  83. // ??? ??? ??? ??? ???.
  84. if (condInformation.content.equals(temp)) {
  85. flag = true;
  86. temp = "";
  87. break;
  88. }
  89. }
  90. // ??? ??? ???
  91. if (flag == false && temp.equals("") == false) {
  92. // ???? ? ???? Queue? ??? ??.
  93. Queue<CondInformation> tempQueue = new LinkedList<CondInformation>();
  94. int condsQueueCount = condsQueue.size();
  95. while (condsQueueCount-- != 0) {
  96. CondInformation tempcond = condsQueue.remove();
  97. // temp ?? ? ???? tempQueue? ???.
  98. if (tempcond.content.length() < temp.length())
  99. tempQueue.add(tempcond);
  100. else
  101. condsQueue.add(tempcond);
  102. }
  103. CondInformation cond = new CondInformation();
  104. cond.name = "cond_" + Integer.toString(number);
  105. cond.content = temp;
  106. cond.number = number++;
  107. condsQueue.add(cond);
  108. temp = "";
  109. for (CondInformation tempcond : tempQueue) {
  110. condsQueue.add(tempcond);
  111. }
  112. }
  113. isCheckingTimeCondtion = false;
  114. }
  115. }
  116. }
  117. for (int i = 0; i < conditions.length; i++) // ?? ??
  118. {
  119. String t = "";
  120. for (int j = 0; j < conditions[i].length(); j++) {
  121. if (conditions[i].charAt(j) == ' '
  122. || conditions[i].charAt(j) == '\n'
  123. || conditions[i].charAt(j) == '\r'
  124. || conditions[i].charAt(j) == '\t')
  125. continue;
  126. t += conditions[i].charAt(j);
  127. }
  128. conditions[i] = t;
  129. }
  130. for (int i = 0; i < conditions.length; i++) // conditionstring?? ?? ????
  131. // cond_1,cond_2,cond_3 ???
  132. // ????.
  133. {
  134. for (CondInformation cond : condsQueue) {
  135. conditions[i] = conditions[i].replace(cond.content, "cond_"
  136. + Integer.toString(cond.number));
  137. }
  138. }
  139. String pakage = "";
  140. // condsQueueSecond = condsQueue; //???? ????
  141. // condsQueue.Clear(); //queue???
  142. number = 'a';
  143. int openIndex = 0;
  144. boolean queueFlag = false;
  145. Stack<Character> reverseStack = new Stack<Character>();
  146. for (int i = 0; i < conditions.length; i++) {
  147. for (int j = 0; j < conditions[i].length(); j++) // 1?? ?? ??.
  148. // cond_???
  149. {
  150. if (conditions[i].charAt(0) == '!') // others? ??.
  151. break;
  152. if (conditions[i].charAt(j) == '(') {
  153. openIndex = j;
  154. }
  155. if (conditions[i].charAt(j) == ')') // ')'? ??? (? ????? ???
  156. // ???.
  157. {
  158. for (int k = j - 1; k > openIndex; k--) {
  159. if (conditions[i].charAt(k) == ')') // //??? ')'? ???
  160. // 1?? ??? ?????
  161. // ????.
  162. {
  163. reverseStack.clear();
  164. break;
  165. }
  166. reverseStack.push(conditions[i].charAt(k));
  167. }
  168. openIndex = 0;
  169. if (reverseStack.size() != 0) // 1?? ??? ? ???.
  170. {
  171. while (reverseStack.size() != 0) {
  172. pakage += reverseStack.pop();
  173. }
  174. pakage = pakage.replace(")", "");
  175. for (CondInformation condInformation : condsQueueSecond) // queue??
  176. // ??
  177. // ????
  178. // ???
  179. // ??
  180. {
  181. if (condInformation.content.equals(pakage)) // ???
  182. // ???
  183. // ???
  184. // ???
  185. // ???.
  186. {
  187. queueFlag = true;
  188. pakage = "";
  189. break;
  190. }
  191. }
  192. if (queueFlag == false) // ??? ??? ???
  193. {
  194. Queue<CondInformation> tempQueue = new LinkedList<CondInformation>();
  195. int condsQueueCount = condsQueueSecond.size();
  196. while (condsQueueCount-- != 0) {
  197. CondInformation tempcond = condsQueueSecond
  198. .remove();
  199. if (tempcond.content.length() < pakage.length()) // SecondQueue??
  200. // ???
  201. // pakage??
  202. // ???
  203. // tempqueue?
  204. // ???.
  205. tempQueue.add(tempcond);
  206. else
  207. condsQueueSecond.add(tempcond);
  208. }
  209. CondInformation cond = new CondInformation();
  210. // char c = number;
  211. cond.name = "cond_" + Integer.toString(number);
  212. cond.content = pakage;
  213. cond.number = number++;
  214. condsQueueSecond.add(cond);
  215. pakage = "";
  216. for (CondInformation tempcond : tempQueue) // pakage??
  217. // ??
  218. // ????
  219. // ???
  220. // ???.
  221. {
  222. condsQueueSecond.add(tempcond);
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. for (int i = 0; i < conditions.length; i++) // conditionstring?? ?? ????
  230. // ??? ??? ??
  231. // cond_a,cond_b??? ???.
  232. {
  233. for (CondInformation cond : condsQueueSecond) {
  234. conditions[i] = conditions[i].replace(cond.content, "cond_"
  235. + Integer.toString(cond.number));
  236. }
  237. }
  238. // ?? ?? ?? ????? ???? ???.
  239. // ????? ?? & |? ???? ????.
  240. boolean flagl = false;
  241. char number = 'A';
  242. for (int i = 0; i < conditions.length; i++) {
  243. String templ = "";
  244. for (int j = 0; j < conditions[i].length(); j++) {
  245. if ((conditions[i].charAt(j) == ' '
  246. || conditions[i].charAt(j) == '\n'
  247. || conditions[i].charAt(j) == '\r'
  248. || conditions[i].charAt(j) == '\t'
  249. || conditions[i].charAt(j) == '!'
  250. || conditions[i].charAt(j) == ')' || conditions[i]
  251. .charAt(j) == '(') && j != conditions[i].length() - 1)
  252. continue;
  253. if (conditions[i].charAt(j) != '&'
  254. && conditions[i].charAt(j) != '|'
  255. && j < conditions[i].length()) // &? |? ?????
  256. {
  257. templ += Character.toString(conditions[i].charAt(j));
  258. if (!(j == conditions[i].length() - 1 && templ.equals("") == false))
  259. continue;
  260. }
  261. templ = templ.replace(")", "");
  262. for (CondInformation condInformation : condsQueueLast) // queue??
  263. // ??
  264. // ????
  265. // ???
  266. // ??
  267. {
  268. if (condInformation.content.equals(templ)) // ??? ??? ???
  269. // ??? ???.
  270. {
  271. flagl = true;
  272. templ = "";
  273. break;
  274. }
  275. }
  276. if (flagl == false && templ.equals("") == false) // ??? ??? ???
  277. {
  278. Queue<CondInformation> tempQueue = new LinkedList<CondInformation>();
  279. int condsQueueCount = condsQueueLast.size();
  280. while (condsQueueCount-- != 0) {
  281. CondInformation tempcond = condsQueueLast.remove();
  282. if (tempcond.content.length() < templ.length()) // temp??
  283. // ?
  284. // ????
  285. // tempQueue?
  286. // ???.
  287. tempQueue.add(tempcond);
  288. else
  289. condsQueueLast.add(tempcond);
  290. }
  291. CondInformation cond = new CondInformation();
  292. cond.name = "cond_" + Character.toString(number);
  293. cond.content = templ;
  294. cond.number = number++;
  295. condsQueueLast.add(cond);
  296. templ = "";
  297. for (CondInformation tempcond : tempQueue) {
  298. condsQueueLast.add(tempcond);
  299. }
  300. }
  301. flagl = false;
  302. templ = "";
  303. }
  304. }
  305. for (int i = 0; i < conditions.length; i++) // conditionstring?? ?? ????
  306. // ??? ??? ??
  307. // cond_A,cond_B??? ???.
  308. {
  309. for (CondInformation cond : condsQueueLast) {
  310. conditions[i] = conditions[i].replace(cond.content, cond.name);
  311. }
  312. }
  313. // condQueue? condQueueLast? ?? content?? ?? ????? ????.
  314. for (CondInformation condlast : condsQueueLast) {
  315. for (CondInformation cond : condsQueueSecond) {
  316. CondInformation c = condlast;
  317. c.content = c.content.replace(cond.name, cond.content);
  318. }
  319. }
  320. for (CondInformation condlast : condsQueueLast) {
  321. for (CondInformation cond : condsQueue) {
  322. CondInformation c = condlast;
  323. c.content = c.content.replace(cond.name, cond.content);
  324. }
  325. }
  326. }
  327. }