/NuSCRtoFBD/src/basefbd/CombineEngine.java
http://fbdtoverilog.googlecode.com/ · Java · 360 lines · 273 code · 33 blank · 54 comment · 158 complexity · a38f33995323b7f8b66315c0443979f7 MD5 · raw file
- package basefbd;
-
- import java.util.LinkedList;
- import java.util.Queue;
- import java.util.Stack;
-
- //import sun.io.Converters;
-
- public class CombineEngine {
- public Queue<CondInformation> condsQueue = new LinkedList<CondInformation>();
- public Queue<CondInformation> condsQueueSecond = new LinkedList<CondInformation>();
-
- int number = 1;
-
- public void MakeCond(String[] conditions,
- Queue<CondInformation> condsQueueLast) {
- // condsQueueLast1 = this.condsQueueLast;
- for (String condition : conditions) // conditionstring? ??? ??? cond???
- // ????.
- {
- String temp = "";
- char c;
- boolean isCheckingTimeCondtion = false;
- int openCount = 0;
-
- for (int i = 0; i < condition.length(); i++) {
- c = condition.charAt(i);
- if (condition.charAt(i) == '[') // timecondition? ?? ()?? ???.
- {
- isCheckingTimeCondtion = true;
- while (true) // ??? ? ????? ???.
- {
- if (condition.charAt(i) == ' '
- || condition.charAt(i) == '\n'
- || condition.charAt(i) == '\r'
- || condition.charAt(i) == '\t') {
- i++;
- continue;
- }
- if (condition.charAt(i) == '(')
- openCount++;
- else if (condition.charAt(i) == ')')
- openCount--;
- temp += Character.toString(condition.charAt(i));
-
- if (openCount == 0 && condition.charAt(i) == ')')
- break;
- i++;
- if (i >= condition.length())
- break;
- }
- while (i < condition.length()
- && (condition.charAt(i) != '|' && condition
- .charAt(i) != '&'))
- i++;
- }
-
- if (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '!')
- continue;
- if ((c == '(' || c == ')') && i != condition.length() - 1
- && isCheckingTimeCondtion == false) // timeconditon? ???
- // ( )?? ??
- continue;
-
- if ((c != '&' && c != '|' && isCheckingTimeCondtion == false)
- && i < condition.length()) // &? |? ????? ??
- // timecondition? ??????
- // ???.
- {
- temp += Character.toString(c);
- if (!(i == condition.length() - 1 && temp.equals("") == false))
- continue;
- }
-
- if (temp.equals("") == false && temp.charAt(0) != '[')
- temp.replace(")", "");
-
- if (condsQueue.size() == 0) // queue? ?? ??? numbering? 1? ??
- // queue? ???.
- {
- CondInformation cond = new CondInformation();
- cond.name = "cond_" + Integer.toString(number);
- cond.number = number++;
- cond.content = temp;
- condsQueue.add(cond);
- temp = "";
- isCheckingTimeCondtion = false;
- } else {
- boolean flag = false;
-
- if (temp.equals("") == false && temp.charAt(0) != '[')
- temp = temp.replace(")", "");
-
- // queue ?? ?? ???? ??? ??
- for (CondInformation condInformation : condsQueue) {
-
- // ??? ??? ??? ??? ???.
- if (condInformation.content.equals(temp)) {
- flag = true;
- temp = "";
- break;
- }
- }
-
- // ??? ??? ???
- if (flag == false && temp.equals("") == false) {
- // ???? ? ???? Queue? ??? ??.
- Queue<CondInformation> tempQueue = new LinkedList<CondInformation>();
- int condsQueueCount = condsQueue.size();
- while (condsQueueCount-- != 0) {
- CondInformation tempcond = condsQueue.remove();
-
- // temp ?? ? ???? tempQueue? ???.
- if (tempcond.content.length() < temp.length())
- tempQueue.add(tempcond);
- else
- condsQueue.add(tempcond);
- }
- CondInformation cond = new CondInformation();
- cond.name = "cond_" + Integer.toString(number);
- cond.content = temp;
- cond.number = number++;
- condsQueue.add(cond);
- temp = "";
-
- for (CondInformation tempcond : tempQueue) {
- condsQueue.add(tempcond);
- }
- }
- isCheckingTimeCondtion = false;
- }
- }
- }
-
- for (int i = 0; i < conditions.length; i++) // ?? ??
- {
- String t = "";
- for (int j = 0; j < conditions[i].length(); j++) {
- if (conditions[i].charAt(j) == ' '
- || conditions[i].charAt(j) == '\n'
- || conditions[i].charAt(j) == '\r'
- || conditions[i].charAt(j) == '\t')
- continue;
- t += conditions[i].charAt(j);
- }
- conditions[i] = t;
- }
-
- for (int i = 0; i < conditions.length; i++) // conditionstring?? ?? ????
- // cond_1,cond_2,cond_3 ???
- // ????.
- {
-
- for (CondInformation cond : condsQueue) {
- conditions[i] = conditions[i].replace(cond.content, "cond_"
- + Integer.toString(cond.number));
- }
- }
-
- String pakage = "";
- // condsQueueSecond = condsQueue; //???? ????
- // condsQueue.Clear(); //queue???
- number = 'a';
- int openIndex = 0;
- boolean queueFlag = false;
- Stack<Character> reverseStack = new Stack<Character>();
- for (int i = 0; i < conditions.length; i++) {
- for (int j = 0; j < conditions[i].length(); j++) // 1?? ?? ??.
- // cond_???
- {
- if (conditions[i].charAt(0) == '!') // others? ??.
- break;
- if (conditions[i].charAt(j) == '(') {
- openIndex = j;
- }
-
- if (conditions[i].charAt(j) == ')') // ')'? ??? (? ????? ???
- // ???.
- {
- for (int k = j - 1; k > openIndex; k--) {
- if (conditions[i].charAt(k) == ')') // //??? ')'? ???
- // 1?? ??? ?????
- // ????.
- {
- reverseStack.clear();
- break;
- }
- reverseStack.push(conditions[i].charAt(k));
- }
-
- openIndex = 0;
- if (reverseStack.size() != 0) // 1?? ??? ? ???.
- {
- while (reverseStack.size() != 0) {
- pakage += reverseStack.pop();
- }
-
- pakage = pakage.replace(")", "");
-
- for (CondInformation condInformation : condsQueueSecond) // queue??
- // ??
- // ????
- // ???
- // ??
- {
- if (condInformation.content.equals(pakage)) // ???
- // ???
- // ???
- // ???
- // ???.
- {
- queueFlag = true;
- pakage = "";
- break;
- }
- }
- if (queueFlag == false) // ??? ??? ???
- {
- Queue<CondInformation> tempQueue = new LinkedList<CondInformation>();
- int condsQueueCount = condsQueueSecond.size();
- while (condsQueueCount-- != 0) {
- CondInformation tempcond = condsQueueSecond
- .remove();
- if (tempcond.content.length() < pakage.length()) // SecondQueue??
- // ???
- // pakage??
- // ???
- // tempqueue?
- // ???.
- tempQueue.add(tempcond);
- else
- condsQueueSecond.add(tempcond);
- }
- CondInformation cond = new CondInformation();
- // char c = number;
- cond.name = "cond_" + Integer.toString(number);
- cond.content = pakage;
- cond.number = number++;
- condsQueueSecond.add(cond);
- pakage = "";
-
- for (CondInformation tempcond : tempQueue) // pakage??
- // ??
- // ????
- // ???
- // ???.
- {
- condsQueueSecond.add(tempcond);
- }
- }
- }
- }
- }
- }
-
- for (int i = 0; i < conditions.length; i++) // conditionstring?? ?? ????
- // ??? ??? ??
- // cond_a,cond_b??? ???.
- {
- for (CondInformation cond : condsQueueSecond) {
- conditions[i] = conditions[i].replace(cond.content, "cond_"
- + Integer.toString(cond.number));
- }
- }
-
- // ?? ?? ?? ????? ???? ???.
- // ????? ?? & |? ???? ????.
-
- boolean flagl = false;
- char number = 'A';
- for (int i = 0; i < conditions.length; i++) {
- String templ = "";
- for (int j = 0; j < conditions[i].length(); j++) {
- if ((conditions[i].charAt(j) == ' '
- || conditions[i].charAt(j) == '\n'
- || conditions[i].charAt(j) == '\r'
- || conditions[i].charAt(j) == '\t'
- || conditions[i].charAt(j) == '!'
- || conditions[i].charAt(j) == ')' || conditions[i]
- .charAt(j) == '(') && j != conditions[i].length() - 1)
- continue;
- if (conditions[i].charAt(j) != '&'
- && conditions[i].charAt(j) != '|'
- && j < conditions[i].length()) // &? |? ?????
- {
- templ += Character.toString(conditions[i].charAt(j));
- if (!(j == conditions[i].length() - 1 && templ.equals("") == false))
- continue;
- }
- templ = templ.replace(")", "");
-
- for (CondInformation condInformation : condsQueueLast) // queue??
- // ??
- // ????
- // ???
- // ??
- {
- if (condInformation.content.equals(templ)) // ??? ??? ???
- // ??? ???.
- {
- flagl = true;
- templ = "";
- break;
- }
- }
- if (flagl == false && templ.equals("") == false) // ??? ??? ???
- {
- Queue<CondInformation> tempQueue = new LinkedList<CondInformation>();
- int condsQueueCount = condsQueueLast.size();
- while (condsQueueCount-- != 0) {
- CondInformation tempcond = condsQueueLast.remove();
- if (tempcond.content.length() < templ.length()) // temp??
- // ?
- // ????
- // tempQueue?
- // ???.
- tempQueue.add(tempcond);
- else
- condsQueueLast.add(tempcond);
- }
- CondInformation cond = new CondInformation();
- cond.name = "cond_" + Character.toString(number);
- cond.content = templ;
- cond.number = number++;
- condsQueueLast.add(cond);
- templ = "";
- for (CondInformation tempcond : tempQueue) {
- condsQueueLast.add(tempcond);
- }
- }
- flagl = false;
- templ = "";
- }
- }
-
- for (int i = 0; i < conditions.length; i++) // conditionstring?? ?? ????
- // ??? ??? ??
- // cond_A,cond_B??? ???.
- {
- for (CondInformation cond : condsQueueLast) {
- conditions[i] = conditions[i].replace(cond.content, cond.name);
- }
- }
-
- // condQueue? condQueueLast? ?? content?? ?? ????? ????.
- for (CondInformation condlast : condsQueueLast) {
- for (CondInformation cond : condsQueueSecond) {
- CondInformation c = condlast;
- c.content = c.content.replace(cond.name, cond.content);
- }
- }
-
- for (CondInformation condlast : condsQueueLast) {
- for (CondInformation cond : condsQueue) {
- CondInformation c = condlast;
- c.content = c.content.replace(cond.name, cond.content);
- }
- }
- }
- }