# HG changeset patch # User Michael Van De Vanter # Date 1425431631 28800 # Node ID 9d2ff2e8360dd39b8835b60802d873e2eb08a221 # Parent 33bdafbf285dbe92f836e85b1974313621cfcb82# Parent fa75218e39424f24e05d31ee58dfd5c2bb4c8319 Merge with fa75218e39424f24e05d31ee58dfd5c2bb4c8319 diff -r fa75218e3942 -r 9d2ff2e8360d graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/policy/GreedyInliningPolicy.java diff -r fa75218e3942 -r 9d2ff2e8360d graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/EffectsPhase.java diff -r fa75218e3942 -r 9d2ff2e8360d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/NullSourceSection.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/NullSourceSection.java Tue Mar 03 10:32:17 2015 -0800 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/NullSourceSection.java Tue Mar 03 17:13:51 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -73,6 +73,14 @@ throw new UnsupportedOperationException(this.toString()); } + public int getEndLine() { + throw new UnsupportedOperationException(this.toString()); + } + + public int getEndColumn() { + throw new UnsupportedOperationException(this.toString()); + } + public final int getCharIndex() { throw new UnsupportedOperationException(this.toString()); } @@ -101,5 +109,4 @@ public String toString() { return getShortDescription(); } - } diff -r fa75218e3942 -r 9d2ff2e8360d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java Tue Mar 03 10:32:17 2015 -0800 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java Tue Mar 03 17:13:51 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -122,6 +122,35 @@ } /** + * Gets the canonical representation of a source file, whose contents have already been read and + * need not be read again. It is confirmed that the file resolves to a file name, so it can be + * indexed by canonical path, but it is not confirmed to be readable. + * + * @param chars textual source code already read from the file + * @param fileName + * @return canonical representation of the file's contents. + * @throws IOException if the file cannot be found + * @throws IllegalArgumentException if there is already a Source indexed under this file name + */ + public static Source fromFileName(CharSequence chars, String fileName) throws IOException, IllegalArgumentException { + final WeakReference nameRef = filePathToSource.get(fileName); + Source source = nameRef == null ? null : nameRef.get(); + if (source == null) { + final File file = new File(fileName); + // We are going to trust that the fileName is readable. + final String path = file.getCanonicalPath(); + final WeakReference pathRef = filePathToSource.get(path); + source = pathRef == null ? null : pathRef.get(); + if (source == null) { + source = new FileSource(file, fileName, path, chars); + filePathToSource.put(path, new WeakReference<>(source)); + return source; + } + } + throw new IOException("Source already exists for file:" + fileName); + } + + /** * Creates a non-canonical source from literal text. If an already created literal source must * be retrievable by name, use {@link #asPseudoFile(CharSequence, String)}. * @@ -275,10 +304,13 @@ } /** - * Return the complete text of the code. + * Returns the complete text of the code. */ public abstract String getCode(); + /** + * Returns a subsection of the code test. + */ public String getCode(int charIndex, int charLength) { return getCode().substring(charIndex, charIndex + charLength); } @@ -542,9 +574,16 @@ private long timeStamp; // timestamp of the cache in the file system public FileSource(File file, String name, String path) { + this(file, name, path, null); + } + + public FileSource(File file, String name, String path, CharSequence chars) { this.file = file.getAbsoluteFile(); this.name = name; this.path = path; + if (chars != null) { + this.code = chars.toString(); + } } @Override @@ -812,6 +851,14 @@ return startColumn; } + public int getEndLine() { + return source.getLineNumber(charIndex + charLength - 1); + } + + public int getEndColumn() { + return source.getColumnNumber(charIndex + charLength - 1); + } + @Override public int getCharIndex() { return charIndex; @@ -900,7 +947,6 @@ } return true; } - } private static final class LineLocationImpl implements LineLocation { diff -r fa75218e3942 -r 9d2ff2e8360d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java Tue Mar 03 10:32:17 2015 -0800 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java Tue Mar 03 17:13:51 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,6 +66,20 @@ int getStartColumn(); /** + * Returns 1-based line number of the last character in this section (inclusive). + * + * @return the starting line number + */ + int getEndLine(); + + /** + * Returns the 1-based column number of the last character in this section (inclusive). + * + * @return the starting column number + */ + int getEndColumn(); + + /** * Returns the 0-based index of the first character in this section. * * @return the starting character index