diff options
Diffstat (limited to 'src/classes/com/sun/gluegen/JavaConfiguration.java')
-rw-r--r-- | src/classes/com/sun/gluegen/JavaConfiguration.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/classes/com/sun/gluegen/JavaConfiguration.java b/src/classes/com/sun/gluegen/JavaConfiguration.java index 152d9cf80..ae8c46eaa 100644 --- a/src/classes/com/sun/gluegen/JavaConfiguration.java +++ b/src/classes/com/sun/gluegen/JavaConfiguration.java @@ -116,6 +116,8 @@ public class JavaConfiguration { private Map/*<String,String>*/ javaMethodRenames = new HashMap(); private Map/*<String,List<String>>*/ javaPrologues = new HashMap(); private Map/*<String,List<String>>*/ javaEpilogues = new HashMap(); + private Map/*<String,Map<Integer,String>>*/ rangeChecks = new HashMap(); + private Map/*<String,Map<Integer,String>>*/ byteRangeChecks = new HashMap(); /** Reads the configuration file. @param filename path to file that should be read @@ -569,6 +571,22 @@ public class JavaConfiguration { return res; } + /** Returns a map of Integer argument numbers to expressions to be + used to range check the given arguments to the given function. + Returns null if there were no range check expressions supplied + for this function. */ + public Map/*<Integer, String>*/ rangeCheckExpressions(String functionName) { + return (Map/*<Integer, String>*/) rangeChecks.get(functionName); + } + + /** Returns a map of Integer argument numbers to expressions to be + used to range check (in size of bytes) the given arguments to + the given function. Returns null if there were no range check + expressions supplied for this function. */ + public Map/*<Integer, String>*/ byteRangeCheckExpressions(String functionName) { + return (Map/*<Integer, String>*/) byteRangeChecks.get(functionName); + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -686,6 +704,14 @@ public class JavaConfiguration { readJavaPrologueOrEpilogue(tok, filename, lineNo, false); // Warning: make sure delimiters are reset at the top of this loop // because readJavaPrologueOrEpilogue changes them. + } else if (cmd.equalsIgnoreCase("RangeCheck")) { + readRangeCheck(tok, filename, lineNo, false); + // Warning: make sure delimiters are reset at the top of this loop + // because RangeCheck changes them. + } else if (cmd.equalsIgnoreCase("RangeCheckBytes")) { + readRangeCheck(tok, filename, lineNo, true); + // Warning: make sure delimiters are reset at the top of this loop + // because RangeCheckBytes changes them. } else { throw new RuntimeException("Unknown command \"" + cmd + "\" in command file " + filename + @@ -1131,6 +1157,33 @@ public class JavaConfiguration { } } + protected void readRangeCheck(StringTokenizer tok, String filename, int lineNo, boolean inBytes) { + try { + String functionName = tok.nextToken(); + int argNum = Integer.parseInt(tok.nextToken()); + String restOfLine = tok.nextToken("\n\r\f"); + restOfLine = restOfLine.trim(); + Map/*<Integer, String>*/ checksForFunction = null; + if (inBytes) { + checksForFunction = (Map/*<Integer, String>*/) byteRangeChecks.get(functionName); + } else { + checksForFunction = (Map/*<Integer, String>*/) rangeChecks.get(functionName); + } + if (checksForFunction == null) { + checksForFunction = new HashMap/*<Integer, String>*/(); + if (inBytes) { + byteRangeChecks.put(functionName, checksForFunction); + } else { + rangeChecks.put(functionName, checksForFunction); + } + } + checksForFunction.put(new Integer(argNum), restOfLine); + } catch (Exception e) { + throw new RuntimeException("Error parsing \"RangeCheck" + (inBytes ? "Bytes" : "") + "\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected static TypeInfo parseTypeInfo(String cType, JavaType javaType) { String typeName = null; int pointerDepth = 0; |