diff options
author | Andrew Niefer | 2004-04-05 18:18:57 +0000 |
---|---|---|
committer | Andrew Niefer | 2004-04-05 18:18:57 +0000 |
commit | 024eca49581fcf338305dc1610be52c9bbb44581 (patch) | |
tree | 13b0c395f9f9c6b930d9494bb2ef4b38a506d5d9 /core | |
parent | bc0892c5e7b6b9f1ae3c92ad8efcb91e16fe6275 (diff) | |
download | org.eclipse.cdt-024eca49581fcf338305dc1610be52c9bbb44581.tar.gz org.eclipse.cdt-024eca49581fcf338305dc1610be52c9bbb44581.tar.xz org.eclipse.cdt-024eca49581fcf338305dc1610be52c9bbb44581.zip |
- performance improvements with Problem reporting originally from Dave Daoust
- added CompleteParseASTFactory.shouldThrowException, so we can ignore certain problems
encountered while parsing templates
- fix NPEs caused by bad type info objects
Diffstat (limited to 'core')
28 files changed, 416 insertions, 338 deletions
diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index e8c5e0bec19..3b5f0d5adc3 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2004-04-05 Andrew Niefer
+ Added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.testTemplateParametersInExpressions
+
2004-04-04 John Camelon
Added CompleteParseASTTest::testBug56516() && CompleteParseASTTests::testBug53786().
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java index 0b613e6598d..dcef1152878 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java @@ -643,4 +643,17 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest { assertAllReferences( 2, createTaskList( new Task( A, 2 ) ) ); } + + public void testTemplateParametersInExpressions() throws Exception + { + Writer writer = new StringWriter(); + writer.write( "template < typename _Tp > power( _Tp, unsigned int ); \n" ); + writer.write( "template < typename _Tp > _Tp helper( _Tp __x, int _n ) \n" ); + writer.write( "{ " ); + writer.write( " return n < 0 ? _Tp( 1 ) / power( __x, -__n ) \n" ); + writer.write( " : power( __x, __n ); \n" ); + writer.write( "} " ); + + parse( writer.toString () ); + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser index 522971b16dc..fc3095c2369 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser +++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser @@ -1,3 +1,13 @@ +2004-04-05 Andrew Niefer + - performance improvements originally from Dave Daoust: + - create new TraceUtil to handle logging trace messages + - postpone building Problem message until it is asked for + - only ask for problem message if it will actually be traced + - added more problem strings for problems coming from the symbol table + - added CompleteParseASTFactory.shouldThrowException, so we can ignore certain problems + encountered while parsing templates + - fix NPEs caused by bad type info objects + 2004-04-05 John Camelon Fixed NPE in CompleteParseASTFactory::createUsingDeclaration(). 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 b109f067c6b..6f5c51cba4b 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 @@ -32,5 +32,9 @@ public class DefaultLogService implements IParserLogService { // do nothing } + + public boolean isTracing(){ + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParserLogService.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParserLogService.java index 1da817e2e25..50c0f69184b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParserLogService.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParserLogService.java @@ -19,5 +19,7 @@ public interface IParserLogService public void traceLog( String message ); public void errorLog( String message ); + + public boolean isTracing(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java index a35639d02c3..084e4afcc04 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser; -import java.util.Map; - import org.eclipse.cdt.internal.core.parser.ParserMessages; /** @@ -55,7 +53,7 @@ public interface IProblem * * @return a map between parameter names and values. */ - Map getArguments(); + String getArguments(); /** * Answer the file name in which the problem was found. 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 4dce2e10b5b..dfa245eed06 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 @@ -27,4 +27,7 @@ public class NullLogService implements IParserLogService { public void errorLog(String message) { } + public boolean isTracing(){ + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java index 755edabde50..f4297afed9d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java @@ -43,6 +43,7 @@ import org.eclipse.cdt.internal.core.parser.token.KeywordSets; import org.eclipse.cdt.internal.core.parser.token.Token; import org.eclipse.cdt.internal.core.parser.token.TokenDuple; import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key; +import org.eclipse.cdt.internal.core.parser.util.TraceUtil; /** * @author jcamelon @@ -2469,7 +2470,7 @@ public class ExpressionParser implements IExpressionParser { } catch (ScannerException e) { - log.traceLog( "ScannerException thrown : " + e.getProblem().getMessage() ); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "ScannerException thrown : ", e.getProblem(), null, null, null); log.errorLog( "Scanner Exception: " + e.getProblem().getMessage()); //$NON-NLS-1$h failParse(); return fetchToken(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 5180ec6a136..bb899226087 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -59,6 +59,7 @@ import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; import org.eclipse.cdt.internal.core.parser.token.KeywordSets; import org.eclipse.cdt.internal.core.parser.token.TokenDuple; import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key; +import org.eclipse.cdt.internal.core.parser.util.TraceUtil; /** * This is our first implementation of the IParser interface, serving as a parser for @@ -2138,9 +2139,7 @@ public abstract class Parser extends ExpressionParser implements IParser catch (BacktrackException e) { failParse(); - log.traceLog( - "Unexpected Token =" //$NON-NLS-1$ - + image ); + TraceUtil.outputTrace( log, "Unexpected Token =", null, image, null, null ); consume(); // eat this token anyway continue; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties index 82725c1efb0..c8ed4b8efe9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties @@ -44,7 +44,20 @@ ScannerProblemFactory.error.scanner.badCharacter=Bad character sequence encounte ASTProblemFactory.error.semantic.uniqueNamePredefined=Attempt to introduce unique symbol failed : {0} ASTProblemFactory.error.semantic.nameNotFound=Attempt to use symbol failed : {0} ASTProblemFactory.error.semantic.nameNotProvided=Name not provided. +ASTProblemFactory.error.semantic.invalidConversionType=Invalid arithmetic conversion LineOffsetReconciler.error.couldNotResetReader=Could not reset Reader -BaseProblemFactory.problemPattern=IProblem : {0} in file: {1} on line: {2, number, integer}.
\ No newline at end of file +BaseProblemFactory.problemPattern=IProblem : {0} in file: {1} on line: {2, number, integer}. + +ASTProblemFactory.error.semantic.pst.ambiguousLookup=Ambiguity encountered during lookup: {0} +ASTProblemFactory.error.semantic.pst.invalidType=Invalid type encountered in: {0} +ASTProblemFactory.error.semantic.pst.circularInheritance=Circular inheritance encountered in: {0} +ASTProblemFactory.error.semantic.pst.invalidOverload=Invalid overload of the name: {0} +ASTProblemFactory.error.semantic.pst.invalidTemplate=Invalid template: {0} +ASTProblemFactory.error.semantic.pst.invalidUsing=Invalid using directive/declaration: {0} +ASTProblemFactory.error.semantic.pst.badVisibility=Symbol not visible: {0} +ASTProblemFactory.error.semantic.pst.unableToResolveFunction=Unable to resolve function: {0} +ASTProblemFactory.error.semantic.pst.invalidTemplateArgument=Invalid template argument: {0} +ASTProblemFactory.error.semantic.pst.invalidTemplateParameter=Invalid template parameter: {0} +ASTProblemFactory.error.semantic.pst.redeclaredTemplateParameter=Redeclaration of template parameter: {0} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java index 960c3cdc36f..3278b68b421 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.internal.core.parser.token.OffsetDuple; import org.eclipse.cdt.internal.core.parser.token.TokenDuple; +import org.eclipse.cdt.internal.core.parser.util.TraceUtil; /** * @author jcamelon @@ -41,15 +42,15 @@ public class SelectionParser extends ContextualParser { protected void handleNewToken(IToken value) { if( value != null && scanner.isOnTopContext() ) { - log.traceLog( "IToken provided w/offsets " + value.getOffset() + " & " + value.getEndOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ + TraceUtil.outputTrace(log, "IToken provided w/offsets ", null, value.getOffset(), " & ", value.getEndOffset() ); if( value.getOffset() == offsetRange.getFloorOffset() ) { - log.traceLog( "Offset Floor Hit w/token \"" + value.getImage() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + TraceUtil.outputTrace(log, "Offset Floor Hit w/token \"", null, value.getImage(), "\"", null ); firstTokenOfDuple = value; } if( value.getEndOffset() == offsetRange.getCeilingOffset() ) { - log.traceLog( "Offset Ceiling Hit w/token \"" + value.getImage() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + TraceUtil.outputTrace(log, "Offset Ceiling Hit w/token \"", null, value.getImage(), "\"", null ); lastTokenOfDuple = value; } if( scanner.isOnTopContext() && lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset() ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java index 18061c43c0c..82422f9e0ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java @@ -10,12 +10,7 @@ ******************************************************************************/ package org.eclipse.cdt.internal.core.parser.ast.complete; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.internal.core.parser.ParserMessages; import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; @@ -27,50 +22,14 @@ import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; */ public class ASTProblemFactory extends BaseProblemFactory implements IProblemFactory { - - protected static final Map errorMessages; - static { - errorMessages = new HashMap(); - errorMessages.put( new Integer( IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED),ParserMessages.getString("ASTProblemFactory.error.semantic.uniqueNamePredefined")); //$NON-NLS-1$ - errorMessages.put( new Integer( IProblem.SEMANTIC_NAME_NOT_FOUND), ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotFound")); //$NON-NLS-1$ - errorMessages.put( new Integer( IProblem.SEMANTIC_NAME_NOT_PROVIDED), ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotProvided")); //$NON-NLS-1$ - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory#createMessage(int, java.util.Map, int, char[]) - */ - public String createMessage(int id, Map arguments, int lineNumber, char[] fileName) { - String message = (String) errorMessages.get( new Integer(id) ); - String arg = null; - - switch (id) - { - case IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED: - case IProblem.SEMANTIC_NAME_NOT_FOUND: - arg = (String) arguments.get((IProblem.A_SYMBOL_NAME)); - break; - case IProblem.SEMANTIC_NAME_NOT_PROVIDED: - break; - default : - return null; - } - - if( arg != null ){ - message = MessageFormat.format( message, new Object [] { arg } ); - } - - Object [] args = { message, new String( fileName ), new Integer( lineNumber ) }; - return ParserMessages.getFormattedString( PROBLEM_PATTERN, args ); - } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#createProblem(int, int, int, int, char[], java.util.Map, boolean, boolean) */ public IProblem createProblem(int id, int start, int end, int line, - char[] file, Map arguments, boolean warn, boolean error) { + char[] file, String arg, boolean warn, boolean error) { if( checkBitmask( id, IProblem.INTERNAL_RELATED ) ) - return createInternalProblem( id, start, end, line, file, arguments, warn, error ); + return createInternalProblem( id, start, end, line, file, arg, warn, error ); if ( checkBitmask( id, IProblem.SEMANTICS_RELATED ) ) return super.createProblem( @@ -79,8 +38,7 @@ public class ASTProblemFactory extends BaseProblemFactory implements IProblemFac end, line, file, - createMessage(id, arguments, line, file), - arguments, + arg, warn, error); @@ -89,25 +47,20 @@ public class ASTProblemFactory extends BaseProblemFactory implements IProblemFac /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#getRequiredAttributesForId(int) */ - public String[] getRequiredAttributesForId(int id) { - String [] result = new String[1]; + public String getRequiredAttributesForId(int id) { switch (id) { case IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED : case IProblem.SEMANTIC_NAME_NOT_FOUND: case IProblem.SEMANTIC_AMBIGUOUS_LOOKUP: - result[0] = IProblem.A_SYMBOL_NAME; - break; + return IProblem.A_SYMBOL_NAME; case IProblem.SEMANTIC_INVALID_TYPE: - result[0] = IProblem.A_TYPE_NAME; - break; + return IProblem.A_TYPE_NAME; case IProblem.SEMANTIC_INVALID_USING: - result[0] = IProblem.A_NAMESPACE_NAME; - break; + return IProblem.A_NAMESPACE_NAME; case IProblem.SEMANTIC_NAME_NOT_PROVIDED: - result = new String[0]; - break; + return null; } - return result; + return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index 8787d2bc150..1d0302734cc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -12,11 +12,9 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Stack; import org.eclipse.cdt.core.parser.Enum; @@ -95,6 +93,7 @@ import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.TemplateSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException; +import org.eclipse.cdt.internal.core.parser.util.TraceUtil; /** @@ -323,7 +322,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } } if ( throwOnError ) - handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, firstSymbol.getImage() ); + handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, firstSymbol.getImage(), -1, -1, firstSymbol.getLineNumber() ); return null; } break; @@ -770,9 +769,18 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto protected void handleProblem( int id, String attribute ) throws ASTSemanticException { - handleProblem( id, attribute, -1, -1, -1 ); //TODO make this right + handleProblem( null, id, attribute, -1, -1, -1 ); //TODO make this right } + protected void handleProblem( IASTScope scope, int id, String attribute ) throws ASTSemanticException + { + handleProblem( scope, id, attribute, -1, -1, -1 ); + } + + protected void handleProblem( int id, String attribute, int startOffset, int endOffset, int lineNumber) throws ASTSemanticException { + handleProblem( null, id, attribute, startOffset, endOffset, lineNumber ); + } + /** * @param id * @param attribute @@ -781,24 +789,28 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto * @param lineNumber * @throws ASTSemanticException */ - protected void handleProblem(int id, String attribute, int startOffset, int endOffset, int lineNumber) throws ASTSemanticException { - Map arguments = new HashMap(); - - if( attribute != null ) - { - String attributes [] = problemFactory.getRequiredAttributesForId( id ); - arguments.put( attributes[ 0 ], attribute ); - } - + protected void handleProblem( IASTScope scope, int id, String attribute, int startOffset, int endOffset, int lineNumber) throws ASTSemanticException { IProblem p = problemFactory.createProblem( id, - startOffset, endOffset, lineNumber, fileProvider.getCurrentFilename(), arguments, false, true ); + startOffset, endOffset, lineNumber, fileProvider.getCurrentFilename(), attribute, false, true ); - StringBuffer logMessage = new StringBuffer( "CompleteParseASTFactory - IProblem : "); //$NON-NLS-1$ - logMessage.append( p.getMessage() ); - logService.traceLog( logMessage.toString() ); - throw new ASTSemanticException(p); + TraceUtil.outputTrace(logService, "CompleteParseASTFactory - IProblem : ", p, null, null, null ); + + if( shouldThrowException( scope, id ) ) + throw new ASTSemanticException(p); } + protected boolean shouldThrowException( IASTScope scope, int id ){ + if( scope != null ){ + IContainerSymbol symbol = scopeToSymbol( scope ); + if( symbol.isTemplateMember() ){ + if( id == IProblem.SEMANTIC_INVALID_CONVERSION_TYPE ) + { + return false; + } + } + } + return true; + } protected TypeInfo.eType classKindToTypeInfo(ASTClassKind kind) { TypeInfo.eType pstType = null; @@ -987,26 +999,34 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException { - StringBuffer logMessage = new StringBuffer(); - logMessage.append( "Entering createExpression with Kind=" ); //$NON-NLS-1$ - logMessage.append( kind.getKindName() ); if( idExpression != null ) { - logMessage.append( " idexpression=" ); //$NON-NLS-1$ - logMessage.append( idExpression.toString()); //$NON-NLS-1$ + TraceUtil.outputTrace( + logService, + "Entering createExpression with Kind=", + null, + kind.getKindName(), + " idexpression=", + idExpression.toString() + ); } else if( literal != null && !literal.equals( "" )) //$NON-NLS-1$ { - logMessage.append( " literal=" ); //$NON-NLS-1$ - logMessage.append( literal ); + TraceUtil.outputTrace( + logService, + "Entering createExpression with Kind=", + null, + kind.getKindName(), + " literal=", + literal + ); } - logService.traceLog( logMessage.toString() ); List references = new ArrayList(); ISymbol symbol = getExpressionSymbol(scope, kind, lhs, rhs, idExpression, references ); // Try to figure out the result that this expression evaluates to - ExpressionResult expressionResult = getExpressionResultType(kind, lhs, rhs, thirdExpression, typeId, literal, symbol); + ExpressionResult expressionResult = getExpressionResultType(scope, kind, lhs, rhs, thirdExpression, typeId, literal, symbol); // expression results could be empty, but should not be null // assert expressionResult != null : expressionResult; //throw new ASTSemanticException(); @@ -1146,7 +1166,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto * Apply the usual arithmetic conversions to find out the result of an expression * that has a lhs and a rhs as indicated in the specs (section 5.Expressions, page 64) */ - protected TypeInfo usualArithmeticConversions(TypeInfo lhs, TypeInfo rhs) throws ASTSemanticException{ + protected TypeInfo usualArithmeticConversions( IASTScope scope, TypeInfo lhs, TypeInfo rhs) throws ASTSemanticException{ // if you have a variable of type basic type, then we need to go to the basic type first while( (lhs.getType() == TypeInfo.t_type) && (lhs.getTypeSymbol() != null)){ @@ -1159,7 +1179,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if( !lhs.isType(TypeInfo.t__Bool, TypeInfo.t_enumerator ) && !rhs.isType(TypeInfo.t__Bool, TypeInfo.t_enumerator ) ) { - handleProblem( IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null ); + handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null ); } TypeInfo info = new TypeInfo(); @@ -1233,6 +1253,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } protected ExpressionResult getExpressionResultType( + IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, @@ -1368,13 +1389,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if (kind == IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION){ ASTExpression left =(ASTExpression)lhs; if(left == null) - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); info = left.getResultType().getResult(); if ((info != null) && (info.getTypeSymbol() != null)){ info.addOperatorExpression( TypeInfo.OperatorExpression.addressof ); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1384,12 +1405,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if (kind == IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION){ ASTExpression left =(ASTExpression)lhs; if(left == null) - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); info = left.getResultType().getResult(); if ((info != null)&& (info.getTypeSymbol() != null)){ info.addOperatorExpression( TypeInfo.OperatorExpression.indirection ); }else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1398,12 +1419,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if (kind == IASTExpression.Kind.POSTFIX_SUBSCRIPT){ ASTExpression left =(ASTExpression)lhs; if(left == null) - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); info = left.getResultType().getResult(); if ((info != null) && (info.getTypeSymbol() != null)){ info.addOperatorExpression( TypeInfo.OperatorExpression.subscript ); }else { - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); } result = new ExpressionResult(info); return result; @@ -1426,13 +1447,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ){ ASTExpression right =(ASTExpression)rhs; if (right == null) - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); info = right.getResultType().getResult(); if ((info != null) && (symbol != null)){ info.addOperatorExpression( TypeInfo.OperatorExpression.indirection ); info.setTypeSymbol(symbol); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1444,7 +1465,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto info.setType(TypeInfo.t_type); info.setTypeSymbol(symbol); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1460,10 +1481,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if((rightType != null) && (thirdType != null)){ info = conditionalExpressionConversions(rightType, thirdType); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1499,10 +1520,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if((left != null ) && (right != null)){ TypeInfo leftType =left.getResultType().getResult(); TypeInfo rightType =right.getResultType().getResult(); - info = usualArithmeticConversions(leftType, rightType); + info = usualArithmeticConversions( scope, leftType, rightType); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1537,7 +1558,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if(left != null){ info =left.getResultType().getResult(); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1610,7 +1631,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto info.setType(TypeInfo.t_type); info.setTypeSymbol(symbol); } else - handleProblem( IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); + handleProblem( scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null ); result = new ExpressionResult(info); return result; @@ -1766,7 +1787,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto addTemplateIdReferences( references, argLists[idx] ); } else - handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, image ); + handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, image, -1, -1, current.getLineNumber() ); } catch (ParserSymbolTableException e) { @@ -1877,6 +1898,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto Iterator p = parameters.iterator(); while (p.hasNext()){ ASTParameterDeclaration param = (ASTParameterDeclaration)p.next(); + if( param.getSymbol() == null ) + handleProblem( IProblem.SEMANTICS_RELATED, param.getName(), param.getNameOffset(), param.getEndingOffset(), param.getStartingLine() ); functionParameters.add(param.getSymbol().getTypeInfo()); } @@ -2637,7 +2660,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto try { template.addTemplateParameter( param.getSymbol() ); } catch (ParserSymbolTableException e) { - handleProblem( e.createProblemID(), "", startingOffset, -1, startingLine ); //$NON-NLS-1$ + handleProblem( e.createProblemID(), param.getName(), startingOffset, -1, startingLine ); } } @@ -2670,7 +2693,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto try { template.addTemplateParameter( param.getSymbol() ); } catch (ParserSymbolTableException e) { - handleProblem( e.createProblemID(), "", param.getStartingOffset(), param.getEndingOffset(), param.getStartingLine() ); //$NON-NLS-1$ + handleProblem( e.createProblemID(), param.getName(), param.getStartingOffset(), param.getEndingOffset(), param.getStartingLine() ); //$NON-NLS-1$ } } symbol = template; @@ -3053,7 +3076,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto { ISymbol typeSymbol = lookupQualifiedName( scopeToSymbol(scope), typeId.getTokenDuple(), refs, true ); if( typeSymbol == null || typeSymbol.getType() == TypeInfo.t_type ) - handleProblem( IProblem.SEMANTIC_INVALID_TYPE, id.getTypeOrClassName() ); + handleProblem( scope, IProblem.SEMANTIC_INVALID_TYPE, id.getTypeOrClassName() ); result.setTypeSymbol( typeSymbol ); typeId.addReferences( refs ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java index 932b51eb57c..5546de7afae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java @@ -10,8 +10,6 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.problem; -import java.util.Map; - import org.eclipse.cdt.core.parser.IProblem; @@ -22,10 +20,8 @@ public abstract class BaseProblemFactory { protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$ - public abstract String createMessage(int id, Map arguments, int lineNumber, char[] fileName ); - - public IProblem createProblem(int id, int start, int end, int line, char[] file, String message, Map arguments, boolean warn, boolean error) { - return new Problem( id, start, end, line, file, message, arguments, warn, error); + public IProblem createProblem(int id, int start, int end, int line, char[] file, String arg, boolean warn, boolean error) { + return new Problem( id, start, end, line, file, arg, warn, error); } public boolean checkBitmask( int id, int bitmask ) @@ -33,9 +29,9 @@ public abstract class BaseProblemFactory { return ( id & bitmask ) != 0; } - protected IProblem createInternalProblem( int id, int start, int end, int line, char [] file, Map arguments, boolean warn, boolean error ) + protected IProblem createInternalProblem( int id, int start, int end, int line, char [] file, String arg, boolean warn, boolean error ) { - return createProblem( id, start, end, line, file, createInternalMessage( id, arguments, line, file), arguments, warn, error ); + return createProblem( id, start, end, line, file, arg, warn, error ); } /** @@ -45,18 +41,18 @@ public abstract class BaseProblemFactory { * @param file * @return */ - private String createInternalMessage(int id, Map arguments, int line, char[] file) + private String createInternalMessage(int id, String arg, int line, char[] file) { - if( checkBitmask( id, IProblem.INTERNAL_RELATED )) - { - StringBuffer buffer = new StringBuffer(); - - switch( id ) - { - } - - return buffer.toString(); - } +// if( checkBitmask( id, IProblem.INTERNAL_RELATED )) +// { +// StringBuffer buffer = new StringBuffer(); +// +// switch( id ) +// { +// } +// +// return buffer.toString(); +// } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/IProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/IProblemFactory.java index 752e32d8ccd..2f5cfe468bb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/IProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/IProblemFactory.java @@ -10,8 +10,6 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.problem; -import java.util.Map; - import org.eclipse.cdt.core.parser.IProblem; /** @@ -20,7 +18,7 @@ import org.eclipse.cdt.core.parser.IProblem; */ public interface IProblemFactory { - public IProblem createProblem( int id, int start, int end, int line, char [] file, Map arguments, boolean warn, boolean error ); - public String [] getRequiredAttributesForId( int id ); + public IProblem createProblem( int id, int start, int end, int line, char [] file, String arg, boolean warn, boolean error ); + public String getRequiredAttributesForId( int id ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java index 2807e2dac11..f7986df3384 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java @@ -10,9 +10,12 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.problem; +import java.text.MessageFormat; +import java.util.HashMap; import java.util.Map; import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.internal.core.parser.ParserMessages; /** * @author jcamelon @@ -20,7 +23,7 @@ import org.eclipse.cdt.core.parser.IProblem; */ public class Problem implements IProblem { - private final Map arguments; + private final String arg; private final int id; private final int sourceStart; private final int sourceEnd; @@ -29,17 +32,17 @@ public class Problem implements IProblem { private final boolean isError; private final boolean isWarning; private final char[] originatingFileName; - private final String message; + + private String message = null; - public Problem( int id, int start, int end, int line, char [] file, String message, Map arguments, boolean warn, boolean error ) + public Problem( int id, int start, int end, int line, char [] file, String arg, boolean warn, boolean error ) { this.id = id; this.sourceStart = start; this.sourceEnd = end; this.lineNumber = line; this.originatingFileName = file; - this.message = message; - this.arguments = arguments; + this.arg = arg; this.isWarning = warn; this.isError = error; } @@ -94,10 +97,125 @@ public class Problem implements IProblem { return isWarning; } + protected static final Map errorMessages; + static { + errorMessages = new HashMap(); + errorMessages.put( + new Integer( IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED), + ParserMessages.getString("ASTProblemFactory.error.semantic.uniqueNamePredefined")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_NAME_NOT_FOUND), + ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotFound")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_NAME_NOT_PROVIDED), + ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotProvided")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_CONVERSION_TYPE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.invalidConversionType")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_AMBIGUOUS_LOOKUP ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.ambiguousLookup")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TYPE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidType")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_CIRCULAR_INHERITANCE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.circularInheritance")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_OVERLOAD ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidOverload")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TEMPLATE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplate")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_USING ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidUsing")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_BAD_VISIBILITY ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.badVisibility")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.unableToResolveFunction")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplateArgument")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TEMPLATE_PARAMETER ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplateParameter")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_REDECLARED_TEMPLATE_PARAMETER ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.redeclaredTemplateParameter")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_POUND_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_UNBALANCE_CONDITION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_CIRCULAR_INCLUSION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INVALID_DIRECTIVE), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_INVALID_ESCAPECHAR), + ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_UNBOUNDED_STRING), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_FLOATING_POINT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_HEX_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_UNEXPECTED_EOF), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_CHARACTER), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ + } + protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$ public String getMessage() { - return message; + if( message != null ) + return message; + + String msg = (String) errorMessages.get( new Integer(id) ); + if( msg == null ) + msg = ""; //$NON-NLS-1$ + + if( arg != null ){ + msg = MessageFormat.format( msg, new Object [] { arg } ); + } + + Object [] args = { msg, new String( originatingFileName ), new Integer( lineNumber ) }; + + message = ParserMessages.getFormattedString( PROBLEM_PATTERN, args ); + return message; } /* (non-Javadoc) @@ -111,8 +229,8 @@ public class Problem implements IProblem { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.IProblem#getArguments() */ - public Map getArguments() { - return arguments; + public String getArguments() { + return arg; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java index 85c8af7837a..9bd2ee04362 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2004 Rational Software Corporation and others. + * Copyright (c) 2004 IBM - Rational Software Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java index b4d733578a5..7b530e28ae6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java @@ -1,9 +1,14 @@ -/* - * Created on Feb 25, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ +/********************************************************************** + * Copyright (c) 2004 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ + package org.eclipse.cdt.internal.core.parser.pst; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java index 0837ec90f07..78ab5e94d3c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java @@ -235,7 +235,9 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz } //a function type is adjusted to become a pointer to function type - if( nfo.isType( TypeInfo.t_type ) && nfo.getTypeSymbol().isType( TypeInfo.t_function ) ){ + if( nfo.isType( TypeInfo.t_type ) && nfo.getTypeSymbol() != null && + nfo.getTypeSymbol().isType( TypeInfo.t_function ) ) + { if( nfo.getPtrOperators().size() == 0 ){ nfo.addPtrOperator( new PtrOp( PtrOp.t_pointer ) ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java index 16591f27060..614dc465601 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java @@ -946,6 +946,9 @@ public class ParserSymbolTable { } if( resolvedSymbol != null && resolvedSymbol.getTypeInfo().checkBit( TypeInfo.isTypedef ) ){ ISymbol symbol = resolvedSymbol.getTypeSymbol(); + if( symbol == null ) + throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); + TypeInfo info = ParserSymbolTable.getFlatTypeInfo( symbol.getTypeInfo() ); symbol = info.getTypeSymbol(); @@ -1815,6 +1818,9 @@ public class ParserSymbolTable { //constructors if( target.getType() == TypeInfo.t_type ){ targetDecl = target.getTypeSymbol(); + if( targetDecl == null ){ + throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); + } if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){ LookupData data = new LookupData( EMPTY_NAME, TypeInfo.t_constructor); data.parameters = new LinkedList(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java index 92a362b23b7..77c68369f39 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java @@ -31,6 +31,8 @@ public final class TemplateEngine { if( argMap == null ){ return info; } else { + if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() == null ) + return info; if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() instanceof IDeferredTemplateInstance ){ IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) info.getTypeSymbol(); TypeInfo newInfo = new TypeInfo( info ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java index a55f6714700..acc60d2ca28 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext.ContextKind; +import org.eclipse.cdt.internal.core.parser.util.TraceUtil; /** * @author aniefer @@ -72,7 +73,7 @@ public class ContextStack { if( !inclusions.add( context.getFilename() ) ) throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION ); - log.traceLog( "Scanner::ContextStack: entering inclusion " +context.getFilename()); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "Scanner::ContextStack: entering inclusion ", null, context.getFilename(), null, null ); context.getExtension().enterScope( requestor ); } else if( context.getKind() == IScannerContext.ContextKind.MACROEXPANSION ) @@ -92,12 +93,12 @@ public class ContextStack { try { currentContext.getReader().close(); } catch (IOException ie) { - log.traceLog("ContextStack : Error closing reader "); //$NON-NLS-1$ + TraceUtil.outputTrace( log, "ContextStack : Error closing reader "); //$NON-NLS-1$ } if( currentContext.getKind() == IScannerContext.ContextKind.INCLUSION ) { - log.traceLog( "Scanner::ContextStack: ending inclusion " +currentContext.getFilename()); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "Scanner::ContextStack: ending inclusion ", null, currentContext.getFilename(), null, null); inclusions.remove( currentContext.getFilename() ); currentContext.getExtension().exitScope( requestor ); } else if( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java index 6376044c8ca..b29ac676601 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.extension.IScannerExtension; +import org.eclipse.cdt.internal.core.parser.util.TraceUtil; import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException; /** @@ -85,7 +86,7 @@ public class GCCScannerExtension implements IScannerExtension { public void handlePreprocessorDirective(String directive, String restOfLine) { if( directive.equals("#include_next") ) //$NON-NLS-1$ { - scannerData.getLogService().traceLog( "GCCScannerExtension handling #include_next directive" ); //$NON-NLS-1$ + TraceUtil.outputTrace(scannerData.getLogService(), "GCCScannerExtension handling #include_next directive", null, null, null, null); // figure out the name of the current file and its path IScannerContext context = scannerData.getContextStack().getCurrentContext(); if( context.getKind() != IScannerContext.ContextKind.INCLUSION ) @@ -123,7 +124,7 @@ public class GCCScannerExtension implements IScannerExtension { try { scannerData.getContextStack().updateContext(duple.getUnderlyingReader(), duple.getFilename(), ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() ); - scannerData.getLogService().traceLog( "GCCScannerExtension handling #include_next directive successfully pushed on new include file" ); //$NON-NLS-1$ + TraceUtil.outputTrace( scannerData.getLogService(), "GCCScannerExtension handling #include_next directive successfully pushed on new include file" ); //$NON-NLS-1$ } catch (ContextException e1) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java index 0502f11d548..4c110bb6ee6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java @@ -59,6 +59,7 @@ import org.eclipse.cdt.internal.core.parser.InternalParserUtil; import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode; import org.eclipse.cdt.internal.core.parser.token.KeywordSets; import org.eclipse.cdt.internal.core.parser.token.Token; +import org.eclipse.cdt.internal.core.parser.util.TraceUtil; /** * @author jcamelon @@ -86,19 +87,18 @@ public class Scanner implements IScanner { protected void handleProblem( int problemID, String argument, int beginningOffset, boolean warning, boolean error, boolean extra ) throws ScannerException { - Map arguments = new HashMap(); - if( argument != null ) - { - String attributes [] = scannerData.getProblemFactory().getRequiredAttributesForId( problemID ); - arguments.put( attributes[ 0 ], argument ); - } - - IProblem problem = scannerData.getProblemFactory().createProblem( problemID, beginningOffset, getCurrentOffset(), scannerData.getContextStack().getCurrentLineNumber(), getCurrentFile().toCharArray(), arguments, warning, error ); + IProblem problem = scannerData.getProblemFactory().createProblem( + problemID, + beginningOffset, + getCurrentOffset(), + scannerData.getContextStack().getCurrentLineNumber(), + getCurrentFile().toCharArray(), + argument, + warning, + error ); // trace log - StringBuffer logMessage = new StringBuffer( "Scanner problem encountered: "); //$NON-NLS-1$ - logMessage.append( problem.getMessage() ); - scannerData.getLogService().traceLog( logMessage.toString() ); + TraceUtil.outputTrace(scannerData.getLogService(), "Scanner problem encountered: ", problem, null, null, null ); if( (! scannerData.getClientRequestor().acceptProblem( problem )) && extra ) throw new ScannerException( problem ); @@ -153,8 +153,8 @@ public class Scanner implements IScanner { } - log.traceLog( "Scanner constructed with the following configuration:"); //$NON-NLS-1$ - log.traceLog( "\tPreprocessor definitions from IScannerInfo: "); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "Scanner constructed with the following configuration:"); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "\tPreprocessor definitions from IScannerInfo: "); //$NON-NLS-1$ if( info.getDefinedSymbols() != null ) { @@ -168,7 +168,7 @@ public class Scanner implements IScanner { if( value instanceof String ) { addDefinition( symbolName, scannerExtension.initializeMacroValue((String) value)); - log.traceLog( "\t\tNAME = " + symbolName + " VALUE = " + value.toString() ); //$NON-NLS-1$ //$NON-NLS-2$ + TraceUtil.outputTrace(log, "\t\tNAME = ", symbolName, " VALUE = ", value.toString() ); //$NON-NLS-1$ //$NON-NLS-2$ ++numberOfSymbolsLogged; } @@ -176,22 +176,22 @@ public class Scanner implements IScanner { addDefinition( symbolName, (IMacroDescriptor)value); } if( numberOfSymbolsLogged == 0 ) - log.traceLog( "\t\tNo definitions specified."); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "\t\tNo definitions specified."); //$NON-NLS-1$ } else - log.traceLog( "\t\tNo definitions specified."); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "\t\tNo definitions specified."); //$NON-NLS-1$ - log.traceLog( "\tInclude paths from IScannerInfo: "); //$NON-NLS-1$ + TraceUtil.outputTrace( log, "\tInclude paths from IScannerInfo: "); //$NON-NLS-1$ if( info.getIncludePaths() != null ) { overwriteIncludePath( info.getIncludePaths() ); for( int i = 0; i < info.getIncludePaths().length; ++i ) - log.traceLog( "\t\tPATH: " + info.getIncludePaths()[i]); //$NON-NLS-1$ + TraceUtil.outputTrace( log, "\t\tPATH: ", info.getIncludePaths()[i], null, null); //$NON-NLS-1$ } else - log.traceLog("\t\tNo include paths specified."); //$NON-NLS-1$ + TraceUtil.outputTrace(log, "\t\tNo include paths specified."); //$NON-NLS-1$ setupBuiltInMacros(); } @@ -3019,9 +3019,7 @@ public class Scanner implements IScanner { } else { - StringBuffer logMessage = new StringBuffer( "Unexpected type of MacroDescriptor stored in definitions table: " ); //$NON-NLS-1$ - logMessage.append( expansion.getMacroType() ); - scannerData.getLogService().traceLog( logMessage.toString() ); + TraceUtil.outputTrace(scannerData.getLogService(), "Unexpected type of MacroDescriptor stored in definitions table: ", null, expansion.getMacroType().toString(), null, null); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java index 6886da71631..29a7b5a7e06 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java @@ -10,12 +10,7 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.internal.core.parser.ParserMessages; import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; @@ -25,126 +20,6 @@ import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; */ public class ScannerProblemFactory extends BaseProblemFactory implements IProblemFactory { - protected static final Map errorMessages; - static { - errorMessages = new HashMap(); - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_POUND_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), - ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), - ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN), - ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), - ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_UNBALANCE_CONDITION), - ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_CIRCULAR_INCLUSION), - ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_INVALID_DIRECTIVE), - ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.SCANNER_INVALID_ESCAPECHAR), - ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.SCANNER_UNBOUNDED_STRING), - ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.SCANNER_BAD_FLOATING_POINT), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.SCANNER_BAD_HEX_FORMAT), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.SCANNER_UNEXPECTED_EOF), - ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ - errorMessages.put( - new Integer(IProblem.SCANNER_BAD_CHARACTER), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.BaseProblemFactory#createMessage() - */ - public String createMessage(int id, Map arguments, int lineNumber, char[] fileName) - { - String message = (String) errorMessages.get( new Integer(id) ); - String arg = null; - - switch (id) - { - case IProblem.PREPROCESSOR_POUND_ERROR : - arg = (String) arguments.get(IProblem.A_PREPROC_POUND_ERROR); - break; - case IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND : - arg = (String) arguments.get((IProblem.A_PREPROC_INCLUDE_FILENAME)); - break; - case IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND : - arg = (String) arguments.get(IProblem.A_PREPROC_MACRO_NAME); - break; - case IProblem.PREPROCESSOR_UNBALANCE_CONDITION : - arg = (String) arguments.get(IProblem.A_PREPROC_CONDITIONAL_MISMATCH); - break; - case IProblem.PREPROCESSOR_INVALID_MACRO_DEFN : - arg = (String) arguments.get(IProblem.A_PREPROC_MACRO_NAME); - break; - case IProblem.PREPROCESSOR_INVALID_DIRECTIVE : - arg = (String) arguments.get(IProblem.A_PREPROC_UNKNOWN_DIRECTIVE); - break; - case IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN : - arg = (String) arguments.get(IProblem.A_PREPROC_MACRO_NAME); - break; - case IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR : - arg = (String) arguments.get(IProblem.A_PREPROC_CONDITION); - break; - case IProblem.PREPROCESSOR_MACRO_USAGE_ERROR : - arg = (String) arguments.get(IProblem.A_PREPROC_MACRO_NAME); - break; - case IProblem.PREPROCESSOR_MACRO_PASTING_ERROR : - arg = (String) arguments.get(IProblem.A_PREPROC_MACRO_NAME); - break; - case IProblem.PREPROCESSOR_CIRCULAR_INCLUSION : - arg = (String) arguments.get(IProblem.A_PREPROC_INCLUDE_FILENAME); - break; - case IProblem.SCANNER_BAD_CHARACTER : - arg = (String) arguments.get(IProblem.A_SCANNER_BADCHAR); - break; - case IProblem.SCANNER_UNBOUNDED_STRING : - case IProblem.SCANNER_INVALID_ESCAPECHAR : - case IProblem.SCANNER_BAD_FLOATING_POINT : - case IProblem.SCANNER_BAD_HEX_FORMAT : - case IProblem.SCANNER_UNEXPECTED_EOF : - break; - default : - return null; - } - - if( arg != null ){ - message = MessageFormat.format( message, new Object [] { arg } ); - } - - Object [] args = { message, new String( fileName ), new Integer( lineNumber ) }; - return ParserMessages.getFormattedString( PROBLEM_PATTERN, args ); - } - /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IProblemFactory#createProblem(int, int, int, int, char[], java.lang.String, boolean, boolean) */ @@ -154,12 +29,12 @@ public class ScannerProblemFactory extends BaseProblemFactory implements IProble int end, int line, char[] file, - Map arguments, + String arg, boolean warn, boolean error) { if( checkBitmask( id, IProblem.INTERNAL_RELATED ) ) - return createInternalProblem( id, start, end, line, file, arguments, warn, error ); + return createInternalProblem( id, start, end, line, file, arg, warn, error ); if ( checkBitmask( id, IProblem.SCANNER_RELATED ) || checkBitmask( id, IProblem.PREPROCESSOR_RELATED ) ) @@ -169,8 +44,7 @@ public class ScannerProblemFactory extends BaseProblemFactory implements IProble end, line, file, - createMessage(id, arguments, line, file), - arguments, + arg, warn, error); @@ -180,47 +54,34 @@ public class ScannerProblemFactory extends BaseProblemFactory implements IProble /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IProblemFactory#getRequiredAttributesForId(int) */ - public String[] getRequiredAttributesForId(int id) + public String getRequiredAttributesForId(int id) { - String [] result = new String[1]; switch (id) { case IProblem.PREPROCESSOR_POUND_ERROR : - result[0] = IProblem.A_PREPROC_POUND_ERROR; - break; + return IProblem.A_PREPROC_POUND_ERROR; case IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND : - result[0] = IProblem.A_PREPROC_INCLUDE_FILENAME; - break; + return IProblem.A_PREPROC_INCLUDE_FILENAME; case IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND : - result[0] = IProblem.A_PREPROC_MACRO_NAME; - break; + return IProblem.A_PREPROC_MACRO_NAME; case IProblem.PREPROCESSOR_UNBALANCE_CONDITION : - result[0] = IProblem.A_PREPROC_CONDITIONAL_MISMATCH; - break; + return IProblem.A_PREPROC_CONDITIONAL_MISMATCH; case IProblem.PREPROCESSOR_INVALID_MACRO_DEFN : - result[0] = IProblem.A_PREPROC_MACRO_NAME; - break; + return IProblem.A_PREPROC_MACRO_NAME; case IProblem.PREPROCESSOR_INVALID_DIRECTIVE : - result[0] = IProblem.A_PREPROC_UNKNOWN_DIRECTIVE; - break; + return IProblem.A_PREPROC_UNKNOWN_DIRECTIVE; case IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN : - result[0] = IProblem.A_PREPROC_MACRO_NAME; - break; + return IProblem.A_PREPROC_MACRO_NAME; case IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR : - result[0] = IProblem.A_PREPROC_CONDITION; - break; + return IProblem.A_PREPROC_CONDITION; case IProblem.PREPROCESSOR_MACRO_USAGE_ERROR : - result[0] = IProblem.A_PREPROC_MACRO_NAME; - break; + return IProblem.A_PREPROC_MACRO_NAME; case IProblem.PREPROCESSOR_MACRO_PASTING_ERROR : - result[0] = IProblem.A_PREPROC_MACRO_NAME; - break; + return IProblem.A_PREPROC_MACRO_NAME; case IProblem.PREPROCESSOR_CIRCULAR_INCLUSION : - result[0] = IProblem.A_PREPROC_INCLUDE_FILENAME; - break; + return IProblem.A_PREPROC_INCLUDE_FILENAME; case IProblem.SCANNER_BAD_CHARACTER : - result[0] = IProblem.A_SCANNER_BADCHAR; - break; + return IProblem.A_SCANNER_BADCHAR; case IProblem.SCANNER_UNBOUNDED_STRING : case IProblem.SCANNER_INVALID_ESCAPECHAR : case IProblem.SCANNER_BAD_FLOATING_POINT : @@ -228,6 +89,6 @@ public class ScannerProblemFactory extends BaseProblemFactory implements IProble case IProblem.SCANNER_UNEXPECTED_EOF : break; } - return result; + return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/Token.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/Token.java index 7f0d63f93cd..33b00495287 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/Token.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/Token.java @@ -55,7 +55,7 @@ public class Token implements IToken { public String toString() { - return "Token type=" + type + " image =" + getImage() + " offset=" + offset; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return "Token=" + type + " \"" + getImage() + "\" " + filename + ":" + lineNumber + " offset=" + offset; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } public int type; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/TraceUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/TraceUtil.java new file mode 100644 index 00000000000..02571b68db1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/TraceUtil.java @@ -0,0 +1,60 @@ +/********************************************************************** + * Copyright (c) 2004 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ + +package org.eclipse.cdt.internal.core.parser.util; + +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IProblem; + +/** + * @author ddaoust + */ +public class TraceUtil { + public static void outputTrace(IParserLogService log, String preface, IProblem problem, String first, String second, String third ) { + if( log.isTracing() ){ + StringBuffer buffer = new StringBuffer(); + buffer.append( preface != null ? preface : "" ); + buffer.append( problem != null ? problem.getMessage() : "" ); + buffer.append( first != null ? first : "" ); + buffer.append( second != null ? second : "" ); + buffer.append( third != null ? third : "" ); + log.traceLog( buffer.toString() ); + } + } + public static void outputTrace(IParserLogService log, String preface, IProblem problem, int first, String second, int third ) { + if( log.isTracing() ){ + StringBuffer buffer = new StringBuffer(); + buffer.append( preface != null ? preface : "" ); + buffer.append( problem != null ? problem.getMessage() : "" ); + buffer.append( Integer.toString( first ) ); + buffer.append( second != null ? second : "" ); + buffer.append( Integer.toString( third ) ); + log.traceLog( buffer.toString() ); + } + } + public static void outputTrace(IParserLogService log, String preface, String first, String second, String third ) { + if( log.isTracing() ){ + StringBuffer buffer = new StringBuffer(); + buffer.append( preface != null ? preface : "" ); + buffer.append( first != null ? first : "" ); + buffer.append( second != null ? second : "" ); + buffer.append( third != null ? third : "" ); + log.traceLog( buffer.toString() ); + } + } + public static void outputTrace(IParserLogService log, String preface) { + if( log.isTracing() ){ + StringBuffer buffer = new StringBuffer(); + buffer.append( preface != null ? preface : "" ); + log.traceLog( buffer.toString() ); + } + } +} 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 4ceb8440b4e..5164366fce2 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 @@ -10,6 +10,7 @@ ***********************************************************************/ 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.internal.core.model.Util; @@ -46,4 +47,10 @@ public class ParserLogService implements IParserLogService Util.log( message, ICLogConstants.CDT ); } + public boolean isTracing(){ + if( CCorePlugin.getDefault() == null ) + return false; + + return ( CCorePlugin.getDefault().isDebugging() && Util.isActive( topic ) ); + } } |