[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[imp-commit] r22972 - trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io

Author: jvinju
Date: 2012-02-08 04:41:14 -0500 (Wed, 08 Feb 2012)
New Revision: 22972

Modified:
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextReader.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextWriter.java
Log:
added support for reading and writing source locs that only have length/offset info and not line/col

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextReader.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextReader.java	2012-02-08 09:32:00 UTC (rev 22971)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextReader.java	2012-02-08 09:41:14 UTC (rev 22972)
@@ -150,30 +150,43 @@
 				ArrayList<IValue> args = new ArrayList<IValue>(4);
 				readFixed(types.valueType(), ')', args);
 
-				if (!args.get(0).getType().isSubtypeOf(types.integerType())) {
-					throw new UnexpectedTypeException(types.integerType(), args.get(0).getType());
-				}
-				if (!args.get(1).getType().isSubtypeOf(types.integerType())) {
-					throw new UnexpectedTypeException(types.integerType(), args.get(1).getType());
-				}
-				Type posType = types.tupleType(types.integerType(), types.integerType());
+				if (args.size() >= 2) {
+					if (!args.get(0).getType().isSubtypeOf(types.integerType())) {
+						throw new UnexpectedTypeException(types.integerType(), args.get(0).getType());
+					}
+					if (!args.get(1).getType().isSubtypeOf(types.integerType())) {
+						throw new UnexpectedTypeException(types.integerType(), args.get(1).getType());
+					}
+					
+					Type posType = types.tupleType(types.integerType(), types.integerType());
 
-				if (!args.get(2).getType().isSubtypeOf(posType)) {
-					throw new UnexpectedTypeException(posType, args.get(2).getType());
+					if (args.size() == 4) {
+						if (!args.get(2).getType().isSubtypeOf(posType)) {
+							throw new UnexpectedTypeException(posType, args.get(2).getType());
+						}
+						if (!args.get(3).getType().isSubtypeOf(posType)) {
+							throw new UnexpectedTypeException(posType, args.get(3).getType());
+						}
+					}
+
+					int offset = Integer.parseInt(args.get(0).toString());
+					int length = Integer.parseInt(args.get(1).toString());
+					
+					if (args.size() == 4) {
+						int beginLine = Integer.parseInt(((ITuple) args.get(2)).get(0).toString());
+						int beginColumn = Integer.parseInt(((ITuple) args.get(2)).get(1).toString());
+						int endLine = Integer.parseInt(((ITuple) args.get(3)).get(0).toString());
+						int endColumn = Integer.parseInt(((ITuple) args.get(3)).get(1).toString());
+						
+						return factory.sourceLocation(new URI(url), offset, length, beginLine, endLine, beginColumn, endColumn);
+					}
+					
+					if (args.size() != 2) {
+						throw new FactParseError("source locations should have either 2 or 4 arguments", offset);
+					}
+					
+					return factory.sourceLocation(new URI(url), offset, length);
 				}
-				if (!args.get(3).getType().isSubtypeOf(posType)) {
-					throw new UnexpectedTypeException(posType, args.get(3).getType());
-				}
-
-				int offset = Integer.parseInt(args.get(0).toString());
-				int length = Integer.parseInt(args.get(1).toString());
-				int beginLine = Integer.parseInt(((ITuple) args.get(2)).get(0).toString());
-				int beginColumn = Integer.parseInt(((ITuple) args.get(2)).get(1).toString());
-				int endLine = Integer.parseInt(((ITuple) args.get(3)).get(0).toString());
-				int endColumn = Integer.parseInt(((ITuple) args.get(3)).get(1).toString());
-
-
-				return factory.sourceLocation(new URI(url), offset, length, beginLine, endLine, beginColumn, endColumn);
 			}
 
 			return factory.sourceLocation(new URI(url));

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextWriter.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextWriter.java	2012-02-08 09:32:00 UTC (rev 22971)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/io/StandardTextWriter.java	2012-02-08 09:41:14 UTC (rev 22972)
@@ -333,23 +333,26 @@
 			append(o.getURI().toString());
 			append('|');
 			
-			if (o.getOffset() != -1) {
+			if (o.hasOffsetLength()) {
 				append('(');
 				append(Integer.toString(o.getOffset()));
 				append(',');
 				append(Integer.toString(o.getLength()));
-				append(',');
-				append('<');
-				append(Integer.toString(o.getBeginLine()));
-				append(',');
-				append(Integer.toString(o.getBeginColumn()));
-				append('>');
-				append(',');
-				append('<');
-				append(Integer.toString(o.getEndLine()));
-				append(',');
-				append(Integer.toString(o.getEndColumn()));
-				append('>');
+				
+				if (o.hasLineColumn()) {
+					append(',');
+					append('<');
+					append(Integer.toString(o.getBeginLine()));
+					append(',');
+					append(Integer.toString(o.getBeginColumn()));
+					append('>');
+					append(',');
+					append('<');
+					append(Integer.toString(o.getEndLine()));
+					append(',');
+					append(Integer.toString(o.getEndColumn()));
+					append('>');
+				}
 				append(')');
 			}
 			return o;