Java Code Examples for com.oracle.truffle.api.source.Source#getPath()

The following examples show how to use com.oracle.truffle.api.source.Source#getPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourcePosition.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public SourcePosition(SourceSection sourceSection) {
    Source source = sourceSection.getSource();
    this.id = getId(source);
    this.name = source.getName();
    String sourcePath = source.getPath();
    if (sourcePath == null) {
        sourcePath = name;
    }
    this.path = sourcePath;
    this.sourceSection = sourceSection.getStartLine() + "," + sourceSection.getStartColumn() + "," + sourceSection.getEndLine() + "," + sourceSection.getEndColumn();
    this.code = source.getCharacters().toString();
    this.uri = source.getURI();
}
 
Example 2
Source File: AnalysisFilterSourceList.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
@Override
@TruffleBoundary
public boolean test(final Source source) {
    // don't try to instrument other languages
    if (isForeignSource(source)) {
        return false;
    }

    // if it's an exclusion filter, we include the source by default
    boolean res = filterExcludes;

    boolean isInternal = SourceMapping.isInternal(source);
    // use name or path of source depending whether we consider it internal

    boolean isEval = SourceMapping.isEval(source);
    boolean isIndirectEval = source.getName().startsWith(Evaluator.FUNCTION_SOURCE_NAME) && !matchSources.contains(Evaluator.FUNCTION_SOURCE_NAME);

    String name;
    if (isEval) {
        name = source.getName();
        String sourceOfEval = SourceMapping.innerMostEvalSource(name);
        if (sourceOfEval != null) {
            name = sourceOfEval.split(":")[0];
            // TODO, currently there is no way to judge if the eval is called from internal
            // for the moment, we assume it's not internal
            isInternal = false;
        }
    } else if (isIndirectEval) {
        name = source.getName();
        isInternal = false;
    } else if (isInternal) {
        name = source.getName();
    } else {
        name = source.getPath();
    }
    assert (name != null);

    if (instrumentInternal || !isInternal) {
        // log warning if source does not have a name
        if (name.equals("")) {
            if (logSource(source)) {
                Logger.warning("Source filter: ignoring source without name");
            }
        } else {
            // match against included/excluded sources
            for (final String str : matchSources) {
                if (name.contains(str)) {
                    // apply filter
                    res = !filterExcludes;
                    break;
                }
            }
            if (res && containsDoNotInstrument(source)) {
                res = false;
                if (logSource(source)) {
                    Logger.debug("Source filter: " + logName(name, isInternal) + " -> excluded due to 'DO NOT INSTRUMENT'" + (this.debugHint.isEmpty() ? "" : (" " + this.debugHint)));
                }
            }
        }
    } else {
        // not instrumenting internal source
        res = false;
    }

    if (res && logSource(source)) {
        Logger.debug("Source filter: " + logName(name, isInternal) + " -> included " + (this.debugHint.isEmpty() ? "" : (" " + this.debugHint)));
    }

    // debug log (once per source) if filter did something
    if (logSource(source)) {
        // don't log internal if they are being excluded (there are a lot of them)
        if (instrumentInternal || !isInternal) {
            Logger.debug("Source filter: " + logName(name, isInternal) + " -> " + (res ? "included" : "excluded") + (this.debugHint.isEmpty() ? "" : (" " + this.debugHint)));
        }
    }
    return res;
}
 
Example 3
Source File: AnalysisFilterJS.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
@Override
@TruffleBoundary
public boolean test(final Source source) {
    if (isForeignSource(source) || excludedSources.contains(source)) {
        return false;
    }
    if (includedSources.containsKey(source)) {
        return true;
    }

    boolean include = true;

    String name;
    if (SourceMapping.isInternal(source)) {
        name = source.getName();
    } else {
        name = source.getPath();
    }

    Logger.debug("JS Analysis filter testing: " + name + (SourceMapping.isInternal(source) ? " (internal)" : ""));

    if (include && containsDoNotInstrument(source)) {
        include = false;
        Logger.debug("JS Analysis filter: " + name + " -> excluded due to 'DO NOT INSTRUMENT'");
    }

    // we need to bail out during builtin calls inside the JS predicate
    if (include && isRecursive) {
        if (!(name.equals("<builtin>") || name.equals("<internal>"))) {
            Logger.error("JS Analysis filter bailout due to recursive call while testing: " + name);
        }
        return false;
    }

    EnumSet<ProfiledTagEnum> includeTags = allTags;

    if (include) {

        // prevent JS predicate being entered more than once
        isRecursive = true;

        try {
            Object ret = InteropLibrary.getFactory().getUncached().execute(jsPredicateFunc, SourceMapping.getJSObjectForSource(source));
            if (JSArray.isJSArray(ret)) {
                include = JSAbstractArray.arrayGetLength((DynamicObject) ret) > 0;
                includeTags = mapToTags(JSAbstractArray.toArray((DynamicObject) ret));
            } else {
                include = JSRuntime.toBoolean(ret);
            }
        } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
            Logger.error("JS Analysis filter: call to JS predicate failed");
            Thread.dumpStack();
            System.exit(-1);
        }

        isRecursive = false;

        String tagStr = "";
        if (includeTags != allTags) {
            tagStr = " " + includeTags.toString();
        }
        Logger.debug("JS Analysis filter: " + name + " -> " + (include ? "included" : "excluded") + tagStr);

    }

    if (include) {
        includedSources.put(source, includeTags);
    } else {
        excludedSources.add(source);
    }

    return include;
}
 
Example 4
Source File: SourceMapping.java    From nodeprof.js with Apache License 2.0 2 votes vote down vote up
/**
 * Helper function to determine what is considered internal by the source filter.
 *
 * @param src the Source to test
 * @return true if src is considered internal
 */
public static boolean isInternal(final Source src) {
    return src.isInternal() || (!isEval(src) && (src.getPath() == null || src.getPath().equals("")));
}