use of com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken in project openj9 by eclipse.
the class ParserController method parse.
/**
* Support for one image builder parsing javacore data for only one runtime.
* Multiple runtime support will require overriding this method in a subclass.
*/
public Image parse(IScannerManager scannerManager) throws ParserException {
ILookAheadBuffer lookAhead = scannerManager.getLookAheadBuffer();
// For error reporting
StringBuffer sb = new StringBuffer();
try {
for (int i = 1; i <= 2 && i <= lookAhead.maxDepth(); ++i) {
IParserToken token = lookAhead.lookAhead(i);
if (token != null) {
sb.append(token.getValue());
}
}
} catch (IOException e) {
} catch (IndexOutOfBoundsException e) {
} catch (ScannerException e) {
throw new ParserException(e);
}
// Don't get too much data
sb.setLength(Math.min(300, sb.length()));
String first = sb.toString();
IImageBuilder imageBuilder = null;
try {
imageBuilder = generateImageBuilder();
} catch (BuilderFailureException e) {
throw new ParserException(e);
}
boolean anyMatched = false;
try {
lookAhead.init();
for (Iterator it = fFramework.iterator(); it.hasNext(); ) {
processUnknownData(lookAhead);
ISectionParser sectionParser = (ISectionParser) it.next();
sectionParser.readIntoDTFJ(lookAhead, imageBuilder);
/*
* Retrieve the error log.
*/
Iterator errors = sectionParser.getErrors();
if ((fListener != null) && errors.hasNext()) {
while (errors.hasNext()) {
fListener.handleEvent(errors.next().toString());
}
}
anyMatched |= sectionParser.anyMatched();
}
} catch (IOException e) {
/*
* If IO exception encountered, parser may have reached a non-recoverable state, so for now no
* point in continuing the parsing process.
*/
e.printStackTrace();
} catch (RuntimeException e) {
/*
* For internal tracing purposes (Eclipse catches runtime exceptions,
* and they get hard to track even with the eclipse error log view).
*/
e.printStackTrace();
throw e;
} catch (ScannerException e) {
throw new ParserException(e);
}
if (!anyMatched) {
throw new ParserException("Not a javacore file. First line: " + first);
}
return imageBuilder.getImage();
}
use of com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken in project openj9 by eclipse.
the class SectionParserGrammar method processTagLine.
/**
* @param tagName
* @param required
* @return attribute value map if tag line successfully parsed or null otherwise.
* @throws ParserException if parsing error threshold reached
*/
private IAttributeValueMap processTagLine(String tagName, boolean required) throws ParserException {
IAttributeValueMap list = null;
if (required ? matchRequired(tagName) : matchOptional(tagName)) {
IParserToken token = lookAhead(1);
consume();
list = getLineRuleResults(token);
}
return list;
}
use of com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken in project openj9 by eclipse.
the class SectionParserGrammar method match.
/**
* The match performs one additional function:
* <br>
* if the mismatch is due to an unrecognised javacore tag, that erroneous tag can be
* interpreted as garbage for now, so the latter is consumed without further processing.
* <br>
* However, <b>beware</b> of considering
* all mismatches to be garbage. It is possible that the mismatch is due to a VALID
* javacore tag that pertains to another language rule. In this case, an argument
* to the method decides whether to handle it as an error (i.e., match was required) or let it fall through to the next
* grammar rule (match was optional).
*
* @return true if matched, false otherwise.
* @param type to match
* @param required will generate an error, otherwise false ignores the mismatch.
*/
protected boolean match(String type, boolean required) throws ParserException {
boolean matched = false;
boolean searchMore = true;
IParserToken token = null;
String tokenType = null;
String tokenValue = null;
while (searchMore && !fLookAheadBuffer.allConsumed() && !(matched = fLookAheadBuffer.match(type))) {
if ((token = lookAhead(1)) != null) {
tokenType = token.getType();
tokenValue = token.getValue();
}
// to be parsed.
if (isValidJavaCoreTag(token)) {
searchMore = false;
if (required) {
handleRequiredMismatch(type, tokenType, tokenValue);
}
} else {
// TODO: Uncomment this line for output on unhandled data.
// handleUnknownMismatch(tokenType, tokenValue);
consume();
}
}
anyMatched |= matched;
return matched;
}
use of com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken in project openj9 by eclipse.
the class JavaCoreAttributeValueMap method getLongValue.
/**
* @param tokenType
*/
public long getLongValue(String tokenType) {
IParserToken token = getToken(tokenType);
long value = IBuilderData.NOT_AVAILABLE;
if (token != null) {
String s = token.getValue();
String s2 = s;
if (s.length() >= 18) {
// Do a textual subtraction, then add back after conversion
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)8(\\p{XDigit}{15})$", "$10$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)9(\\p{XDigit}{15})$", "$11$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)[aA](\\p{XDigit}{15})$", "$12$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)[bB](\\p{XDigit}{15})$", "$13$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)[cC](\\p{XDigit}{15})$", "$14$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)[dD](\\p{XDigit}{15})$", "$15$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)[eE](\\p{XDigit}{15})$", "$16$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?(?:#|0[xX])0*)[fF](\\p{XDigit}{15})$", "$17$2");
if (s.equals(s2))
s2 = s.replaceFirst("^(-?010*)([01234567]{21})$", "$10$2");
}
if (s.equals(s2)) {
value = Long.decode(s).longValue();
} else {
value = Long.decode(s2).longValue() + Long.MIN_VALUE;
}
}
return value;
}
use of com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken in project openj9 by eclipse.
the class MonitorObjectLineRule method addHexToken.
protected IParserToken addHexToken(String token) {
IParserToken ret;
// Be careful as the thread ID can be prefixed while the monitor object might not be
CommonPatternMatchers.hex_0x.reset(fSource);
if (CommonPatternMatchers.hex_0x.lookingAt()) {
// Immediate 0x
ret = addPrefixedHexToken(token);
} else {
CommonPatternMatchers.hex.reset(fSource);
if (CommonPatternMatchers.hex.lookingAt()) {
// Immediate non prefixed hex
// Some older versions of Sovereign or J9 display the threadID/monitor object without the "0x" prefix.
ret = addNonPrefixedHexToken(token);
} else {
// Try looking for 0x first
ret = addPrefixedHexToken(token);
if (ret == null) {
// Some older versions of Sovereign or J9 display the threadID/monitor object without the "0x" prefix.
ret = addNonPrefixedHexToken(token);
}
;
}
}
;
return ret;
}
Aggregations