diff --git a/core/org.eclipse.cdt.core/.options b/core/org.eclipse.cdt.core/.options index 015a827ee4e..563c37c4354 100644 --- a/core/org.eclipse.cdt.core/.options +++ b/core/org.eclipse.cdt.core/.options @@ -6,6 +6,9 @@ org.eclipse.cdt.core/debug/model=false # Reports parser activity org.eclipse.cdt.core/debug/parser=false +# Prints parser stack traces +org.eclipse.cdt.core/debug/parser/exceptions=false + # Reports scanner activity org.eclipse.cdt.core/debug/scanner=false diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java index daaac501d38..dfc78b04b50 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java @@ -7,6 +7,7 @@ * * Contributors: * Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -33,6 +34,7 @@ public class Util implements ICLogConstants { public static boolean VERBOSE_PARSER = false; public static boolean VERBOSE_SCANNER = false; public static boolean VERBOSE_MODEL = false; + public static boolean PARSER_EXCEPTIONS= false; public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$ @@ -207,7 +209,7 @@ public class Util implements ICLogConstants { // Time stamp if (addTimeStamp) message = MessageFormat.format("[{0}] {1}", new Object[]{ //$NON-NLS-1$ - new Long(System.currentTimeMillis()), message}); //$NON-NLS-1$ + new Long(System.currentTimeMillis()), message}); while (message.length() > 100) { String partial = message.substring(0, 100); message = message.substring(100); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/AbstractParserLogService.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/AbstractParserLogService.java new file mode 100644 index 00000000000..186ed05da27 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/AbstractParserLogService.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.parser; + +public abstract class AbstractParserLogService implements IParserLogService { + + public void traceLog(String message) { + } + + public void errorLog(String message) { + } + + public boolean isTracing(){ + return false; + } + + boolean traceExceptions() { + return false; + } + + public void traceException(Throwable th) { + if (traceExceptions()) { + th.printStackTrace(); + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultLogService.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultLogService.java index 62d781270ee..0e7164b6422 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultLogService.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultLogService.java @@ -14,27 +14,6 @@ package org.eclipse.cdt.core.parser; * @author jcamelon * */ -public class DefaultLogService implements IParserLogService +public class DefaultLogService extends AbstractParserLogService { - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String) - */ - public void traceLog(String message) - { - // do nothing - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IParserLogService#errorLog(java.lang.String) - */ - public void errorLog(String message) - { - // do nothing - } - - public boolean isTracing(){ - return false; - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullLogService.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullLogService.java index 2ea3b898d83..91c2ac7bbe0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullLogService.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullLogService.java @@ -13,21 +13,5 @@ package org.eclipse.cdt.core.parser; /** * @author jcamelon */ -public class NullLogService implements IParserLogService { - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String) - */ - public void traceLog(String message) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IParserLogService#errorLog(java.lang.String) - */ - public void errorLog(String message) { - } - - public boolean isTracing(){ - return false; - } +public class NullLogService extends AbstractParserLogService { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index a870fb7f5ad..c9e8f1160f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -58,6 +59,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression; +import org.eclipse.cdt.core.parser.AbstractParserLogService; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IParserLogService; @@ -72,7 +74,7 @@ import org.eclipse.cdt.core.parser.ParserMode; */ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { - protected final IParserLogService log; + protected final AbstractParserLogService log; protected final IScanner scanner; @@ -97,7 +99,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { boolean supportKnRC, boolean supportGCCOtherBuiltinSymbols, boolean supportAttributeSpecifiers) { this.scanner = scanner; - this.log = logService; + this.log = wrapLogService(logService); this.mode = parserMode; this.supportStatementsInExpressions = supportStatementsInExpressions; this.supportTypeOfUnaries = supportTypeOfUnaries; @@ -107,12 +109,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { this.supportAttributeSpecifiers = supportAttributeSpecifiers; } - protected boolean parsePassed = true; + protected boolean parsePassed = true; protected BacktrackException backtrack = new BacktrackException(); protected int backtrackCount = 0; + private AbstractParserLogService wrapLogService(IParserLogService logService) { + if (logService instanceof AbstractParserLogService) { + return (AbstractParserLogService) logService; + } + else { + return new ParserLogServiceWrapper(logService); + } + } + protected final void throwBacktrack(int offset, int length) throws BacktrackException { ++backtrackCount; @@ -355,18 +366,20 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @param e */ protected void logThrowable(String methodName, Throwable e) { - if (e != null && log.isTracing()) { - StringBuffer buffer = new StringBuffer(); - buffer.append("Parser: Unexpected throwable in "); //$NON-NLS-1$ - buffer.append(methodName); - buffer.append(":"); //$NON-NLS-1$ - buffer.append(e.getClass().getName()); - buffer.append("::"); //$NON-NLS-1$ - buffer.append(e.getMessage()); - buffer.append(". w/"); //$NON-NLS-1$ - buffer.append(scanner.toString()); - log.traceLog(buffer.toString()); - // log.errorLog( buffer.toString() ); + if (e != null) { + if (log.isTracing()) { + StringBuffer buffer = new StringBuffer(); + buffer.append("Parser: Unexpected throwable in "); //$NON-NLS-1$ + buffer.append(methodName); + buffer.append(":"); //$NON-NLS-1$ + buffer.append(e.getClass().getName()); + buffer.append("::"); //$NON-NLS-1$ + buffer.append(e.getMessage()); + buffer.append(". w/"); //$NON-NLS-1$ + buffer.append(scanner.toString()); + log.traceLog(buffer.toString()); + } + log.traceException(e); } } @@ -379,18 +392,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @param e */ protected void logException(String methodName, Exception e) { - if (!(e instanceof EndOfFileException) && e != null && log.isTracing()) { - StringBuffer buffer = new StringBuffer(); - buffer.append("Parser: Unexpected exception in "); //$NON-NLS-1$ - buffer.append(methodName); - buffer.append(":"); //$NON-NLS-1$ - buffer.append(e.getClass().getName()); - buffer.append("::"); //$NON-NLS-1$ - buffer.append(e.getMessage()); - buffer.append(". w/"); //$NON-NLS-1$ - buffer.append(scanner.toString()); - log.traceLog(buffer.toString()); - // log.errorLog(buffer.toString()); + if (!(e instanceof EndOfFileException) && e != null) { + if (log.isTracing()) { + StringBuffer buffer = new StringBuffer(); + buffer.append("Parser: Unexpected exception in "); //$NON-NLS-1$ + buffer.append(methodName); + buffer.append(":"); //$NON-NLS-1$ + buffer.append(e.getClass().getName()); + buffer.append("::"); //$NON-NLS-1$ + buffer.append(e.getMessage()); + buffer.append(". w/"); //$NON-NLS-1$ + buffer.append(scanner.toString()); + log.traceLog(buffer.toString()); + // log.errorLog(buffer.toString()); + } + log.traceException(e); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ParserLogServiceWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ParserLogServiceWrapper.java new file mode 100644 index 00000000000..d0f09a2dc3c --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ParserLogServiceWrapper.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.dom.parser; + +import org.eclipse.cdt.core.parser.AbstractParserLogService; +import org.eclipse.cdt.core.parser.IParserLogService; + +public class ParserLogServiceWrapper extends AbstractParserLogService { + + private IParserLogService fDelegate; + + public ParserLogServiceWrapper(IParserLogService log) { + fDelegate= log; + } + public boolean isTracing() { + return fDelegate.isTracing(); + } + + public void traceLog(String message) { + fDelegate.traceLog(message); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java index 5a4fb9803f5..c26e53a0a2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/Messages.java @@ -16,6 +16,7 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.indexer.messages"; //$NON-NLS-1$ public static String PDOMIndexerTask_collectingFilesTask; + public static String PDOMIndexerTask_errorWhileParsing; public static String PDOMIndexerTask_parsingFileTask; static { // initialize resource bundle diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/messages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/messages.properties index 8fc64db49f5..13bfcee9eaf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/messages.properties +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/messages.properties @@ -1,2 +1,3 @@ PDOMIndexerTask_collectingFilesTask=Collecting files to parse PDOMIndexerTask_parsingFileTask=parsing {0} ({1}) +PDOMIndexerTask_errorWhileParsing=Error while parsing {0}. diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index c7945d43eff..e070cc9bd0d 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -947,6 +947,7 @@ public class CCorePlugin extends Plugin { private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$ private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$ + private static final String PARSER_EXCEPTIONS = CCorePlugin.PLUGIN_ID + "/debug/parser/exceptions" ; //$NON-NLS-1$ private static final String SCANNER = CCorePlugin.PLUGIN_ID + "/debug/scanner"; //$NON-NLS-1$ private static final String DELTA = CCorePlugin.PLUGIN_ID + "/debug/deltaprocessor" ; //$NON-NLS-1$ //private static final String CONTENTASSIST = CCorePlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$ @@ -959,7 +960,10 @@ public class CCorePlugin extends Plugin { if(CCorePlugin.getDefault().isDebugging()) { String option = Platform.getDebugOption(PARSER); if(option != null) Util.VERBOSE_PARSER = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ - + + option = Platform.getDebugOption(PARSER_EXCEPTIONS); + if( option != null ) Util.PARSER_EXCEPTIONS = option.equalsIgnoreCase("true"); //$NON-NLS-1$ + option = Platform.getDebugOption(SCANNER); if( option != null ) Util.VERBOSE_SCANNER = option.equalsIgnoreCase("true"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/parser/ParserLogService.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/parser/ParserLogService.java index 8ccee0926de..626f828efd4 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/parser/ParserLogService.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/parser/ParserLogService.java @@ -7,12 +7,13 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICLogConstants; -import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.AbstractParserLogService; import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant; @@ -20,15 +21,25 @@ import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant; * @author jcamelon * */ -public class ParserLogService implements IParserLogService +public class ParserLogService extends AbstractParserLogService { - final DebugLogConstant topic; + final DebugLogConstant topic; + final boolean fIsTracing; + final boolean fIsTracingExceptions; + /** * @param constant */ public ParserLogService(DebugLogConstant constant) { topic = constant; + if (CCorePlugin.getDefault() == null) { + fIsTracing= fIsTracingExceptions= false; + } + else { + fIsTracingExceptions= Util.PARSER_EXCEPTIONS; + fIsTracing= Util.isActive(topic); + } } /* (non-Javadoc)