Commit daf1fb1e authored by Peter's avatar Peter
Browse files

dev

parent 3429f4a6
Loading
Loading
Loading
Loading
Loading
+8 −6
Changes for src/main/java/hk/quantr/verilogcompiler/VerilogHelper.java: 8 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class VerilogHelper {
		String lines[] = content.split("\r?\n");
		if (ps.macroListing.isEmpty()) {
			for (int x = 0; x < lines.length; x++) {
				ps.macroListing.add(new MacroListing(x, lines[x], Type.ORIGINAL));
				ps.macroListing.add(new MacroListing(0, x, x, lines[x], Type.ORIGINAL));
			}
		}

@@ -104,7 +104,7 @@ public class VerilogHelper {
//							}

							int lineNo = token.getLine() - 1;
							MacroListing parentMacro = ps.get(lineNo, parseNo);
							MacroListing parentMacro = ps.get(lineNo, parseNo > 0 ? parseNo - 1 : 0);

							if (parentMacro.lineNo == 194) {
								System.out.println("");
@@ -113,8 +113,10 @@ public class VerilogHelper {
								System.err.println("ERROR");
								System.exit(125);
							}
							int delta = 0;
							for (String temp : macroBody.split("\r?\n")) {
								parentMacro.children.add(new MacroListing(parentMacro.lineNo, temp, Type.MACRO));
								parentMacro.children.add(new MacroListing(parseNo, parentMacro.lineNo, token.getLine() - 1 + delta, temp, Type.MACRO));
								delta++;
							}
							// end add to macroListing

@@ -134,12 +136,12 @@ public class VerilogHelper {
				} else {
//				logger.info("\treplacing " + macroName);
					int lineNo = token.getLine() - 1;
					MacroListing parentMacro = ps.get(lineNo, parseNo);
					MacroListing parentMacro = ps.get(lineNo, parseNo > 0 ? parseNo - 1 : 0);
					if (parentMacro == null) {
						System.err.println("ERROR");
						System.exit(125);
						System.exit(129);
					}
					parentMacro.children.add(new MacroListing(parentMacro.lineNo, macroBody, Type.MACRO));
					parentMacro.children.add(new MacroListing(parseNo, parentMacro.lineNo, token.getLine() - 1, macroBody, Type.MACRO));

					rewriter.replace(token, macroBody);
					rewriter.delete(token.getTokenIndex() - 1);
+5 −2
Changes for src/main/java/hk/quantr/verilogcompiler/macro/MacroListing.java: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -17,11 +17,14 @@ public class MacroListing {

	public int parseNo;
	public Type type;
	public int originalLineNo;
	public int lineNo;
	public String line;
	public ArrayList<MacroListing> children = new ArrayList<>();

	public MacroListing(int lineNo, String line, Type type) {
	public MacroListing(int parseNo, int originalLineNo, int lineNo, String line, Type type) {
		this.parseNo = parseNo;
		this.originalLineNo = originalLineNo;
		this.lineNo = lineNo;
		this.line = line;
		this.type = type;
@@ -32,7 +35,7 @@ public class MacroListing {
//		if (type == Type.MACRO) {
//			return lineNo + "\t" + secondLineNo + "\t" + type + "(" + uuid + ")" + "\t" + line;
//		} else {
		return lineNo + "    " + type + "    " + line.trim();
		return originalLineNo + "    " + lineNo + "    " + type + "    " + line.trim();
//		}
	}

+38 −19
Changes for src/main/java/hk/quantr/verilogcompiler/macro/ParseStructure.java: 38 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@ public class ParseStructure {

	public ArrayList<MacroListing> macroListing = new ArrayList<>();

	public Pair<String, Integer> macroListingToString(ArrayList<MacroListing> temp, int index, int tabSize) {
	public Pair<String, Integer> macroListingToString(ArrayList<MacroListing> temp, int index) {
		String s = "";
		for (MacroListing macroListing : temp) {
			s += "(" + tabSize + ") " + index + "    ".repeat(tabSize + 1) + macroListing + "\n";
			s += index + "\t(" + macroListing.parseNo + ")" + "    ".repeat(macroListing.parseNo + 1) + macroListing + "\n";
			index++;
			if (!macroListing.children.isEmpty()) {
				Pair<String, Integer> temp2 = macroListingToString(macroListing.children, index, tabSize + 1);
				Pair<String, Integer> temp2 = macroListingToString(macroListing.children, index);
				s += temp2.getLeft();
				index = temp2.getRight();
			}
@@ -31,30 +31,49 @@ public class ParseStructure {

	@Override
	public String toString() {
		return macroListingToString(macroListing, 0, 0).getLeft();
		return macroListingToString(macroListing, 0).getLeft();
	}

	public MacroListing get(int lineNo, int maxDeep) {
		return get(lineNo, 0, macroListing, 0, maxDeep).getLeft();
	public MacroListing get(int lineNo, int parseNo) {
		return get(macroListing, lineNo, parseNo);
	}

	public Pair<MacroListing, Integer> get(int lineNo, int current, ArrayList<MacroListing> temp, int deep, int maxDeep) {
		for (MacroListing m : temp) {
			if (lineNo == current) {
				return new ImmutablePair(m, current);
	public MacroListing get(ArrayList<MacroListing> temp, int lineNo, int parseNo) {
		for (int x = temp.size() - 1; x >= 0; x--) {
			System.out.println(">>>>>>> " + temp.get(x).lineNo + " = " + temp.get(x).parseNo + " : " + temp.get(x).line);
			if (temp.get(x).lineNo == lineNo && temp.get(x).parseNo == parseNo) {
				return temp.get(x);
			}
			if (!m.children.isEmpty() & deep < maxDeep) {
				Pair<MacroListing, Integer> p = get(lineNo, current, m.children, deep + 1, maxDeep);
				MacroListing t = p.getLeft();
				current = p.getRight();
				if (t != null) {
					return new ImmutablePair(t, current);
			if (!temp.get(x).children.isEmpty()) {
				MacroListing temp2 = get(temp.get(x).children, lineNo, parseNo);
				if (temp2 != null) {
					return temp2;
				}
			} else {
				current++;
			}
		}
		return new ImmutablePair(null, current);
		return null;
	}

//	public MacroListing get(int lineNo, int maxDeep) {
//		return get(lineNo, 0, macroListing, 0, maxDeep).getLeft();
//	}
//
//	public Pair<MacroListing, Integer> get(int lineNo, int current, ArrayList<MacroListing> temp, int deep, int maxDeep) {
//		for (MacroListing m : temp) {
//			if (lineNo == current) {
//				return new ImmutablePair(m, current);
//			}
//			if (!m.children.isEmpty() & deep < maxDeep) {
//				Pair<MacroListing, Integer> p = get(lineNo, current, m.children, deep + 1, maxDeep);
//				MacroListing t = p.getLeft();
//				current = p.getRight();
//				if (t != null) {
//					return new ImmutablePair(t, current);
//				}
//			} else {
//				current++;
//			}
//		}
//		return new ImmutablePair(null, current);
//	}
}