From 78f863bc01f14da837b73ca9e4cb68d0639cd9d2 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Tue, 1 Jan 2013 16:31:18 -0500 Subject: [PATCH 01/23] Bug 396749 - Checker is not enabled if only one problem is selected --- .../eclipse/cdt/codan/internal/core/CheckersRegistry.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java index 6e34549c8a8..89ec54fe986 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Alena Laskavaia + * Copyright (c) 2009, 2013 Alena Laskavaia * 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 @@ -417,9 +417,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { IProblem problem = resourceProfile.findProblem(p.getId()); if (problem == null) throw new IllegalArgumentException(p.getId() + " is not registered"); //$NON-NLS-1$ - if (!problem.isEnabled()) - return false; - if (checker instanceof AbstractCheckerWithProblemPreferences) { + if (problem.isEnabled() && checker instanceof AbstractCheckerWithProblemPreferences) { LaunchModeProblemPreference pref = ((AbstractCheckerWithProblemPreferences) checker).getLaunchModePreference(problem); if (pref.isRunningInMode(mode)) { From 76ddab24aaa07cfd9d785694653952ad09efab44 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 31 Dec 2012 16:34:48 -0800 Subject: [PATCH 02/23] Cosmetics. --- .../parser/scanner/MacroDefinitionParser.java | 50 +++--- .../core/parser/scanner/MacroExpander.java | 158 +++++++++--------- .../parser/scanner/MacroExpansionStep.java | 8 +- .../parser/scanner/MacroExpansionTracker.java | 22 +-- .../core/parser/scanner/StreamHasher.java | 3 +- .../internal/core/parser/scanner/Token.java | 13 +- .../core/parser/scanner/TokenForDigraph.java | 2 +- .../core/parser/scanner/TokenList.java | 41 ++--- .../core/parser/scanner/TokenUtil.java | 42 +++-- 9 files changed, 167 insertions(+), 172 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java index 15221454f32..5eaf6696381 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java @@ -7,7 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; import java.util.ArrayList; @@ -45,22 +45,22 @@ public class MacroDefinitionParser { */ static class TokenParameterReference extends TokenWithImage { private final int fIndex; - + public TokenParameterReference(int type, int idx, Object source, int offset, int endOffset, char[] name) { super(type, source, offset, endOffset, name); fIndex= idx; } - + public int getIndex() { return fIndex; } - + @Override public String toString() { return "[" + fIndex + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } } - + public static char[] getExpansion(AbstractCharArray expansionImage, int offset, int endOffset) { TokenList tl= new TokenList(); Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null); @@ -83,7 +83,7 @@ public class MacroDefinitionParser { buf.append(t.getCharImage()); endOffset= t.getEndOffset(); } - final int length= buf.length(); + final int length= buf.length(); final char[] expansion= new char[length]; buf.getChars(0, length, expansion, 0); return expansion; @@ -93,10 +93,10 @@ public class MacroDefinitionParser { private int fExpansionOffset; private int fExpansionEndOffset; private Token fNameToken; - + MacroDefinitionParser() { } - + /** * In case the name was successfully parsed, the name token is returned. * Otherwise the return value is undefined. @@ -105,10 +105,10 @@ public class MacroDefinitionParser { return fNameToken; } - /** + /** * Parses an entire macro definition. Name must be the next token of the lexer. */ - public ObjectStyleMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log) + public ObjectStyleMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log) throws OffsetLimitReachedException, InvalidMacroDefinitionException { final Token name = parseName(lexer); final AbstractCharArray source= lexer.getInput(); @@ -122,10 +122,10 @@ public class MacroDefinitionParser { return new FunctionStyleMacro(nameChars, paramList, fHasVarArgs, fExpansionOffset, fExpansionEndOffset, replacement, source); } - /** + /** * Parses a macro definition without the replacement. Name must be the next token of the lexer. */ - public PreprocessorMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log, final char[] replacement) + public PreprocessorMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log, final char[] replacement) throws InvalidMacroDefinitionException, OffsetLimitReachedException { final Token name = parseName(lexer); @@ -135,14 +135,14 @@ public class MacroDefinitionParser { if (replacementToken.getType() != IToken.tEND_OF_INPUT) { throw new InvalidMacroDefinitionException(nameChars, replacementToken.getOffset(), replacementToken.getEndOffset()); } - - if (paramList == null) { + + if (paramList == null) { return new ObjectStyleMacro(nameChars, replacement); } return new FunctionStyleMacro(nameChars, paramList, fHasVarArgs, replacement); } - /** + /** * Parses a macro definition basically checking for var-args. */ public static PreprocessorMacro parseMacroDefinition(final char[] name, char[][] paramList, final char[] replacement) { @@ -176,8 +176,8 @@ public class MacroDefinitionParser { } } } - - if (paramList == null) { + + if (paramList == null) { return new ObjectStyleMacro(name, replacement); } return new FunctionStyleMacro(name, paramList, hasVarargs, replacement); @@ -195,11 +195,11 @@ public class MacroDefinitionParser { fNameToken= name; return name; } - + private char[][] parseParamList(Lexer lex, final Token name) throws OffsetLimitReachedException, InvalidMacroDefinitionException { final Token lparen= lex.nextToken(); fHasVarArgs= FunctionStyleMacro.NO_VAARGS; - if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) { + if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) { return null; } ArrayList paramList= new ArrayList(); @@ -224,7 +224,7 @@ public class MacroDefinitionParser { paramList.add(Keywords.cVA_ARGS); next= lex.nextToken(); break; - + case IToken.tRPAREN: if (next == null) { next= param; @@ -255,7 +255,7 @@ public class MacroDefinitionParser { Token needAnotherToken= null; Token candidate= lexer.currentToken(); - fExpansionOffset= fExpansionEndOffset= candidate.getOffset(); + fExpansionOffset= fExpansionEndOffset= candidate.getOffset(); loop: while(true) { switch (candidate.getType()) { @@ -266,18 +266,16 @@ public class MacroDefinitionParser { break loop; case IToken.tIDENTIFIER: if (paramList != null) { - // convert the parameters to special tokens + // Convert the parameters to special tokens. final char[] image = candidate.getCharImage(); int idx= CharArrayUtils.indexOf(image, paramList); if (idx >= 0) { candidate= new TokenParameterReference(CPreprocessor.tMACRO_PARAMETER, idx, lexer.getSource(), candidate.getOffset(), candidate.getEndOffset(), paramList[idx]); needParam= false; - } - else { + } else { if (needParam) { log.handleProblem(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, name, fExpansionOffset, candidate.getEndOffset()); - } - else if (CharArrayUtils.equals(Keywords.cVA_ARGS, image)) { + } else if (CharArrayUtils.equals(Keywords.cVA_ARGS, image)) { log.handleProblem(IProblem.PREPROCESSOR_INVALID_VA_ARGS, null, fExpansionOffset, candidate.getEndOffset()); } needParam= false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java index 669bfd2cce4..ae1c0cc4983 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java @@ -7,7 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; import java.util.ArrayList; @@ -35,9 +35,9 @@ public class MacroExpander { private static final class AbortMacroExpansionException extends Exception {} private static final int ORIGIN = OffsetLimitReachedException.ORIGIN_MACRO_EXPANSION; - private static final TokenList EMPTY_TOKEN_LIST = new TokenList(); + private static final TokenList EMPTY_TOKEN_LIST = new TokenList(); - /** + /** * Marks the beginning and the end of the scope of a macro expansion. Necessary to properly * handle recursive expansions and to figure out whether spaces are required during a stringify * operation across such boundaries. @@ -56,7 +56,7 @@ public class MacroExpander { public char[] getCharImage() { return CharArrayUtils.EMPTY; } - + @Override public String toString() { return "{" + (fIsStart ? '+' : '-') + fMacro.getName() + '}'; //$NON-NLS-1$ @@ -70,8 +70,8 @@ public class MacroExpander { } } } - - /** + + /** * Combines a list of tokens with the preprocessor to form the input for macro expansion. */ private class TokenSource extends TokenList { @@ -112,7 +112,7 @@ public class MacroExpander { if (fLexer != null) { t= fLexer.currentToken(); - while(t.getType() == Lexer.tNEWLINE) { + while (t.getType() == Lexer.tNEWLINE) { t= fLexer.nextToken(); } return t.getType() == IToken.tLPAREN; @@ -131,14 +131,14 @@ public class MacroExpander { private boolean fCompletionMode; private int fStartOffset; private int fEndOffset; - + // for using the expander to track expansions private String fFixedCurrentFilename; private int fFixedLineNumber; private char[] fFixedInput; private ScannerContext fReportMacros; private boolean fReportUndefined; - + public MacroExpander(ILexerLog log, CharArrayMap macroDictionary, LocationMap locationMap, LexerOptions lexOptions) { fDictionary= macroDictionary; @@ -147,10 +147,10 @@ public class MacroExpander { fLexOptions= lexOptions; fLog= log; } - - /** + + /** * Expects that the identifier has been consumed, stores the result in the list provided. - * @param scannerContext + * @param scannerContext */ public TokenList expand(ITokenSequence lexer, final int ppOptions, PreprocessorMacro macro, Token identifier, boolean completionMode, @@ -162,16 +162,16 @@ public class MacroExpander { } else { fReportMacros= null; } - + fImplicitMacroExpansions.clear(); fImageLocationInfos.clear(); - + fStartOffset= identifier.getOffset(); fEndOffset= identifier.getEndOffset(); fCompletionMode= completionMode; - + IdentityHashMap forbidden= new IdentityHashMap(); - + // setup input sequence TokenSource input= new TokenSource(lexer); TokenList firstExpansion= new TokenList(); @@ -186,8 +186,8 @@ public class MacroExpander { result= expandAll(input, forbidden, protectDefined, null); } catch (CompletionInMacroExpansionException e) { - // For content assist in macro expansions, we return the list of tokens of the - // parameter at the current cursor position and hope that they make sense if + // For content assist in macro expansions, we return the list of tokens of the + // parameter at the current cursor position and hope that they make sense if // they are inserted at the position of the expansion. // For a better solution one would have to perform the expansion with artificial // parameters and then check where the completion token ends up in the expansion. @@ -211,7 +211,7 @@ public class MacroExpander { fFixedLineNumber= lineNumber; fReportMacros= null; Lexer lexer= new Lexer(fFixedInput, fLexOptions, fLog, this); - + try { tracker.start(fFixedInput); Token identifier= lexer.nextToken(); @@ -246,21 +246,21 @@ public class MacroExpander { } catch (OffsetLimitReachedException e) { } } - + /** * Expects that the identifier of the macro expansion has been consumed. Expands the macro * consuming tokens from the input (to read the parameters) and stores the resulting tokens * together with boundary markers in the result token list. * @return the last token of the expansion. - * @throws AbortMacroExpansionException + * @throws AbortMacroExpansionException */ - private Token expandOne(Token lastConsumed, PreprocessorMacro macro, + private Token expandOne(Token lastConsumed, PreprocessorMacro macro, IdentityHashMap forbidden, TokenSource input, TokenList result, MacroExpansionTracker tracker) throws OffsetLimitReachedException { if (fReportMacros != null) fReportMacros.significantMacro(macro); - + if (macro.isFunctionStyle()) { final int paramCount = macro.getParameterPlaceholderList().length; final TokenSource[] argInputs= new TokenSource[paramCount]; @@ -271,13 +271,13 @@ public class MacroExpander { try { lastConsumed= parseArguments(input, (FunctionStyleMacro) macro, forbidden, argInputs, tracker); } catch (AbortMacroExpansionException e) { - // ignore this macro expansion + // Ignore this macro expansion. for (TokenSource argInput : argInputs) { executeScopeMarkers(argInput, forbidden); if (tracker != null) { tracker.setExpandedMacroArgument(null); } - } + } if (tracker != null) { if (tracker.isRequestedStep()) { tracker.storeFunctionStyleMacroReplacement(macro, new TokenList(), result); @@ -288,7 +288,7 @@ public class MacroExpander { } return null; } - + TokenList[] clonedArgs= new TokenList[paramCount]; TokenList[] expandedArgs= new TokenList[paramCount]; for (int i = 0; i < paramCount; i++) { @@ -342,11 +342,11 @@ public class MacroExpander { private void executeScopeMarkers(TokenSource input, IdentityHashMap forbidden) { Token t= input.removeFirst(); - while(t != null) { + while (t != null) { if (t.getType() == CPreprocessor.tSCOPE_MARKER) { ((ExpansionBoundary) t).execute(forbidden); } - t= input.removeFirst(); + t= input.removeFirst(); } } @@ -356,7 +356,7 @@ public class MacroExpander { boolean protect= false; Token l= null; Token t= input.removeFirst(); - while(t != null) { + while (t != null) { switch (t.getType()) { case CPreprocessor.tSCOPE_MARKER: ((ExpansionBoundary) t).execute(forbidden); @@ -395,7 +395,7 @@ public class MacroExpander { addSpacemarker(l, t, replacement); // start expansion replacement.append(new ExpansionBoundary(macro, true)); - Token last= expandOne(t, macro, forbidden, input, replacement, tracker); + Token last= expandOne(t, macro, forbidden, input, replacement, tracker); replacement.append(new ExpansionBoundary(macro, false)); addSpacemarker(last, input.first(), replacement); // end expansion @@ -404,12 +404,12 @@ public class MacroExpander { break; case IToken.tLPAREN: case CPreprocessor.tNOSPACE: - case CPreprocessor.tSPACE: + case CPreprocessor.tSPACE: result.append(t); break; default: protect= false; - result.append(t); + result.append(t); break; } l= t; @@ -450,26 +450,26 @@ public class MacroExpander { } target.append(new Token(CPreprocessor.tNOSPACE, null, 0, 0)); } - + /** * Expects that the identifier has been consumed. */ private Token parseArguments(TokenSource input, FunctionStyleMacro macro, - IdentityHashMap forbidden, + IdentityHashMap forbidden, TokenSource[] result, MacroExpansionTracker tracker) throws OffsetLimitReachedException, AbortMacroExpansionException { final int argCount= macro.getParameterPlaceholderList().length; final boolean hasVarargs= macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS; - final int requiredArgs= hasVarargs ? argCount-1 : argCount; + final int requiredArgs= hasVarargs ? argCount - 1 : argCount; int idx= 0; int nesting= -1; for (int i = 0; i < result.length; i++) { result[i]= new TokenSource(null); } - + boolean missingRParenthesis= false; boolean tooManyArgs= false; - + boolean isFirstOfArg= true; Token lastToken= null; TokenList spaceMarkers= new TokenList(); @@ -481,7 +481,7 @@ public class MacroExpander { } if (tracker != null) { switch (t.getType()) { - case IToken.tEND_OF_INPUT: + case IToken.tEND_OF_INPUT: case IToken.tCOMPLETION: case CPreprocessor.tSCOPE_MARKER: case Lexer.tNEWLINE: @@ -509,28 +509,28 @@ public class MacroExpander { throw new CompletionInMacroExpansionException(ORIGIN, t, result[idx]); } throw new OffsetLimitReachedException(ORIGIN, t); - + case Lexer.tNEWLINE: continue loop; case IToken.tLPAREN: - // the first one sets nesting to zero. + // The first one sets nesting to zero. if (++nesting == 0) { continue; } break; - + case IToken.tRPAREN: assert nesting >= 0; if (--nesting < 0) { break loop; } break; - + case IToken.tCOMMA: assert nesting >= 0; if (nesting == 0) { - if (idx < argCount-1) { // next argument + if (idx < argCount - 1) { // Next argument. isFirstOfArg= true; spaceMarkers.clear(); idx++; @@ -541,7 +541,7 @@ public class MacroExpander { } } break; - + case CPreprocessor.tSCOPE_MARKER: if (argCount == 0) { ((ExpansionBoundary) t).execute(forbidden); @@ -549,14 +549,14 @@ public class MacroExpander { result[idx].append(t); } continue loop; - + case CPreprocessor.tSPACE: case CPreprocessor.tNOSPACE: if (!isFirstOfArg) { spaceMarkers.append(t); } continue loop; - + default: assert nesting >= 0; } @@ -573,7 +573,7 @@ public class MacroExpander { handleProblem(IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST, macro.getNameCharArray()); throw new AbortMacroExpansionException(); } - + if (tooManyArgs) { handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, macro.getNameCharArray()); } else if (idx + 1 < requiredArgs) { @@ -581,18 +581,18 @@ public class MacroExpander { } return lastToken; } - + private void handleProblem(int problemID, char[] arg) { fLog.handleProblem(problemID, arg, fStartOffset, fEndOffset); } private void replaceArgs(PreprocessorMacro macro, TokenList[] args, TokenList[] expandedArgs, TokenList result) { TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this)); - + Token l= null; - Token n; - Token pasteArg1= null; - for (Token t= replacement.first(); t != null; l=t, t=n) { + Token n; + Token pasteArg1= null; + for (Token t= replacement.first(); t != null; l= t, t= n) { n= (Token) t.getNext(); switch (t.getType()) { @@ -614,7 +614,7 @@ public class MacroExpander { } } break; - + case IToken.tPOUND: addSpacemarker(l, t, result); // start stringify StringBuilder buf= new StringBuilder(); @@ -628,19 +628,19 @@ public class MacroExpander { n= (Token) n.getNext(); } buf.append('"'); - final int length= buf.length(); + final int length= buf.length(); final char[] image= new char[length]; buf.getChars(0, length, image, 0); - + Token generated= new TokenWithImage(IToken.tSTRING, null, 0, 0, image); if (isKind(n, IToken.tPOUNDPOUND)) { // start token paste, same as start stringify - pasteArg1= generated; + pasteArg1= generated; } else { result.append(generated); addSpacemarker(t, n, result); // end stringify } break; - + case IToken.tPOUNDPOUND: Token pasteArg2= null; TokenList rest= null; @@ -664,7 +664,7 @@ public class MacroExpander { idx= -1; pasteArg2= n; } - + t= n; n= (Token) n.getNext(); final boolean pasteNext= isKind(n, IToken.tPOUNDPOUND); @@ -676,7 +676,7 @@ public class MacroExpander { generated= pasteArg1; if (rest == null) rest= new TokenList(); - + rest.prepend(pasteArg2); spaceDef0= generated; spaceDef1= pasteArg2; @@ -707,15 +707,15 @@ public class MacroExpander { } } break; - + case IToken.tCOMMA: if (isKind(n, IToken.tPOUNDPOUND)) { final Token nn= (Token) n.getNext(); if (isKind(nn, CPreprocessor.tMACRO_PARAMETER)) { idx= ((TokenParameterReference) nn).getIndex(); - + // check for gcc-extension preventing the paste operation - if (idx == args.length-1 && macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS && + if (idx == args.length - 1 && macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS && !isKind(nn.getNext(), IToken.tPOUNDPOUND)) { final Token nnn= (Token) nn.getNext(); TokenList arg= clone(expandedArgs[idx]); @@ -733,14 +733,14 @@ public class MacroExpander { break; } } - + addSpacemarker(l, t, result); pasteArg1= t; } else { result.append(t); } break; - + default: if (isKind(n, IToken.tPOUNDPOUND)) { addSpacemarker(l, t, result); // start token paste @@ -752,7 +752,7 @@ public class MacroExpander { } } } - + private boolean isKind(final IToken t, final int kind) { return t != null && t.getType() == kind; } @@ -760,9 +760,9 @@ public class MacroExpander { private BitSet getParamUsage(PreprocessorMacro macro) { final BitSet result= new BitSet(); final TokenList replacement= macro.getTokens(fDefinitionParser, fLexOptions, this); - + Token l= null; - Token n; + Token n; for (Token t= replacement.first(); t != null; l= t, t= n) { n= (Token) t.getNext(); switch (t.getType()) { @@ -773,7 +773,7 @@ public class MacroExpander { } result.set(idx); break; - + case IToken.tPOUND: if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) { idx= ((TokenParameterReference) n).getIndex(); @@ -781,7 +781,7 @@ public class MacroExpander { t= n; n= (Token) n.getNext(); } break; - + case IToken.tPOUNDPOUND: if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) { idx= ((TokenParameterReference) n).getIndex(); @@ -795,17 +795,17 @@ public class MacroExpander { t= n; n= (Token) n.getNext(); } break; - } + } } return result; } private void objStyleTokenPaste(PreprocessorMacro macro, TokenList result) { TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this)); - + Token l= null; - Token n; - Token pasteArg1= null; + Token n; + Token pasteArg1= null; for (Token t= replacement.first(); t != null; l= t, t= n) { n= (Token) t.getNext(); @@ -817,7 +817,7 @@ public class MacroExpander { pasteArg2= n; n= (Token) n.getNext(); } - + t= tokenpaste(pasteArg1, pasteArg2, macro); if (t != null) { if (isKind(n, IToken.tPOUNDPOUND)) { @@ -829,7 +829,7 @@ public class MacroExpander { } } break; - + default: if (isKind(n, IToken.tPOUNDPOUND)) { addSpacemarker(l, t, result); // start token paste @@ -910,7 +910,7 @@ public class MacroExpander { } space= false; break; - + case CPreprocessor.tSPACE: if (!space && l != null && n != null) { buf.append(' '); @@ -920,7 +920,7 @@ public class MacroExpander { case CPreprocessor.tNOSPACE: break; - + default: buf.append(t.getCharImage()); space= false; @@ -928,7 +928,7 @@ public class MacroExpander { } } } - + public IASTName[] clearImplicitExpansions() { IASTName[] result= fImplicitMacroExpansions.toArray(new IASTName[fImplicitMacroExpansions.size()]); fImplicitMacroExpansions.clear(); @@ -983,7 +983,7 @@ public class MacroExpander { l= t; } } - + int getCurrentLineNumber() { if (fFixedInput != null) { return fFixedLineNumber + countNewlines(fFixedInput); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionStep.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionStep.java index 7fe0cf05e73..410e938d4e6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionStep.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionStep.java @@ -7,7 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; @@ -30,12 +30,12 @@ public class MacroExpansionStep implements IMacroExpansionStep { fMacroDefinition= def; fMacroLocation= macroLoc; } - + @Override public String getCodeBeforeStep() { return fBefore; } - + @Override public String getCodeAfterStep() { StringBuilder result= new StringBuilder(); @@ -49,7 +49,7 @@ public class MacroExpansionStep implements IMacroExpansionStep { result.append(fBefore, offset, fBefore.length()); return result.toString(); } - + @Override public IMacroBinding getExpandedMacro() { return fMacroDefinition; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java index 3d96a1318ea..ebfcddef978 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java @@ -7,7 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; import java.util.ArrayList; @@ -35,7 +35,7 @@ public class MacroExpansionTracker { } private final int fStepToTrack; - + private int fStepCount; private String fPreStep; private ReplaceEdit fReplacement; @@ -58,14 +58,14 @@ public class MacroExpansionTracker { public boolean isDone() { return fStepCount > fStepToTrack; } - + /** * Returns whether we are currently looking at the requested step. */ public boolean isRequestedStep() { return fStepCount == fStepToTrack; } - + /** * Returns the total amount of steps encountered so far. */ @@ -79,7 +79,7 @@ public class MacroExpansionTracker { public String getCodeBeforeStep() { return fPreStep; } - + /** * Returns the replacement that represents the change by the step that was tracked. */ @@ -132,7 +132,7 @@ public class MacroExpansionTracker { fReplacement= new ReplaceEdit(offset, replace.length(), fReplacementText); } } - + /** * There was no macro at the beginning of the input. */ @@ -140,7 +140,7 @@ public class MacroExpansionTracker { fPreStep= new String(fInput); fReplacement= new ReplaceEdit(0, 0, ""); //$NON-NLS-1$ } - + private void toString(TokenList tokenList, char[] rootInput, StringBuilder before, StringBuilder replace, StringBuilder after) { StringBuilder buf= before; @@ -176,7 +176,7 @@ public class MacroExpansionTracker { } } } - + private char[] getInputForSource(Object source, char[] rootInput) { if (source instanceof MacroExpander) { return rootInput; @@ -197,7 +197,7 @@ public class MacroExpansionTracker { public void startFunctionStyleMacro(Token identifier) { fMacroStack.add(new MacroInfo(identifier)); } - + /** * All tokens defining a function-style macro expansion are reported. */ @@ -235,7 +235,7 @@ public class MacroExpansionTracker { * Append the current function-style macro with the arguments substituted. */ public void appendFunctionStyleMacro(TokenList result) { - MacroInfo minfo= fMacroStack.getLast(); + MacroInfo minfo= fMacroStack.getLast(); boolean active= true; int nesting= -1; int pcount= 0; @@ -298,7 +298,7 @@ public class MacroExpansionTracker { result.append(t); } break; - + default: if (active) { result.append(t); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/StreamHasher.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/StreamHasher.java index 5cbf46fae79..d2b9d151ad0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/StreamHasher.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/StreamHasher.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation + * Sergey Prigogin (Google) - initial API and implementation * * Based on lookup3.c, by Bob Jenkins {@link "http://burtleburtle.net/bob/c/lookup3.c"} * @@ -44,7 +44,6 @@ * mixing with 12*3 instructions on 3 integers than you can with 3 instructions * on 1 byte), but shoehorning those bytes into integers efficiently is messy. *******************************************************************************/ - package org.eclipse.cdt.internal.core.parser.scanner; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java index 14e682f5d15..46174108f57 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; import org.eclipse.cdt.core.parser.IToken; @@ -48,7 +48,7 @@ public class Token implements IToken, Cloneable { @Override final public int getLength() { - return fEndOffset-fOffset; + return fEndOffset - fOffset; } @Override @@ -56,7 +56,6 @@ public class Token implements IToken, Cloneable { return fNextToken; } - @Override final public void setType(int kind) { fKind= kind; @@ -73,8 +72,8 @@ public class Token implements IToken, Cloneable { } public void shiftOffset(int shift) { - fOffset+= shift; - fEndOffset+= shift; + fOffset += shift; + fEndOffset += shift; } @Override @@ -86,7 +85,7 @@ public class Token implements IToken, Cloneable { public String toString() { return getImage(); } - + @Override final public boolean isOperator() { return TokenUtil.isOperator(fKind); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenForDigraph.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenForDigraph.java index fabc818f718..3446a128900 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenForDigraph.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenForDigraph.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java index e47c293f34b..5fc7d31abcb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; class TokenList { @@ -17,7 +17,8 @@ class TokenList { final Token removeFirst() { final Token first= fFirst; if (first == fLast) { - fFirst= fLast= null; + fFirst= null; + fLast= null; return first; } fFirst= (Token) first.getNext(); @@ -26,38 +27,38 @@ class TokenList { public final void append(Token t) { if (fFirst == null) { - fFirst= fLast= t; - } - else { + fFirst= t; + fLast= t; + } else { fLast.setNext(t); fLast= t; } t.setNext(null); } - + public final void appendAll(TokenList tl) { final Token t= tl.first(); if (t != null) { if (fFirst == null) { fFirst= tl.fFirst; - } - else { + } else { fLast.setNext(tl.fFirst); } fLast= tl.fLast; } - tl.fFirst= tl.fLast= null; + tl.fFirst= null; + tl.fLast= null; } public final void appendAllButLast(TokenList tl) { Token t= tl.first(); if (t != null) { - for (Token n= (Token) t.getNext(); n != null; t=n, n= (Token) n.getNext()) { + for (Token n= (Token) t.getNext(); n != null; t= n, n= (Token) n.getNext()) { append(t); } } } - + public final void prepend(Token t) { final Token first= t; if (first != null) { @@ -81,7 +82,7 @@ class TokenList { } } } - + public final TokenList cloneTokens() { TokenList result= new TokenList(); for (Token t= fFirst; t != null; t= (Token) t.getNext()) { @@ -110,8 +111,7 @@ class TokenList { fLast= null; } } - } - else { + } else { final Token r= (Token) l.getNext(); if (r != null) { l.setNext(r.getNext()); @@ -124,19 +124,20 @@ class TokenList { void cutAfter(Token l) { if (l == null) { - fFirst= fLast= null; - } - else { + fFirst= null; + fLast= null; + } else { l.setNext(null); fLast= l; } } public void clear() { - fFirst= fLast= null; + fFirst= null; + fLast= null; } public boolean isEmpty() { - return fFirst==null; + return fFirst == null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenUtil.java index 2bc67dddc80..2a6489fc329 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenUtil.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; import org.eclipse.cdt.core.parser.IGCCToken; @@ -20,7 +20,7 @@ public class TokenUtil { private static final char[] SPACE = {' '}; private static final char[] IMAGE_POUND_POUND = "##".toCharArray(); //$NON-NLS-1$ private static final char[] IMAGE_POUND = "#".toCharArray(); //$NON-NLS-1$ - + private static final char[] DIGRAPH_LBRACE= "<%".toCharArray(); //$NON-NLS-1$ private static final char[] DIGRAPH_RBRACE= "%>".toCharArray(); //$NON-NLS-1$ private static final char[] DIGRAPH_LBRACKET= "<:".toCharArray(); //$NON-NLS-1$ @@ -40,7 +40,7 @@ public class TokenUtil { case IToken.tSHIFTL: case IToken.tSHIFTLASSIGN: case IToken.tSHIFTR: case IToken.tSHIFTRASSIGN: case IToken.tXOR: case IToken.tXORASSIGN: - + // logical operations case IToken.tNOT: case IToken.tAND: case IToken.tOR: @@ -52,25 +52,25 @@ public class TokenUtil { case IToken.tPLUS: case IToken.tPLUSASSIGN: case IToken.tSTAR: case IToken.tSTARASSIGN: case IGCCToken.tMAX: case IGCCToken.tMIN: - + // comparison case IToken.tEQUAL: case IToken.tNOTEQUAL: case IToken.tGT: case IToken.tGTEQUAL: case IToken.tLT: case IToken.tLTEQUAL: - + // other case IToken.tASSIGN: case IToken.tCOMMA: return true; } - + return false; } public static char[] getImage(int type) { switch (type) { case IToken.tPOUND: return IMAGE_POUND; - case IToken.tPOUNDPOUND: return IMAGE_POUND_POUND; - case IToken.tCOLONCOLON: return Keywords.cpCOLONCOLON; + case IToken.tPOUNDPOUND: return IMAGE_POUND_POUND; + case IToken.tCOLONCOLON: return Keywords.cpCOLONCOLON; case IToken.tCOLON: return Keywords.cpCOLON; case IToken.tSEMI: return Keywords.cpSEMI; case IToken.tCOMMA: return Keywords.cpCOMMA; @@ -120,34 +120,33 @@ public class TokenUtil { case IToken.tDOT: return Keywords.cpDOT; case IToken.tDIVASSIGN: return Keywords.cpDIVASSIGN; case IToken.tDIV: return Keywords.cpDIV; - + case IGCCToken.tMIN: return Keywords.cpMIN; case IGCCToken.tMAX: return Keywords.cpMAX; - - case CPreprocessor.tSPACE: return SPACE; + + case CPreprocessor.tSPACE: return SPACE; case CPreprocessor.tNOSPACE: return CharArrayUtils.EMPTY; - + default: - return CharArrayUtils.EMPTY; + return CharArrayUtils.EMPTY; } } - + public static char[] getDigraphImage(int type) { switch (type) { case IToken.tPOUND: return DIGRAPH_POUND; - case IToken.tPOUNDPOUND: return DIGRAPH_POUNDPOUND; + case IToken.tPOUNDPOUND: return DIGRAPH_POUNDPOUND; case IToken.tLBRACKET: return DIGRAPH_LBRACKET; case IToken.tRBRACKET: return DIGRAPH_RBRACKET; case IToken.tLBRACE: return DIGRAPH_LBRACE; case IToken.tRBRACE: return DIGRAPH_RBRACE; - + default: assert false: type; - return CharArrayUtils.EMPTY; + return CharArrayUtils.EMPTY; } } - - + /** * Returns the last token in the given token list. * @throws NullPointerException if the argument is null @@ -156,8 +155,7 @@ public class TokenUtil { IToken last; do { last = tokenList; - } while((tokenList = tokenList.getNext()) != null); + } while ((tokenList = tokenList.getNext()) != null); return last; } - } From 3b6247d7cf3fb23d5f3f7fb02d886fff0e53c994 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 2 Jan 2013 14:13:07 -0800 Subject: [PATCH 03/23] Changed default preferences to not produce a warning for the last case in a switch statement. --- .../cdt/codan/internal/checkers/CaseBreakChecker.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java index b6b001ae71a..2c528ab5153 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Gil Barash + * Copyright (c) 2010, 2013 Gil Barash * 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 @@ -116,7 +116,7 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke if (str.toLowerCase().contains(fNoBreakComment.toLowerCase())) continue; } - reportProblem(curr, prevCase); + reportProblem(curr); } } } @@ -159,7 +159,7 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke } } - private void reportProblem(IASTStatement curr, IASTStatement prevCase) { + private void reportProblem(IASTStatement curr) { reportProblem(ER_ID, getProblemLocationAtEndOfNode(curr)); } @@ -218,7 +218,7 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke super.initPreferences(problem); addPreference(problem, PARAM_NO_BREAK_COMMENT, CheckersMessages.CaseBreakChecker_DefaultNoBreakCommentDescription, DEFAULT_NO_BREAK_COMMENT); - addPreference(problem, PARAM_LAST_CASE, CheckersMessages.CaseBreakChecker_LastCaseDescription, Boolean.TRUE); + addPreference(problem, PARAM_LAST_CASE, CheckersMessages.CaseBreakChecker_LastCaseDescription, Boolean.FALSE); addPreference(problem, PARAM_EMPTY_CASE, CheckersMessages.CaseBreakChecker_EmptyCaseDescription, Boolean.FALSE); } From 336f3b170db2782c5bb8041c0ad519e750f147a7 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 2 Jan 2013 15:41:52 -0500 Subject: [PATCH 04/23] bug 396410: JUnit failure: cdt.build.core.scannerconfig.tests.CfgScannerConfigProfileManagerTests.testBasicCfgScannerConfigProfileChanges --- .../tests/CfgScannerConfigProfileManagerTests.java | 2 ++ .../internal/dataprovider/ConfigurationDataProvider.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/CfgScannerConfigProfileManagerTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/CfgScannerConfigProfileManagerTests.java index 8a86125fea8..2a45af47eb7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/CfgScannerConfigProfileManagerTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/build/core/scannerconfig/tests/CfgScannerConfigProfileManagerTests.java @@ -18,6 +18,7 @@ import junit.framework.TestSuite; import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; @@ -106,6 +107,7 @@ public class CfgScannerConfigProfileManagerTests extends BaseTestCase { Assert.isTrue("dummyFile".equals(scbi.getBuildOutputFilePath())); // Test restore defaults + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(fProject, false); scbis.applyInfo(cic, null); // Save the project description CoreModel.getDefault().setProjectDescription(fProject, prjDesc); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java index 2e198a9c3aa..5c10adc1efb 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java @@ -563,7 +563,7 @@ public class ConfigurationDataProvider extends CConfigurationDataProvider implem private static List getDefaultLanguageSettingsProviders(IConfiguration cfg) { List providers = new ArrayList(); - String[] ids = cfg.getDefaultLanguageSettingsProviderIds(); + String[] ids = cfg != null ? cfg.getDefaultLanguageSettingsProviderIds() : null; if (ids != null) { for (String id : ids) { ILanguageSettingsProvider provider = null; From 071096e343dbf6ad45b254f8ccbe7d363a48d9ad Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Thu, 3 Jan 2013 00:49:38 -0500 Subject: [PATCH 05/23] Bug 397121 - Add support for Windows SDK 8.0 and Visual C++ 11.0 --- .../build/WinEnvironmentVariableSupplier.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/WinEnvironmentVariableSupplier.java b/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/WinEnvironmentVariableSupplier.java index 5cbde63a03e..9c93579ab01 100644 --- a/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/WinEnvironmentVariableSupplier.java +++ b/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/WinEnvironmentVariableSupplier.java @@ -90,11 +90,15 @@ public class WinEnvironmentVariableSupplier return value; } - // Current support is for Windows SDK 7.1 with Visual C++ 10.0 - // Secondary support for Windows SDK 7.0 with Visual C++ 9.0 + // Current support is for Windows SDK 8.0 with Visual C++ 11.0 + // or Windows SDK 7.1 with Visual C++ 10.0 + // or Windows SDK 7.0 with Visual C++ 9.0 private static String getSDKDir() { WindowsRegistry reg = WindowsRegistry.getRegistry(); - String sdkDir = getSoftwareKey(reg, "Microsoft\\Microsoft SDKs\\Windows\\v7.1", "InstallationFolder"); + String sdkDir = getSoftwareKey(reg, "Microsoft\\Microsoft SDKs\\Windows\\v8.0", "InstallationFolder"); + if (sdkDir != null) + return sdkDir; + sdkDir = getSoftwareKey(reg, "Microsoft\\Microsoft SDKs\\Windows\\v7.1", "InstallationFolder"); if (sdkDir != null) return sdkDir; return getSoftwareKey(reg, "Microsoft SDKs\\Windows\\v7.0", "InstallationFolder"); @@ -102,7 +106,10 @@ public class WinEnvironmentVariableSupplier private static String getVCDir() { WindowsRegistry reg = WindowsRegistry.getRegistry(); - String vcDir = getSoftwareKey(reg, "Microsoft\\VisualStudio\\SxS\\VC7", "10.0"); + String vcDir = getSoftwareKey(reg, "Microsoft\\VisualStudio\\SxS\\VC7", "11.0"); + if (vcDir != null) + return vcDir; + vcDir = getSoftwareKey(reg, "Microsoft\\VisualStudio\\SxS\\VC7", "10.0"); if (vcDir != null) return vcDir; return getSoftwareKey(reg, "Microsoft\\VisualStudio\\SxS\\VC7", "9.0"); @@ -151,8 +158,10 @@ public class WinEnvironmentVariableSupplier buff = new StringBuffer(); if (vcDir != null) buff.append(vcDir).append("Lib;"); - if (sdkDir != null) + if (sdkDir != null) { buff.append(sdkDir).append("Lib;"); + buff.append(sdkDir).append("Lib\\win8\\um\\x86;"); + } addvar(new WindowsBuildEnvironmentVariable("LIB", buff.toString(), IBuildEnvironmentVariable.ENVVAR_PREPEND)); From 2993ef82667e507170ae6fb67e682991471799da Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Wed, 2 Jan 2013 00:06:16 -0500 Subject: [PATCH 06/23] Bug 397288 - typename keyword is not completed Change-Id: I26d62f771b5bb08d1c5cab64929c765c025053b3 Reviewed-on: https://git.eclipse.org/r/9419 Reviewed-by: Marc-Andre Laperle IP-Clean: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../dom/parser/cpp/GNUCPPSourceParser.java | 6 ++++-- .../AbstractContentAssistTest.java | 20 ++++++++++++------- .../text/contentassist2/CompletionTests.java | 8 +++++++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 50d5b8b6c1a..ccd86e57d21 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2012 IBM Corporation and others. + * Copyright (c) 2002, 2013 IBM Corporation 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 @@ -2057,7 +2057,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } List parms= outerTemplateParameterList(); - consume(IToken.tGT, IToken.tGT_in_SHIFTR); + if (LT(1) != IToken.tEOC) { + consume(IToken.tGT, IToken.tGT_in_SHIFTR); + } IASTDeclaration d = declaration(option); ICPPASTTemplateDeclaration templateDecl = nodeFactory.newTemplateDeclaration(d); setRange(templateDecl, offset, calculateEndOffset(d)); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java index e39e48b2b2a..26db8a43f23 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation 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 @@ -96,8 +96,8 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { fCFile= null; super.tearDown(); } - - protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, int compareType) throws Exception { + + protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, boolean filterResults, int compareType) throws Exception { if (CTestPlugin.getDefault().isDebugging()) { System.out.println("\n\n\n\n\nTesting "+this.getClass().getName()); } @@ -116,10 +116,12 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { long endTime= System.currentTimeMillis(); assertTrue(results != null); - if(isTemplate) { - results= filterResultsKeepTemplates(results); - } else { - results= filterResults(results, isCode); + if (filterResults) { + if (isTemplate) { + results= filterResultsKeepTemplates(results); + } else { + results= filterResults(results, isCode); + } } String[] resultStrings= toStringArray(results, compareType); Arrays.sort(expected); @@ -160,6 +162,10 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { } } + + protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, int compareType) throws Exception { + assertContentAssistResults(offset, length, expected, isCompletion, isTemplate, true, compareType); + } protected void assertContentAssistResults(int offset, String[] expected, boolean isCompletion, int compareType) throws Exception { assertContentAssistResults(offset, 0, expected, isCompletion, false, compareType); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java index da4abfe8443..2b251130613 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2013 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 @@ -1374,4 +1374,10 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "foo;" }; assertCompletionResults(fCursorOffset, expected, COMPARE_REP_STRINGS); } + + // template Date: Thu, 3 Jan 2013 14:46:50 -0500 Subject: [PATCH 07/23] Bug 397404 - Trying to export memory on a 64-bit address space does not bring up the dialog. --- .../traditional/TraditionalRendering.java | 6 ++- .../ui/memory/transport/SRecordExporter.java | 43 ++++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java index b9331ea9f69..df26c55c2bb 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java @@ -268,8 +268,10 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe * the model provider. */ fModel = factory.createModelProxy(block, context); - fModel.installed(null); - fModel.addModelChangedListener(TraditionalRendering.this); + if ( fModel != null ) { + fModel.installed(null); + fModel.addModelChangedListener(TraditionalRendering.this); + } }}); } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java index 225ccfc6825..f1e7807b101 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java @@ -72,9 +72,13 @@ public class SRecordExporter implements IMemoryExporter fProperties.put(TRANSFER_START, fStartText.getText()); fProperties.put(TRANSFER_END, fEndText.getText()); - fStartAddress = getStartAddress(); - fEndAddress = getEndAddress(); - fOutputFile = getFile(); + try + { + fStartAddress = getStartAddress(); + fEndAddress = getEndAddress(); + fOutputFile = getFile(); + } + catch(Exception e) {} super.dispose(); } @@ -157,11 +161,38 @@ public class SRecordExporter implements IMemoryExporter textValue = fProperties.get(TRANSFER_START); fStartText.setText(textValue != null ? textValue : "0x0"); //$NON-NLS-1$ + + try + { + getStartAddress(); + } + catch(Exception e) + { + fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); + } + textValue = fProperties.get(TRANSFER_END); fEndText.setText(textValue != null ? textValue : "0x0"); //$NON-NLS-1$ - - fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString()); + + try + { + getEndAddress(); + } + catch(Exception e) + { + fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); + } + + try + { + fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString()); + } + catch(Exception e) + { + fLengthText.setText("0"); + fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); + } fileButton.addSelectionListener(new SelectionListener() { @@ -234,7 +265,7 @@ public class SRecordExporter implements IMemoryExporter } catch(Exception ex) { - fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); + fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); validate(); //fParentDialog.setValid(false); } From 8ebad61314a7f8a9431705ceb0a5489693c2318f Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 4 Jan 2013 09:18:46 -0500 Subject: [PATCH 08/23] Typo --- .../src/org/eclipse/cdt/dsf/concurrent/Sequence.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/Sequence.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/Sequence.java index 8246f66fdb6..0bf62f923ff 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/Sequence.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/Sequence.java @@ -381,7 +381,7 @@ abstract public class Sequence extends DsfRunnable implements Future { } /* - * If sequence was cencelled during last step (or before the sequence + * If sequence was cancelled during last step (or before the sequence * was ever executed), start rolling back the execution. */ if (isCancelled()) { From fdbafed3f38f35f6dae02f74ddc7036f3507bec1 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 4 Jan 2013 11:52:44 -0500 Subject: [PATCH 09/23] Bug 397460 - [breakpoints] Duplicate GDB breakpoints do not get associated to the platform bp properly Change-Id: Ieaaed2e5a70f381a6da241b1bdf460e1ffcaf624 Reviewed-on: https://git.eclipse.org/r/9460 Reviewed-by: Mikhail Khodjaiants IP-Clean: Mikhail Khodjaiants Tested-by: Mikhail Khodjaiants Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../cdt/dsf/mi/service/MIBreakpointsManager.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsManager.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsManager.java index 629014d30a6..e371a7eedbc 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsManager.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsManager.java @@ -549,7 +549,8 @@ public class MIBreakpointsManager extends AbstractDsfService implements IBreakpo /** * Install a platform breakpoint on the back-end. For a given context, a * platform breakpoint can resolve into multiple back-end breakpoints when - * threads are taken into account. + * threads are taken into account or if multiple breakpoints are created + * on the target using the console. * * @param dmc * @param breakpoint @@ -572,13 +573,6 @@ public class MIBreakpointsManager extends AbstractDsfService implements IBreakpo final Map> threadsIDs = fBreakpointThreads.get(dmc); assert threadsIDs != null; - // Minimal validation - if (breakpointIDs.containsKey(breakpoint) || targetBPs.containsValue(breakpoint)) { - rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, BREAKPOINT_ALREADY_INSTALLED, null)); - rm.done(); - return; - } - // Ensure the breakpoint has a valid debugger source path if (breakpoint instanceof ICLineBreakpoint && !(breakpoint instanceof ICAddressBreakpoint) From e2a18cf6c2012d674276d18817069cd77997eb89 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 4 Jan 2013 19:22:22 -0800 Subject: [PATCH 10/23] Bug 397496 - Formatter does not wrap long macro arguments --- .../core/parser/scanner/MacroExpander.java | 26 +- .../formatter/CodeFormatterVisitor.java | 285 ++++++++++-------- .../cdt/ui/tests/text/CodeFormatterTest.java | 30 +- 3 files changed, 208 insertions(+), 133 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java index ae1c0cc4983..17d53908aa8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java @@ -418,6 +418,14 @@ public class MacroExpander { return result; } + private void addImageLocationInfo(int offset, Token t) { + ImageLocationInfo info= createImageLocationInfo(t); + if (info != null) { + info.fTokenOffsetInExpansion= offset; + fImageLocationInfos.add(info); + } + } + private ImageLocationInfo createImageLocationInfo(Token t) { if (fLocationMap != null) { final Object s= t.fSource; @@ -950,20 +958,12 @@ public class MacroExpander { case CPreprocessor.tEXPANDED_IDENTIFIER: t.setType(IToken.tIDENTIFIER); if (createImageLocations) { - ImageLocationInfo info= createImageLocationInfo(t); - if (info != null) { - info.fTokenOffsetInExpansion= offset; - fImageLocationInfos.add(info); - } + addImageLocationInfo(offset, t); } break; case IToken.tIDENTIFIER: if (createImageLocations) { - ImageLocationInfo info= createImageLocationInfo(t); - if (info != null) { - info.fTokenOffsetInExpansion= offset; - fImageLocationInfos.add(info); - } + addImageLocationInfo(offset, t); } break; @@ -978,6 +978,12 @@ public class MacroExpander { t.setOffset(offset, offset + t.getLength()); t.setNext(null); return; + + default: + if (createImageLocations && t.fSource instanceof CPreprocessor) { + addImageLocationInfo(offset, t); + } + break; } t.setOffset(offset, ++offset); l= t; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 3a9d9d64d8e..19ba1afcff7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -66,6 +66,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; +import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTNullStatement; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; @@ -143,6 +144,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.cdt.core.formatter.DefaultCodeFormatterOptions; import org.eclipse.cdt.core.parser.IToken; +import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.formatter.align.Alignment; import org.eclipse.cdt.internal.formatter.align.AlignmentException; @@ -232,6 +234,28 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } } + private static class TokenRange { + private int offset; + private int endOffset; + + TokenRange(int offset, int endOffset) { + this.offset = offset; + this.endOffset = endOffset; + } + + int getOffset() { + return offset; + } + + int getEndOffset() { + return endOffset; + } + + int getLength() { + return endOffset - offset; + } + } + /** * Formats a trailing semicolon. * @see #formatList(List, ListOptions, boolean, boolean, Runnable) @@ -360,6 +384,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, private final Scribe scribe; private boolean fInsideFor; + private boolean fInsideMacroArguments; private boolean fExpectSemicolonAfterDeclaration= true; private MultiStatus fStatus; @@ -540,97 +565,79 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (fileLocation != null) { scribe.printRaw(fileLocation.getNodeOffset(), fileLocation.getNodeLength()); } - fileLocation = macroExpansion.getFileLocation(); - scribe.printNextToken(Token.tLPAREN); IMacroBinding binding = (IMacroBinding) name.resolveBinding(); - if (preferences.insert_space_after_opening_paren_in_method_invocation) { - scribe.space(); + List arguments = getMacroArguments(binding.getParameterList().length); + + final ListOptions options= new ListOptions(preferences.alignment_for_arguments_in_method_invocation); + options.fSeparatorToken = Token.tCOMMA; + options.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_invocation; + options.fSpaceBeforeClosingParen= preferences.insert_space_before_closing_paren_in_method_invocation; + options.fSpaceBetweenEmptyParen= preferences.insert_space_between_empty_parens_in_method_invocation; + options.fSpaceBeforeSeparator= preferences.insert_space_before_comma_in_method_invocation_arguments; + options.fSpaceAfterSeparator= preferences.insert_space_after_comma_in_method_invocation_arguments; + options.fTieBreakRule = Alignment.R_OUTERMOST; + fInsideMacroArguments = true; + try { + formatList(arguments, options, true, false, scribe.takeTailFormatter()); + } finally { + fInsideMacroArguments = false; } - final int continuationIndentation = preferences.continuation_indentation; - Alignment listAlignment = scribe.createAlignment( - Alignment.MACRO_ARGUMENTS, - preferences.alignment_for_arguments_in_method_invocation, - Alignment.R_OUTERMOST, - binding.getParameterList().length, - getCurrentPosition(), - continuationIndentation, - false); - scribe.enterAlignment(listAlignment); - boolean ok = false; - do { - try { - int fragment = 0; - scribe.alignFragment(listAlignment, fragment); - int parenLevel= 0; - boolean done = false; - while (!done) { - boolean hasWhitespace= scribe.printComment(); - int token = peekNextToken(); - switch (token) { - case Token.tLPAREN: - ++parenLevel; - scribe.printNextToken(token, hasWhitespace); - break; - case Token.tRPAREN: - if (parenLevel > 0) { - --parenLevel; - scribe.printNextToken(token, hasWhitespace); - } else { - if (preferences.insert_space_before_closing_paren_in_method_invocation) { - scribe.space(); - } - scribe.printNextToken(token); - done = true; - } - break; - case Token.tCOMMA: - if (parenLevel == 0 && preferences.insert_space_before_comma_in_method_invocation_arguments) { - scribe.space(); - } - scribe.printNextToken(token); - if (parenLevel == 0) { - if (preferences.insert_space_after_comma_in_method_invocation_arguments) { - scribe.space(); - } - scribe.printComment(); - ++fragment; - if (fragment < listAlignment.fragmentCount) { - scribe.alignFragment(listAlignment, fragment); - } - } - break; - case Token.tSTRING: - case Token.tLSTRING: - case Token.tRSTRING: - boolean needSpace= hasWhitespace; - while (true) { - scribe.printNextToken(token, needSpace); - if (peekNextToken() != token) { - break; - } - scribe.printCommentPreservingNewLines(); - needSpace= true; - } - break; - case Token.tBADCHAR: - // Avoid infinite loop if something bad happened. - scribe.exitAlignment(listAlignment, true); - return; - default: - scribe.printNextToken(token, hasWhitespace); - } + } + + /** + * Scans macro expansion arguments starting from the current position and returns a list of + * arguments where each argument is represented either by a {@link IASTNode} or, if not + * possible, by a {@link TokenRange}. + */ + private List getMacroArguments(int expectedNumberOfArguments) { + List argumentRanges = new ArrayList(expectedNumberOfArguments); + TokenRange currentArgument = null; + localScanner.resetTo(getCurrentPosition(), scribe.scannerEndPosition); + localScanner.getNextToken(); // Skip the opening parenthesis. + int parenLevel = 0; + int token; + while ((token = localScanner.getNextToken()) != Token.tBADCHAR) { + int tokenOffset = localScanner.getCurrentTokenStartPosition(); + if (parenLevel == 0 && (token == Token.tCOMMA || token == Token.tRPAREN)) { + if (currentArgument != null) { + argumentRanges.add(currentArgument); + currentArgument = null; + } else { + argumentRanges.add(new TokenRange(tokenOffset, tokenOffset)); } - int token = peekNextToken(); - if (token == Token.tSEMI) { - scribe.printNextToken(token); - scribe.startNewLine(); + if (token == Token.tRPAREN) + break; + } else { + int tokenEndOffset = localScanner.getCurrentPosition(); + if (currentArgument == null) { + currentArgument = new TokenRange(tokenOffset, tokenEndOffset); + } else { + currentArgument.endOffset = tokenEndOffset; + } + + switch (token) { + case Token.tLPAREN: + ++parenLevel; + break; + case Token.tRPAREN: + if (parenLevel > 0) + --parenLevel; + break; } - ok = true; - } catch (AlignmentException e) { - scribe.redoAlignment(e); } - } while (!ok); - scribe.exitAlignment(listAlignment, true); + } + + List arguments = new ArrayList(argumentRanges.size()); + IASTNodeSelector nodeSelector = ast.getNodeSelector(null); + for (TokenRange argument : argumentRanges) { + IASTNode node = nodeSelector.findNodeInExpansion(argument.getOffset(), argument.getLength()); + if (node != null) { + arguments.add(node); + } else { + arguments.add(argument); + } + } + return arguments; } @Override @@ -2077,15 +2084,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, /** * Format a given list of elements according alignment options. * - * @param elements the elements to format + * @param elements the elements to format, which can be either {@link IASTNode}s or + * {@link TokenRange}s. * @param options formatting options * @param encloseInParen indicates whether the list should be enclosed in parentheses * @param addEllipsis indicates whether ellipsis should be added after the last element * @param tailFormatter formatter for the trailing text that should be kept together with * the last element of the list. */ - private void formatList(List elements, ListOptions options, - boolean encloseInParen, boolean addEllipsis, Runnable tailFormatter) { + private void formatList(List elements, ListOptions options, boolean encloseInParen, + boolean addEllipsis, Runnable tailFormatter) { if (encloseInParen) scribe.printNextToken(Token.tLPAREN, options.fSpaceBeforeOpeningParen); @@ -2118,22 +2126,26 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, try { int i; for (i = 0; i < elementsLength; i++) { - final IASTNode node= elements.get(i); + final Object element = elements.get(i); if (i < elementsLength - 1) { scribe.setTailFormatter( new TrailingTokenFormatter(options.fSeparatorToken, - findTokenAfterNode(options.fSeparatorToken, node), + findTokenAfterNodeOrTokenRange(options.fSeparatorToken, element), options.fSpaceBeforeSeparator, options.fSpaceAfterSeparator)); } else { scribe.setTailFormatter(tailFormatter); } scribe.alignFragment(alignment, i); - if (node instanceof ICPPASTConstructorChainInitializer) { - // Constructor chain initializer is a special case. - visit((ICPPASTConstructorChainInitializer) node); + if (element instanceof IASTNode) { + if (element instanceof ICPPASTConstructorChainInitializer) { + // Constructor chain initializer is a special case. + visit((ICPPASTConstructorChainInitializer) element); + } else { + ((IASTNode) element).accept(this); + } } else { - node.accept(this); + formatTokenRange((TokenRange) element); } if (i < elementsLength - 1) { scribe.runTailFormatter(); @@ -2163,6 +2175,15 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } } + private void formatTokenRange(TokenRange tokenRange) { + scribe.restartAtOffset(tokenRange.getOffset()); + while (getCurrentPosition() < tokenRange.getEndOffset()) { + boolean hasWhitespace= scribe.printComment(); + int token = peekNextToken(); + scribe.printNextToken(token, hasWhitespace); + } + } + private int visit(ICPPASTTryBlockStatement node) { scribe.printNextToken(Token.t_try, scribe.printComment()); final IASTStatement tryBody= node.getTryBody(); @@ -3782,18 +3803,23 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } IASTNodeLocation[] locations= node.getNodeLocations(); if (locations.length == 0) { - } else if (locations[0] instanceof IASTMacroExpansionLocation) { + } else if (!fInsideMacroArguments && locations[0] instanceof IASTMacroExpansionLocation) { IASTMacroExpansionLocation location = (IASTMacroExpansionLocation) locations[0]; if (locations.length <= 2 && node instanceof IASTStatement) { IASTPreprocessorMacroExpansion macroExpansion = location.getExpansion(); IASTFileLocation macroLocation = macroExpansion.getFileLocation(); - IASTFileLocation nodeLocation = node.getFileLocation(); + IASTFileLocation nodeLocation = getFileLocation(node); if (macroLocation.getNodeOffset() >= getCurrentPosition() && !scribe.shouldSkip(macroLocation.getNodeOffset()) && (nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() == macroLocation.getNodeOffset() + macroLocation.getNodeLength() || locations.length == 2 && isSemicolonLocation(locations[1])) && isFunctionStyleMacroExpansion(macroExpansion)) { + if (locations.length == 2 && isSemicolonLocation(locations[1])) { + scribe.setTailFormatter( + new TrailingTokenFormatter(Token.tSEMI, locations[1].getNodeOffset(), + preferences.insert_space_before_semicolon, false)); + } formatFunctionStyleMacroExpansion(macroExpansion); return false; } @@ -3808,12 +3834,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, return false; } } else { - IASTFileLocation fileLocation= node.getFileLocation(); + IASTFileLocation fileLocation= getFileLocation(node); scribe.restartAtOffset(fileLocation.getNodeOffset()); } return true; } + private IASTFileLocation getFileLocation(IASTNode node) { + return fInsideMacroArguments ? ((ASTNode) node).getImageLocation() : node.getFileLocation(); + } + /** * Formatting of node is complete. Undo skip region if any. * @@ -3824,7 +3854,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, return; } if (scribe.skipRange()) { - IASTFileLocation fileLocation= node.getFileLocation(); + IASTFileLocation fileLocation= getFileLocation(node); if (fileLocation != null) { int nodeEndOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength(); scribe.restartAtOffset(nodeEndOffset); @@ -3845,7 +3875,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (node instanceof IASTProblemHolder || node instanceof IASTTranslationUnit) { return; } - IASTFileLocation fileLocation= node.getFileLocation(); + IASTFileLocation fileLocation= getFileLocation(node); if (fileLocation == null) { return; } @@ -3881,7 +3911,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private void skipNode(IASTNode node) { - final IASTNodeLocation fileLocation= node.getFileLocation(); + final IASTNodeLocation fileLocation= getFileLocation(node); if (fileLocation != null && fileLocation.getNodeLength() > 0) { final int endOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength(); final int currentOffset= getCurrentPosition(); @@ -3893,7 +3923,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private void skipToNode(IASTNode node) { - final IASTNodeLocation fileLocation= node.getFileLocation(); + final IASTNodeLocation fileLocation= getFileLocation(node); if (fileLocation != null) { final int startOffset= fileLocation.getNodeOffset(); final int currentOffset= getCurrentPosition(); @@ -3905,7 +3935,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private void skipNonWhitespaceToNode(IASTNode node) { - final IASTNodeLocation fileLocation= node.getFileLocation(); + final IASTNodeLocation fileLocation= getFileLocation(node); if (fileLocation != null) { final int startOffset= fileLocation.getNodeOffset(); final int nextTokenOffset= getNextTokenOffset(); @@ -3985,18 +4015,22 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } } - private static boolean startsWithMacroExpansion(IASTNode node) { + private boolean startsWithMacroExpansion(IASTNode node) { + if (fInsideMacroArguments) + return false; IASTNodeLocation[] locations= node.getNodeLocations(); if (!(node instanceof IASTProblemHolder) && locations.length != 0 && locations[0] instanceof IASTMacroExpansionLocation) { IASTFileLocation expansionLocation= locations[0].asFileLocation(); - IASTFileLocation fileLocation= node.getFileLocation(); + IASTFileLocation fileLocation= getFileLocation(node); return expansionLocation.getNodeOffset() == fileLocation.getNodeOffset(); } return false; } - private static boolean endsWithMacroExpansion(IASTNode node) { + private boolean endsWithMacroExpansion(IASTNode node) { + if (fInsideMacroArguments) + return false; IASTNodeLocation[] locations= node.getNodeLocations(); if (!(node instanceof IASTProblemHolder) && locations.length != 0 && locations[locations.length - 1] instanceof IASTMacroExpansionLocation) { @@ -4005,13 +4039,17 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, return false; } - private static boolean enclosedInMacroExpansion(IASTNode node) { + private boolean enclosedInMacroExpansion(IASTNode node) { + if (fInsideMacroArguments) + return false; IASTNodeLocation[] locations= node.getNodeLocations(); return locations.length == 1 && locations[0] instanceof IASTMacroExpansionLocation; } - private static boolean withinMacroExpansion(IASTNode node, int offset) { - IASTFileLocation loc = node.getFileLocation(); + private boolean withinMacroExpansion(IASTNode node, int offset) { + if (fInsideMacroArguments) + return false; + IASTFileLocation loc = getFileLocation(node); if (loc == null || offset < loc.getNodeOffset() || offset >= loc.getNodeOffset() + loc.getNodeLength()) { return false; } @@ -4061,9 +4099,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, * normally separated by other tokens this is an indication that they were produced by the same * macro expansion. */ - private static boolean doNodeLocationsOverlap(IASTNode node1, IASTNode node2) { - IASTFileLocation loc1 = node1.getFileLocation(); - IASTFileLocation loc2 = node2.getFileLocation(); + private boolean doNodeLocationsOverlap(IASTNode node1, IASTNode node2) { + IASTFileLocation loc1 = getFileLocation(node1); + IASTFileLocation loc2 = getFileLocation(node2); return loc1.getNodeOffset() + loc1.getNodeLength() > loc2.getNodeOffset() && loc1.getNodeOffset() < loc2.getNodeOffset() + loc2.getNodeLength(); } @@ -4073,16 +4111,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, * separated by other tokens this is an indication that they were produced by the same macro * expansion. */ - private static boolean doNodesHaveSameOffset(IASTNode node1, IASTNode node2) { + private boolean doNodesHaveSameOffset(IASTNode node1, IASTNode node2) { return nodeOffset(node1) == nodeOffset(node2); } - private static int nodeOffset(IASTNode node) { - return node.getFileLocation().getNodeOffset(); + private int nodeOffset(IASTNode node) { + return getFileLocation(node).getNodeOffset(); } - private static int nodeEndOffset(IASTNode node) { - IASTFileLocation loc = node.getFileLocation(); + private int nodeEndOffset(IASTNode node) { + IASTFileLocation loc = getFileLocation(node); return loc.getNodeOffset() + loc.getNodeLength(); } @@ -4407,14 +4445,19 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int findTokenWithinNode(int tokenType, IASTNode node) { - IASTFileLocation location = node.getFileLocation(); + IASTFileLocation location = getFileLocation(node); int endOffset = location.getNodeOffset() + location.getNodeLength(); return scribe.findToken(tokenType, endOffset); } - private int findTokenAfterNode(int tokenType, IASTNode node) { - IASTFileLocation location = node.getFileLocation(); - int startOffset = location.getNodeOffset() + location.getNodeLength(); + private int findTokenAfterNodeOrTokenRange(int tokenType, Object nodeOrTokenRange) { + int startOffset; + if (nodeOrTokenRange instanceof IASTNode) { + IASTFileLocation location = getFileLocation((IASTNode) nodeOrTokenRange); + startOffset = location.getNodeOffset() + location.getNodeLength(); + } else { + startOffset = ((TokenRange) nodeOrTokenRange).getEndOffset(); + } return scribe.findToken(tokenType, startOffset, scribe.scannerEndPosition - 1); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index f2ef0f47940..f1032773097 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -1765,7 +1765,6 @@ public class CodeFormatterTest extends BaseUITestCase { // } //#endif //} - public void testMacroAsFunctionArguments_Bug253039() throws Exception { assertFormatterResult(); } @@ -1901,6 +1900,33 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define MACRO(a,b) f(a,b) + //void f(bool b, int i); + //int function_with_loooooooooooooooong_name(); + //int another_function_with_loooooong_name(); + // + //void test(){ + // MACRO("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"=="bbbbbbbbbbbbbbbbbbbbbbbbbbb",function_with_loooooooooooooooong_name()+another_function_with_loooooong_name()); + //} + + //#define MACRO(a,b) f(a,b) + //void f(bool b, int i); + //int function_with_loooooooooooooooong_name(); + //int another_function_with_loooooong_name(); + // + //void test() { + // MACRO("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + // == "bbbbbbbbbbbbbbbbbbbbbbbbbbb", + // function_with_loooooooooooooooong_name() + // + another_function_with_loooooong_name()); + //} + public void testMacroArguments() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, + Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN)); + assertFormatterResult(); + } + //bool member __attribute__ ((__unused__)) = false; //bool member __attribute__ ((__unused__)) = false; @@ -2892,7 +2918,7 @@ public class CodeFormatterTest extends BaseUITestCase { //void f() { // if (1) { // } - // IF(1>0); + // IF(1 > 0); //} public void testMacroAfterCompoundStatement_Bug356690() throws Exception { assertFormatterResult(); From 7f79e5da86fdf216796ea1f5a95c2e557a67eda8 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Sat, 5 Jan 2013 11:46:13 -0500 Subject: [PATCH 11/23] Bug 397469 - Fix problem with scanner discovery on relative source paths. --- .../core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java index 1ff5e0f1e53..af58dd60d6a 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java @@ -221,7 +221,7 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser // appending fileName to cwd should yield file path filePath = cwd.append(fileName); } - if (!filePath.toString().equalsIgnoreCase(EFSExtensionManager.getDefault().getPathFromURI(file.getLocationURI()))) { + if (!filePath.toOSString().equalsIgnoreCase(EFSExtensionManager.getDefault().getPathFromURI(file.getLocationURI()))) { // must be the cwd is wrong // check if file name starts with ".." if (fileName.startsWith("..")) { //$NON-NLS-1$ From e4943b330ad9ea8c1e5d4df58ae4095de8a5a2de Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 5 Jan 2013 12:23:02 -0800 Subject: [PATCH 12/23] Fixed broken test. --- .../ui/quickfix/CaseBreakQuickFixTest.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java index d8b20403f49..4982bb2207a 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java @@ -29,34 +29,22 @@ public class CaseBreakQuickFixTest extends QuickFixTestCase { // break; // } //} - public void testMiddleCase() throws Exception { + public void testSimpleCase() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("break;\tcase 2:", result); } - //void func() { - // int a; - // switch(a) { - // case 1: - // hello(); - // } - //} - public void testLastCase() throws Exception { - loadcode(getAboveComment()); - String result = runQuickFixOneFile(); - assertContainedIn("break;\t}", result); - } - //void func() { // int a; // switch(a) { // case 1: { // hello(); // } + // default: // } //} - public void testLastCaseComp() throws Exception { + public void testCompositeStatementCase() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("hello();\t\tbreak;", result); From e679870821fb9d4f1291d5f15fc3d382c0f71738 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 6 Jan 2013 07:37:51 -0500 Subject: [PATCH 13/23] Bug 397469 - Fix problem with scanner discovery on relative source paths. --- .../scannerconfig/gnu/ScannerInfoConsoleParserUtility.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java index af58dd60d6a..29694f9b1e7 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java @@ -221,7 +221,8 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser // appending fileName to cwd should yield file path filePath = cwd.append(fileName); } - if (!filePath.toOSString().equalsIgnoreCase(EFSExtensionManager.getDefault().getPathFromURI(file.getLocationURI()))) { + IPath fileLocation = new Path(EFSExtensionManager.getDefault().getPathFromURI(file.getLocationURI())); + if (!filePath.toString().equalsIgnoreCase(fileLocation.toString())) { // must be the cwd is wrong // check if file name starts with ".." if (fileName.startsWith("..")) { //$NON-NLS-1$ @@ -238,7 +239,7 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser tPath = tPath.removeFirstSegments(1); } // get the file path from the file - filePath = new Path(EFSExtensionManager.getDefault().getPathFromURI(file.getLocationURI())); + filePath = fileLocation; IPath lastFileSegment = filePath.removeFirstSegments(filePath.segmentCount() - tPath.segmentCount()); if (lastFileSegment.matchingFirstSegments(tPath) == tPath.segmentCount()) { cwd = filePath.removeLastSegments(tPath.segmentCount()); From 3602ab4d96004988f5d685cdb4b2fb4f02f88d5e Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 6 Jan 2013 21:26:24 -0800 Subject: [PATCH 14/23] Bug 397496. A missing piece of the previous fix. --- .../formatter/CodeFormatterVisitor.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 19ba1afcff7..c4da1712865 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -3885,20 +3885,22 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (currentOffset > nodeEndOffset) { return; } - IASTNodeLocation[] locations= node.getNodeLocations(); - for (int i= 0; i < locations.length; i++) { - IASTNodeLocation nodeLocation= locations[i]; - if (nodeLocation instanceof IASTMacroExpansionLocation) { - IASTFileLocation expansionLocation= nodeLocation.asFileLocation(); - int startOffset= expansionLocation.getNodeOffset(); - int endOffset= startOffset + expansionLocation.getNodeLength(); - if (currentOffset <= startOffset) { - break; - } - if (currentOffset < endOffset || - currentOffset == endOffset && i == locations.length - 1) { - scribe.skipRange(startOffset, endOffset); - break; + if (!fInsideMacroArguments) { + IASTNodeLocation[] locations= node.getNodeLocations(); + for (int i= 0; i < locations.length; i++) { + IASTNodeLocation nodeLocation= locations[i]; + if (nodeLocation instanceof IASTMacroExpansionLocation) { + IASTFileLocation expansionLocation= nodeLocation.asFileLocation(); + int startOffset= expansionLocation.getNodeOffset(); + int endOffset= startOffset + expansionLocation.getNodeLength(); + if (currentOffset <= startOffset) { + break; + } + if (currentOffset < endOffset || + currentOffset == endOffset && i == locations.length - 1) { + scribe.skipRange(startOffset, endOffset); + break; + } } } } From ce1fa180df02eef40b842be7e09484f31789c143 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 7 Jan 2013 14:53:00 +0100 Subject: [PATCH 15/23] Bug 397127: Limit raw-string detection to c++ parser. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 5 +++ .../core/parser/tests/scanner/LexerTests.java | 30 +++++++++--------- ...AbstractScannerExtensionConfiguration.java | 12 +++++-- .../IScannerExtensionConfiguration.java | 6 ++++ .../cpp/GPPScannerExtensionConfiguration.java | 8 +++++ .../core/parser/scanner/CPreprocessor.java | 1 + .../internal/core/parser/scanner/Lexer.java | 31 +++++++++++-------- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 23061d5fdf7..0a8e2de6c42 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -7420,4 +7420,9 @@ public class AST2Tests extends AST2BaseTest { public void testGCCDecltype_397227() throws Exception { parseAndCheckBindings(getAboveComment(), CPP, true); } + + // #define macro(R) #R"" + public void testNoRawStringInPlainC_397127() throws Exception { + parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java index aba5c29b8ff..23bdc2bd11a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java @@ -27,10 +27,12 @@ public class LexerTests extends BaseTestCase { private static final LexerOptions NO_DOLLAR = new LexerOptions(); private static final LexerOptions NO_MINMAX = new LexerOptions(); private static final LexerOptions SLASH_PERCENT = new LexerOptions(); + private static final LexerOptions CPP_OPTIONS = new LexerOptions(); static { NO_DOLLAR.fSupportDollarInIdentifiers= false; NO_MINMAX.fSupportMinAndMax= false; SLASH_PERCENT.fSupportSlashPercentComments= true; + CPP_OPTIONS.fSupportRawStringLiterals= true; } static String TRIGRAPH_REPLACES_CHARS= "#^[]|{}~\\"; @@ -41,7 +43,7 @@ public class LexerTests extends BaseTestCase { } private Lexer fLexer; - private TestLexerLog fLog= new TestLexerLog(); + private final TestLexerLog fLog= new TestLexerLog(); private int fLastEndOffset; public LexerTests() { @@ -576,51 +578,51 @@ public class LexerTests extends BaseTestCase { public void testRawStringLiteral() throws Exception { String lit= "abc0123\\\"'.:; \\\\ \n\"("; - init("R\"(" + lit + ")\""); + init("R\"(" + lit + ")\"", CPP_OPTIONS); rstr("", lit); eof(); - init("LR\"(" + lit + ")\""); + init("LR\"(" + lit + ")\"", CPP_OPTIONS); wrstr("", lit); eof(); - init("u8R\"(" + lit + ")\""); + init("u8R\"(" + lit + ")\"", CPP_OPTIONS); utf8rstr("", lit); eof(); - init("uR\"(" + lit + ")\""); + init("uR\"(" + lit + ")\"", CPP_OPTIONS); utf16rstr("", lit); eof(); - init("UR\"(" + lit + ")\""); + init("UR\"(" + lit + ")\"", CPP_OPTIONS); utf32rstr("", lit); eof(); - init("R\"ut"); + init("R\"ut", CPP_OPTIONS); problem(IProblem.SCANNER_UNBOUNDED_STRING, "R\"ut"); token(IToken.tSTRING, "R\"ut"); eof(); - init("LR\"(ut"); + init("LR\"(ut", CPP_OPTIONS); problem(IProblem.SCANNER_UNBOUNDED_STRING, "LR\"(ut"); token(IToken.tLSTRING, "LR\"(ut"); eof(); - init("uR\"p()"); + init("uR\"p()", CPP_OPTIONS); problem(IProblem.SCANNER_UNBOUNDED_STRING, "uR\"p()"); token(IToken.tUTF16STRING, "uR\"p()"); eof(); - init("UR\"(ut"); + init("UR\"(ut", CPP_OPTIONS); problem(IProblem.SCANNER_UNBOUNDED_STRING, "UR\"(ut"); token(IToken.tUTF32STRING, "UR\"(ut"); eof(); - init("R\"+=(Text)=+\"Text)+=\""); + init("R\"+=(Text)=+\"Text)+=\"", CPP_OPTIONS); rstr("+=", "Text)=+\"Text"); eof(); - init("UR uR LR u8R U8R\"\""); + init("UR uR LR u8R U8R\"\"", CPP_OPTIONS); id("UR"); ws(); id("uR"); ws(); id("LR"); ws(); @@ -630,7 +632,7 @@ public class LexerTests extends BaseTestCase { } public void testRawStringLiteralInInactiveCode() throws Exception { - init("start\n" + "inactive: Rbla\n" + "#end"); + init("start\n" + "inactive: Rbla\n" + "#end", CPP_OPTIONS); id("start"); nextDirective(); token(IToken.tPOUND); @@ -638,7 +640,7 @@ public class LexerTests extends BaseTestCase { eof(); // raw string containing a directive - init("start\n" + "inactive: uR\"(\n#endif\n)\"\n" + "#end"); + init("start\n" + "inactive: uR\"(\n#endif\n)\"\n" + "#end", CPP_OPTIONS); id("start"); nextDirective(); token(IToken.tPOUND); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java index e9ec9210087..7cd17177aeb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java @@ -29,8 +29,8 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE private CharArrayIntMap fAddPreprocessorKeywords; protected static class MacroDefinition implements IMacro { - private char[] fSignature; - private char[] fExpansion; + private final char[] fSignature; + private final char[] fExpansion; MacroDefinition(char[] signature, char[] expansion) { fSignature= signature; @@ -103,6 +103,14 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE return false; } + /** + * @since 5.5 + */ + @Override + public boolean supportRawStringLiterals() { + return false; + } + @Override public CharArrayIntMap getAdditionalPreprocessorKeywords() { return fAddPreprocessorKeywords; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java index c4a2aa58afb..839dbbbd123 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java @@ -109,4 +109,10 @@ public interface IScannerExtensionConfiguration { * @see "http://publib.boulder.ibm.com/infocenter/comphelp/v101v121/index.jsp?topic=/com.ibm.xlcpp101.aix.doc/language_ref/unicode_standard.html" */ public boolean supportUTFLiterals(); + + /** + * Support for C++ raw string literals. + * @since 5.5 + */ + public boolean supportRawStringLiterals(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java index ffd4111d06a..476a245dc5e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java @@ -113,4 +113,12 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu public boolean supportMinAndMaxOperators() { return true; } + + /** + * @since 5.5 + */ + @Override + public boolean supportRawStringLiterals() { + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index ad0bcd7b0aa..66382144eba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -290,6 +290,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { fLexOptions.fSupportMinAndMax = configuration.supportMinAndMaxOperators(); fLexOptions.fSupportSlashPercentComments= configuration.supportSlashPercentComments(); fLexOptions.fSupportUTFLiterals = configuration.supportUTFLiterals(); + fLexOptions.fSupportRawStringLiterals = configuration.supportRawStringLiterals(); fLocationMap= new LocationMap(fLexOptions); fKeywords= new CharArrayIntMap(40, -1); fPPKeywords= new CharArrayIntMap(40, -1); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java index 6b925714106..439e2a910fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java @@ -54,6 +54,7 @@ final public class Lexer implements ITokenSequence { public boolean fCreateImageLocations= true; public boolean fSupportSlashPercentComments= false; public boolean fSupportUTFLiterals= true; + public boolean fSupportRawStringLiterals= false; @Override public Object clone() { @@ -73,7 +74,7 @@ final public class Lexer implements ITokenSequence { // the input to the lexer private final AbstractCharArray fInput; - private int fStart; + private final int fStart; private int fLimit; // after phase 3 (newline, trigraph, line-splice) @@ -267,12 +268,14 @@ final public class Lexer implements ITokenSequence { case 'L': switch(d) { case 'R': - markPhase3(); - if (nextCharPhase3() == '"') { - nextCharPhase3(); - return rawStringLiteral(start, 3, IToken.tLSTRING); + if (fOptions.fSupportRawStringLiterals) { + markPhase3(); + if (nextCharPhase3() == '"') { + nextCharPhase3(); + return rawStringLiteral(start, 3, IToken.tLSTRING); + } + restorePhase3(); } - restorePhase3(); break; case '"': nextCharPhase3(); @@ -288,12 +291,14 @@ final public class Lexer implements ITokenSequence { if (fOptions.fSupportUTFLiterals) { switch(d) { case 'R': - markPhase3(); - if (nextCharPhase3() == '"') { - nextCharPhase3(); - return rawStringLiteral(start, 3, c == 'u' ? IToken.tUTF16STRING : IToken.tUTF32STRING); + if (fOptions.fSupportRawStringLiterals) { + markPhase3(); + if (nextCharPhase3() == '"') { + nextCharPhase3(); + return rawStringLiteral(start, 3, c == 'u' ? IToken.tUTF16STRING : IToken.tUTF32STRING); + } + restorePhase3(); } - restorePhase3(); break; case '"': nextCharPhase3(); @@ -306,7 +311,7 @@ final public class Lexer implements ITokenSequence { markPhase3(); switch (nextCharPhase3()) { case 'R': - if (nextCharPhase3() == '"') { + if (fOptions.fSupportRawStringLiterals && nextCharPhase3() == '"') { nextCharPhase3(); return rawStringLiteral(start, 4, IToken.tSTRING); } @@ -323,7 +328,7 @@ final public class Lexer implements ITokenSequence { return identifier(start, 1); case 'R': - if (d == '"') { + if (fOptions.fSupportRawStringLiterals && d == '"') { nextCharPhase3(); return rawStringLiteral(start, 2, IToken.tSTRING); } From 5ee1a4a1743176403be8dc34a8dbf57566f2b902 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Mon, 7 Jan 2013 11:05:17 -0500 Subject: [PATCH 16/23] Bug 396081 - Duplicate target breakpoints created when setting a GDB console breakpoint with relative path. Change-Id: I622d78dbe8231abade54c94d0190d8fb3b1dcdb9 Reviewed-on: https://git.eclipse.org/r/9114 Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam Reviewed-by: Mikhail Khodjaiants IP-Clean: Mikhail Khodjaiants Tested-by: Mikhail Khodjaiants --- .../dsf/gdb/service/GDBBreakpoints_7_4.java | 142 ++++++++++----- .../mi/service/MIBreakpointsSynchronizer.java | 168 ++++++++++++++---- 2 files changed, 232 insertions(+), 78 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBreakpoints_7_4.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBreakpoints_7_4.java index c58005eb554..4b871a9a251 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBreakpoints_7_4.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBreakpoints_7_4.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.dsf.gdb.service; import java.util.Hashtable; import java.util.Map; +import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; @@ -169,72 +170,117 @@ public class GDBBreakpoints_7_4 extends GDBBreakpoints_7_2 implements IEventList } @Override - protected void addBreakpoint(IBreakpointsTargetDMContext context, Map attributes, DataRequestMonitor finalRm) { - MIBreakpointsSynchronizer bs = getServicesTracker().getService(MIBreakpointsSynchronizer.class); + protected void addBreakpoint( + final IBreakpointsTargetDMContext context, + final Map attributes, + final DataRequestMonitor finalRm) { + final MIBreakpointsSynchronizer bs = getServicesTracker().getService(MIBreakpointsSynchronizer.class); if (bs != null) { // Skip the breakpoints set from the console or from outside of Eclipse // because they are already installed on the target. - MIBreakpoint miBpt = bs.getTargetBreakpoint(context, attributes); - if (miBpt != null) { - bs.removeCreatedTargetBreakpoint(context, miBpt); - MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(miBpt); - getBreakpointMap(context).put(newBreakpoint.getNumber(), newBreakpoint); - IBreakpointDMContext dmc = new MIBreakpointDMContext(this, new IDMContext[] { context }, newBreakpoint.getNumber()); - finalRm.setData(dmc); - - getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties()); - - finalRm.done(); - return; - } + bs.getTargetBreakpoint( + context, + attributes, + new DataRequestMonitor(getExecutor(), finalRm) { + @Override + @ConfinedToDsfExecutor( "fExecutor" ) + protected void handleSuccess() { + MIBreakpoint miBpt = getData(); + if (miBpt != null) { + bs.removeCreatedTargetBreakpoint(context, miBpt); + MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(miBpt); + getBreakpointMap(context).put(newBreakpoint.getNumber(), newBreakpoint); + IBreakpointDMContext dmc = + new MIBreakpointDMContext(GDBBreakpoints_7_4.this, new IDMContext[] { context }, newBreakpoint.getNumber()); + finalRm.setData(dmc); + getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties()); + finalRm.done(); + } + else { + GDBBreakpoints_7_4.super.addBreakpoint(context, attributes, finalRm); + } + } + }); + } + else { + super.addBreakpoint(context, attributes, finalRm); } - super.addBreakpoint(context, attributes, finalRm); } @Override - protected void addTracepoint(IBreakpointsTargetDMContext context, Map attributes, DataRequestMonitor drm) { - MIBreakpointsSynchronizer bs = getServicesTracker().getService(MIBreakpointsSynchronizer.class); + protected void addTracepoint( + final IBreakpointsTargetDMContext context, + final Map attributes, + final DataRequestMonitor drm) { + final MIBreakpointsSynchronizer bs = getServicesTracker().getService(MIBreakpointsSynchronizer.class); if (bs != null) { // Skip the breakpoints set from the console or from outside of Eclipse // because they are already installed on the target. - MIBreakpoint miBpt = bs.getTargetBreakpoint(context, attributes); - if (miBpt != null) { - bs.removeCreatedTargetBreakpoint(context, miBpt); - MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(miBpt); - getBreakpointMap(context).put(newBreakpoint.getNumber(), newBreakpoint); - IBreakpointDMContext dmc = new MIBreakpointDMContext(this, new IDMContext[] { context }, newBreakpoint.getNumber()); - drm.setData(dmc); - - getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties()); - - drm.done(); - return; - } + bs.getTargetBreakpoint( + context, + attributes, + new DataRequestMonitor(getExecutor(), drm) { + @Override + @ConfinedToDsfExecutor( "fExecutor" ) + protected void handleSuccess() { + MIBreakpoint miBpt = getData(); + if (miBpt != null) { + bs.removeCreatedTargetBreakpoint(context, miBpt); + MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(miBpt); + getBreakpointMap(context).put(newBreakpoint.getNumber(), newBreakpoint); + IBreakpointDMContext dmc = + new MIBreakpointDMContext(GDBBreakpoints_7_4.this, new IDMContext[] { context }, newBreakpoint.getNumber()); + drm.setData(dmc); + getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties()); + drm.done(); + } + else { + GDBBreakpoints_7_4.super.addTracepoint(context, attributes, drm); + } + } + }); + } + else { + super.addTracepoint(context, attributes, drm); } - super.addTracepoint(context, attributes, drm); } @Override - protected void addWatchpoint(IBreakpointsTargetDMContext context, Map attributes, DataRequestMonitor drm) { - MIBreakpointsSynchronizer bs = getServicesTracker().getService(MIBreakpointsSynchronizer.class); + protected void addWatchpoint( + final IBreakpointsTargetDMContext context, + final Map attributes, + final DataRequestMonitor drm) { + final MIBreakpointsSynchronizer bs = getServicesTracker().getService(MIBreakpointsSynchronizer.class); if (bs != null) { // Skip the breakpoints set from the console or from outside of Eclipse // because they are already installed on the target. - MIBreakpoint miBpt = bs.getTargetBreakpoint(context, attributes); - if (miBpt != null) { - bs.removeCreatedTargetBreakpoint(context, miBpt); - MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(miBpt); - getBreakpointMap(context).put(newBreakpoint.getNumber(), newBreakpoint); - IBreakpointDMContext dmc = new MIBreakpointDMContext(this, new IDMContext[] { context }, newBreakpoint.getNumber()); - drm.setData(dmc); - - getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties()); - - drm.done(); - return; - } + bs.getTargetBreakpoint( + context, + attributes, + new DataRequestMonitor(getExecutor(), drm) { + @Override + @ConfinedToDsfExecutor( "fExecutor" ) + protected void handleSuccess() { + MIBreakpoint miBpt = getData(); + if (miBpt != null) { + bs.removeCreatedTargetBreakpoint(context, miBpt); + MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(miBpt); + getBreakpointMap(context).put(newBreakpoint.getNumber(), newBreakpoint); + IBreakpointDMContext dmc = + new MIBreakpointDMContext(GDBBreakpoints_7_4.this, new IDMContext[] { context }, newBreakpoint.getNumber()); + drm.setData(dmc); + getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties()); + drm.done(); + } + else { + GDBBreakpoints_7_4.super.addWatchpoint(context, attributes, drm); + } + } + }); + } + else { + super.addWatchpoint(context, attributes, drm); } - super.addWatchpoint(context, attributes, drm); } @Override diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsSynchronizer.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsSynchronizer.java index aa74559bdb4..abf68c175f4 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsSynchronizer.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpointsSynchronizer.java @@ -37,6 +37,7 @@ import org.eclipse.cdt.debug.core.model.ICTracepoint; import org.eclipse.cdt.debug.core.model.ICWatchpoint; import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.datamodel.DMContexts; @@ -731,86 +732,126 @@ public class MIBreakpointsSynchronizer extends AbstractDsfService implements IMI return DMContexts.getAncestorOfType(contContext, IBreakpointsTargetDMContext.class); } - public MIBreakpoint getTargetBreakpoint(IBreakpointsTargetDMContext context, Map attributes) { + public void getTargetBreakpoint( + IBreakpointsTargetDMContext context, + Map attributes, + DataRequestMonitor rm) { Map map = fCreatedTargetBreakpoints.get(context); - if (map == null) - return null; + if (map == null) { + rm.done(); + return; + } String type = (String)attributes.get(MIBreakpoints.BREAKPOINT_TYPE); if (MIBreakpoints.BREAKPOINT.equals(type)) { - return getTargetLineBreakpoint( + getTargetLineBreakpoint( + context, map.values(), (String)attributes.get(MIBreakpoints.FILE_NAME), (Integer)attributes.get(MIBreakpoints.LINE_NUMBER), (String)attributes.get(MIBreakpoints.FUNCTION), (String)attributes.get(MIBreakpoints.ADDRESS), (Boolean)attributes.get(MIBreakpointDMData.IS_HARDWARE), - (Boolean)attributes.get(MIBreakpointDMData.IS_TEMPORARY)); + (Boolean)attributes.get(MIBreakpointDMData.IS_TEMPORARY), + rm); } else if (MIBreakpoints.TRACEPOINT.equals(type)) { - return getTargetTracepoint( + getTargetTracepoint( + context, map.values(), (String)attributes.get(MIBreakpoints.FILE_NAME), (Integer)attributes.get(MIBreakpoints.LINE_NUMBER), (String)attributes.get(MIBreakpoints.FUNCTION), (String)attributes.get(MIBreakpoints.ADDRESS), (Boolean)attributes.get(MIBreakpointDMData.IS_HARDWARE), - (Boolean)attributes.get(MIBreakpointDMData.IS_TEMPORARY)); + (Boolean)attributes.get(MIBreakpointDMData.IS_TEMPORARY), + rm); } else if (MIBreakpoints.WATCHPOINT.equals(type)) { - return getTargetWatchpoint( + getTargetWatchpoint( + context, map.values(), (String)attributes.get(MIBreakpoints.EXPRESSION), (Boolean)attributes.get(MIBreakpoints.READ), (Boolean)attributes.get(MIBreakpoints.WRITE), (Boolean)attributes.get(MIBreakpointDMData.IS_HARDWARE), - (Boolean)attributes.get(MIBreakpointDMData.IS_TEMPORARY)); + (Boolean)attributes.get(MIBreakpointDMData.IS_TEMPORARY), + rm); } - return null; + else { + rm.done(); + } } - private MIBreakpoint getTargetLineBreakpoint( + private void getTargetLineBreakpoint( + IBreakpointsTargetDMContext bpTargetDMC, Collection targetBreakpoints, String fileName, Integer lineNumber, String function, String address, Boolean isHardware, - Boolean isTemporary) { + Boolean isTemporary, + DataRequestMonitor drm) { + List candidates = new ArrayList(targetBreakpoints.size()); for (MIBreakpoint miBpt : targetBreakpoints) { - if (!miBpt.isWatchpoint() && !isCatchpoint(miBpt) && !miBpt.isTracepoint() - && compareBreakpointAttributes( - miBpt, fileName, lineNumber, function, address, isHardware, isTemporary)) - return miBpt; + if (!miBpt.isWatchpoint() && !isCatchpoint(miBpt) && !miBpt.isTracepoint()) { + // Filter out target breakpoints with different file names and line numbers + if (fileName == null + || (new File(fileName).getName().equals(new File(getFileName(miBpt)).getName()) + && getLineNumber(miBpt) == lineNumber)) { + candidates.add(miBpt); + } + } } - return null; + if (candidates.size() == 0) { + drm.done(); + return; + } + + findTargetLineBreakpoint(bpTargetDMC, candidates, + fileName, lineNumber, function, address, isHardware, isTemporary, drm); } - private MIBreakpoint getTargetTracepoint( + private void getTargetTracepoint( + IBreakpointsTargetDMContext bpTargetDMC, Collection targetBreakpoints, String fileName, Integer lineNumber, String function, String address, Boolean isHardware, - Boolean isTemporary) { + Boolean isTemporary, + DataRequestMonitor rm) { + List candidates = new ArrayList(targetBreakpoints.size()); for (MIBreakpoint miBpt : targetBreakpoints) { - if (miBpt.isTracepoint() - && compareBreakpointAttributes( - miBpt, fileName, lineNumber, function, address, isHardware, isTemporary)) - return miBpt; + if (miBpt.isTracepoint()) { + // Filter out target breakpoints with different file names and line numbers + if (new File(fileName).getName().equals(new File(getFileName(miBpt)).getName()) + && miBpt.getLine() == lineNumber) { + candidates.add(miBpt); + } + } } - return null; + if (candidates.size() == 0) { + rm.done(); + return; + } + + findTargetLineBreakpoint(bpTargetDMC, candidates, + fileName, lineNumber, function, address, isHardware, isTemporary, rm); } - private MIBreakpoint getTargetWatchpoint( + private void getTargetWatchpoint( + IBreakpointsTargetDMContext bpTargetDMC, Collection targetBreakpoints, String expression, boolean readAccess, boolean writeAccess, Boolean isHardware, - Boolean isTemporary) { + Boolean isTemporary, + DataRequestMonitor rm) { for (MIBreakpoint miBpt : targetBreakpoints) { if (!miBpt.isWatchpoint()) continue; @@ -824,25 +865,92 @@ public class MIBreakpointsSynchronizer extends AbstractDsfService implements IMI continue; if (!compareBreakpointTypeAttributes(miBpt, isHardware, isTemporary)) continue; - return miBpt; + rm.setData(miBpt); + break; } - return null; + rm.done(); + } + + private void findTargetLineBreakpoint( + final IBreakpointsTargetDMContext bpTargetDMC, + final List candidates, + final String fileName, + final Integer lineNumber, + final String function, + final String address, + final Boolean isHardware, + final Boolean isTemporary, + final DataRequestMonitor drm) { + // We need to convert the debugger paths of the candidate target breakpoints + // before comparing them with the platform breakpoint's file name. + final List bpts = new ArrayList(candidates); + + class FindBreakpointRM extends ImmediateDataRequestMonitor { + + @Override + @ConfinedToDsfExecutor("fExecutor") + protected void handleCompleted() { + if (bpts.isEmpty()) { + drm.done(); + return; + } + + final MIBreakpoint bpt = bpts.remove(0); + final String debuggerPath = getFileName(bpt); + getSource( + bpTargetDMC, + debuggerPath, + new DataRequestMonitor(getExecutor(), drm) { + @Override + @ConfinedToDsfExecutor( "fExecutor" ) + protected void handleCompleted() { + // If an error occur performing source lookup + // log it and use the debugger path. + if (!isSuccess()) { + GdbPlugin.log(getStatus()); + } + if (compareBreakpointAttributes( + bpt, + isSuccess() ? getData() : debuggerPath, + fileName, + lineNumber, + function, + address, + isHardware, + isTemporary)) { + // The target breakpoint is found, we're done. + drm.setData(bpt); + drm.done(); + } + else { + // Try the next candidate + new FindBreakpointRM().done(); + } + } + }); + } + }; + + // Start the search. + new FindBreakpointRM().done(); } private boolean compareBreakpointAttributes( MIBreakpoint miBpt, + String miBptFileName, String fileName, Integer lineNumber, String function, String address, Boolean isHardware, Boolean isTemporary) { - return compareBreakpointLocationAttributes(miBpt, fileName, lineNumber, function, address) + return compareBreakpointLocationAttributes(miBpt, miBptFileName, fileName, lineNumber, function, address) && compareBreakpointTypeAttributes(miBpt, isHardware, isTemporary); } private boolean compareBreakpointLocationAttributes( MIBreakpoint miBpt, + String miBptFileName, String fileName, Integer lineNumber, String function, @@ -853,7 +961,7 @@ public class MIBreakpointsSynchronizer extends AbstractDsfService implements IMI && (address == null || !address.equals(getPlatformAddress(miBpt.getAddress()).toHexAddressString()))) return false; if (isLineBreakpoint(miBpt)) { - if (fileName == null || !fileName.equals(getFileName(miBpt))) + if (fileName == null || !fileName.equals(miBptFileName)) return false; if (lineNumber == null || lineNumber.intValue() != getLineNumber(miBpt)) return false; From 1131bb801d76a156fcb79a6997c243cc9bd2eff8 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 3 Jan 2013 11:52:19 -0500 Subject: [PATCH 17/23] Bug 380344 - RunToLine or MoveToLine doesn't use sourcelookup to set its temporary breakpoint Change-Id: Ibde43ce9c3c8edba581db0a7caac204657e8c7b0 Reviewed-on: https://git.eclipse.org/r/9433 Reviewed-by: Mikhail Khodjaiants IP-Clean: Mikhail Khodjaiants Tested-by: Mikhail Khodjaiants Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../dsf/gdb/service/GDBRunControl_7_0_NS.java | 90 ++++++++++++------ .../cdt/dsf/mi/service/MIRunControl.java | 91 +++++++++++++------ 2 files changed, 127 insertions(+), 54 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java index d8eb3adaac6..a3d72580739 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java @@ -51,6 +51,8 @@ import org.eclipse.cdt.dsf.debug.service.IProcesses.IProcessDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses.IThreadDMContext; import org.eclipse.cdt.dsf.debug.service.IRunControl; import org.eclipse.cdt.dsf.debug.service.IRunControl2; +import org.eclipse.cdt.dsf.debug.service.ISourceLookup; +import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext; import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommand; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; @@ -1727,13 +1729,15 @@ public class GDBRunControl_7_0_NS extends AbstractDsfService implements IMIRunCo * @since 3.0 */ @Override - public void runToLine(IExecutionDMContext context, String sourceFile, - int lineNumber, boolean skipBreakpoints, RequestMonitor rm) { + public void runToLine(final IExecutionDMContext context, String sourceFile, + final int lineNumber, final boolean skipBreakpoints, final RequestMonitor rm) { - // Hack around a MinGW bug; see 196154 - sourceFile = adjustDebuggerPath(sourceFile); - - runToLocation(context, sourceFile + ":" + Integer.toString(lineNumber), skipBreakpoints, rm); //$NON-NLS-1$ + determineDebuggerPath(context, sourceFile, new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + runToLocation(context, getData() + ":" + Integer.toString(lineNumber), skipBreakpoints, rm); //$NON-NLS-1$ + } + }); } /* (non-Javadoc) @@ -1778,33 +1782,37 @@ public class GDBRunControl_7_0_NS extends AbstractDsfService implements IMIRunCo * @since 3.0 */ @Override - public void moveToLine(IExecutionDMContext context, String sourceFile, - int lineNumber, boolean resume, RequestMonitor rm) { - IMIExecutionDMContext threadExecDmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class); + public void moveToLine(final IExecutionDMContext context, String sourceFile, + final int lineNumber, final boolean resume, final RequestMonitor rm) { + final IMIExecutionDMContext threadExecDmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class); if (threadExecDmc == null) { rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Invalid thread context", null)); //$NON-NLS-1$ rm.done(); } else { - // Hack around a MinGW bug; see 369622 (and also 196154 and 232415) - sourceFile = adjustDebuggerPath(sourceFile); - - String location = sourceFile + ":" + lineNumber; //$NON-NLS-1$ - if (resume) - resumeAtLocation(context, location, rm); - else - { - // Create the breakpoint attributes - Map attr = new HashMap(); - attr.put(MIBreakpoints.BREAKPOINT_TYPE, MIBreakpoints.BREAKPOINT); - attr.put(MIBreakpoints.FILE_NAME, sourceFile); - attr.put(MIBreakpoints.LINE_NUMBER, lineNumber); - attr.put(MIBreakpointDMData.IS_TEMPORARY, true); - attr.put(MIBreakpointDMData.THREAD_ID, Integer.toString(threadExecDmc.getThreadId())); - // Now do the operation - moveToLocation(context, location, attr, rm); - } + determineDebuggerPath(context, sourceFile, new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + String debuggerPath = getData(); + + String location = debuggerPath + ":" + lineNumber; //$NON-NLS-1$ + if (resume) { + resumeAtLocation(context, location, rm); + } else { + // Create the breakpoint attributes + Map attr = new HashMap(); + attr.put(MIBreakpoints.BREAKPOINT_TYPE, MIBreakpoints.BREAKPOINT); + attr.put(MIBreakpoints.FILE_NAME, debuggerPath); + attr.put(MIBreakpoints.LINE_NUMBER, lineNumber); + attr.put(MIBreakpointDMData.IS_TEMPORARY, true); + attr.put(MIBreakpointDMData.THREAD_ID, Integer.toString(threadExecDmc.getThreadId())); + + // Now do the operation + moveToLocation(context, location, attr, rm); + } + } + }); } } @@ -1866,6 +1874,34 @@ public class GDBRunControl_7_0_NS extends AbstractDsfService implements IMIRunCo } /** + * Determine the path that should be sent to the debugger as per the source lookup service. + * + * @param dmc A context that can be used to obtain the sourcelookup context. + * @param hostPath The path of the file on the host, which must be converted. + * @param rm The result of the conversion. + */ + private void determineDebuggerPath(IDMContext dmc, String hostPath, final DataRequestMonitor rm) + { + ISourceLookup sourceLookup = getServicesTracker().getService(ISourceLookup.class); + ISourceLookupDMContext srcDmc = DMContexts.getAncestorOfType(dmc, ISourceLookupDMContext.class); + if (sourceLookup == null || srcDmc == null) { + // Source lookup not available for given context, use the host + // path for the debugger path. + // Hack around a MinGW bug; see 369622 (and also 196154 and 232415) + rm.done(adjustDebuggerPath(hostPath)); + return; + } + + sourceLookup.getDebuggerPath(srcDmc, hostPath, new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleSuccess() { + // Hack around a MinGW bug; see 369622 (and also 196154 and 232415) + rm.done(adjustDebuggerPath(getData())); + } + }); + } + + /** * See bug 196154 * * @param path diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIRunControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIRunControl.java index b15021870f3..de72f05ae9b 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIRunControl.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIRunControl.java @@ -21,6 +21,7 @@ import java.util.Map; import org.eclipse.cdt.core.IAddress; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; +import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.Immutable; @@ -40,6 +41,8 @@ import org.eclipse.cdt.dsf.debug.service.IBreakpointsExtension.IBreakpointHitDME import org.eclipse.cdt.dsf.debug.service.ICachingService; import org.eclipse.cdt.dsf.debug.service.IDisassembly.IDisassemblyDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses; +import org.eclipse.cdt.dsf.debug.service.ISourceLookup; +import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext; import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; import org.eclipse.cdt.dsf.debug.service.command.BufferedCommandControl; import org.eclipse.cdt.dsf.debug.service.command.CommandCache; @@ -1435,13 +1438,15 @@ public class MIRunControl extends AbstractDsfService implements IMIRunControl, I * @since 3.0 */ @Override - public void runToLine(IExecutionDMContext context, String sourceFile, - int lineNumber, boolean skipBreakpoints, RequestMonitor rm) { + public void runToLine(final IExecutionDMContext context, String sourceFile, + final int lineNumber, final boolean skipBreakpoints, final RequestMonitor rm) { - // Hack around a MinGW bug; see 196154 - sourceFile = MIBreakpointsManager.adjustDebuggerPath(sourceFile); - - runToLocation(context, sourceFile + ":" + Integer.toString(lineNumber), skipBreakpoints, rm); //$NON-NLS-1$ + determineDebuggerPath(context, sourceFile, new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + runToLocation(context, getData() + ":" + Integer.toString(lineNumber), skipBreakpoints, rm); //$NON-NLS-1$ + } + }); } /* (non-Javadoc) @@ -1487,33 +1492,37 @@ public class MIRunControl extends AbstractDsfService implements IMIRunControl, I * @since 3.0 */ @Override - public void moveToLine(IExecutionDMContext context, String sourceFile, - int lineNumber, boolean resume, RequestMonitor rm) { - IMIExecutionDMContext threadExecDmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class); + public void moveToLine(final IExecutionDMContext context, String sourceFile, + final int lineNumber, final boolean resume, final RequestMonitor rm) { + final IMIExecutionDMContext threadExecDmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class); if (threadExecDmc == null) { rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Invalid thread context", null)); //$NON-NLS-1$ rm.done(); } else { - // Hack around a MinGW bug; see 369622 (and also 196154 and 232415) - sourceFile = MIBreakpointsManager.adjustDebuggerPath(sourceFile); - - String location = sourceFile + ":" + lineNumber; //$NON-NLS-1$ - if (resume) - resumeAtLocation(context, location, rm); - else { - // Create the breakpoint attributes - Map attr = new HashMap(); - attr.put(MIBreakpoints.BREAKPOINT_TYPE, MIBreakpoints.BREAKPOINT); - attr.put(MIBreakpoints.FILE_NAME, sourceFile); - attr.put(MIBreakpoints.LINE_NUMBER, lineNumber); - attr.put(MIBreakpointDMData.IS_TEMPORARY, true); - attr.put(MIBreakpointDMData.THREAD_ID, Integer.toString(threadExecDmc.getThreadId())); - - // Now do the operation - moveToLocation(context, location, attr, rm); - } + determineDebuggerPath(context, sourceFile, new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + String debuggerPath = getData(); + + String location = debuggerPath + ":" + lineNumber; //$NON-NLS-1$ + if (resume) { + resumeAtLocation(context, location, rm); + } else { + // Create the breakpoint attributes + Map attr = new HashMap(); + attr.put(MIBreakpoints.BREAKPOINT_TYPE, MIBreakpoints.BREAKPOINT); + attr.put(MIBreakpoints.FILE_NAME, debuggerPath); + attr.put(MIBreakpoints.LINE_NUMBER, lineNumber); + attr.put(MIBreakpointDMData.IS_TEMPORARY, true); + attr.put(MIBreakpointDMData.THREAD_ID, Integer.toString(threadExecDmc.getThreadId())); + + // Now do the operation + moveToLocation(context, location, attr, rm); + } + } + }); } } @@ -1578,4 +1587,32 @@ public class MIRunControl extends AbstractDsfService implements IMIRunControl, I // we know GDB is accepting commands return !fTerminated && fSuspended && !fResumePending; } + + /** + * Determine the path that should be sent to the debugger as per the source lookup service. + * + * @param dmc A context that can be used to obtain the sourcelookup context. + * @param hostPath The path of the file on the host, which must be converted. + * @param rm The result of the conversion. + */ + private void determineDebuggerPath(IDMContext dmc, String hostPath, final DataRequestMonitor rm) + { + ISourceLookup sourceLookup = getServicesTracker().getService(ISourceLookup.class); + ISourceLookupDMContext srcDmc = DMContexts.getAncestorOfType(dmc, ISourceLookupDMContext.class); + if (sourceLookup == null || srcDmc == null) { + // Source lookup not available for given context, use the host + // path for the debugger path. + // Hack around a MinGW bug; see 369622 (and also 196154 and 232415) + rm.done(MIBreakpointsManager.adjustDebuggerPath(hostPath)); + return; + } + + sourceLookup.getDebuggerPath(srcDmc, hostPath, new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleSuccess() { + // Hack around a MinGW bug; see 369622 (and also 196154 and 232415) + rm.done(MIBreakpointsManager.adjustDebuggerPath(getData())); + } + }); + } } From fb5f1bd39db76db409626eee2f46cde13c9d7784 Mon Sep 17 00:00:00 2001 From: Randy Rohrbach Date: Mon, 7 Jan 2013 17:48:41 -0500 Subject: [PATCH 18/23] Bug 397636 : Editing the SRecord Exporter length field fill it in with the end address. --- .../cdt/debug/ui/memory/transport/SRecordExporter.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java index f1e7807b101..f5786fb0cb3 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java @@ -239,7 +239,6 @@ public class SRecordExporter implements IMemoryExporter { fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); validate(); - //fParentDialog.setValid(false); } } @@ -267,7 +266,6 @@ public class SRecordExporter implements IMemoryExporter { fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); validate(); - //fParentDialog.setValid(false); } } @@ -284,9 +282,8 @@ public class SRecordExporter implements IMemoryExporter String endString = "0x" + getStartAddress().add(length).toString(16); //$NON-NLS-1$ if(!fEndText.getText().equals(endString)) { if ( ! length.equals( BigInteger.ZERO ) ) { - fLengthText.setText(endString); + fEndText.setText(endString); } - fEndText.setText(endString); } validate(); } @@ -294,7 +291,6 @@ public class SRecordExporter implements IMemoryExporter { fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); validate(); - //fParentDialog.setValid(false); } } From f9498e093ad0115aed3bb418bbf3ab460554ece5 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 7 Jan 2013 14:57:19 -0800 Subject: [PATCH 19/23] Bug 395243. Fall back to the simplified type if the original type of a template argument could not be stored in the index. --- .../eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java index ac6d4058964..99d99e82e3f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java @@ -214,7 +214,7 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { fPos--; IType type = unmarshalType(); IType originalType = unmarshalType(); - if (originalType == null) + if (originalType == null || originalType == UNSTORABLE_TYPE_PROBLEM) originalType= type; return new CPPTemplateTypeArgument(type, originalType); } From 67ac1524014e012dc2bc6745fcac955d73c75a81 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 7 Jan 2013 15:00:03 -0800 Subject: [PATCH 20/23] Bug 395243. Don't allow template arguments based on problem types. --- .../parser/cpp/semantics/CPPEvaluation.java | 2 +- .../parser/cpp/semantics/CPPTemplates.java | 53 ++++++++++++------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 762badaa597..d1d279b2628 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -240,7 +240,7 @@ public abstract class CPPEvaluation implements ICPPEvaluation { protected static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { try { - return CPPTemplates.instantiateArguments(args, tpMap, packOffset, within, point); + return CPPTemplates.instantiateArguments(args, tpMap, packOffset, within, point, false); } catch (DOMException e) { CCorePlugin.log(e); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 717bd660ad6..4d3afd83849 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -789,7 +789,7 @@ public class CPPTemplates { ICPPClassTemplate template= pspec.getPrimaryClassTemplate(); ICPPTemplateArgument[] args = pspec.getTemplateArguments(); template= (ICPPClassTemplate) owner.specializeMember(template, point); - args= instantiateArguments(args, tpMap, -1, within, point); + args= instantiateArguments(args, tpMap, -1, within, point, false); spec= new CPPClassTemplatePartialSpecializationSpecialization(pspec, tpMap, template, args); } catch (DOMException e) { } @@ -1047,10 +1047,15 @@ public class CPPTemplates { } /** - * Instantiates arguments contained in an array. + * Instantiates arguments contained in an array. Instantiated arguments are checked for + * validity. If the {@code strict} parameter is {@code true}, the method returns {@code null} if + * any of the instantiated arguments are invalid. If the {@code strict} parameter is + * {@code false}, any invalid instantiated arguments are replaced by the corresponding original + * arguments. */ public static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, - ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) + ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, + IASTNode point, boolean strict) throws DOMException { // Don't create a new array until it's really needed. ICPPTemplateArgument[] result = args; @@ -1066,11 +1071,19 @@ public class CPPTemplates { } else if (packSize == PACK_SIZE_DEFER) { newArg= origArg; } else { - final int shift = packSize - 1; + int shift = packSize - 1; ICPPTemplateArgument[] newResult= new ICPPTemplateArgument[args.length + resultShift + shift]; System.arraycopy(result, 0, newResult, 0, i + resultShift); for (int j= 0; j < packSize; j++) { - newResult[i + resultShift + j]= instantiateArgument(origArg, tpMap, j, within, point); + newArg = instantiateArgument(origArg, tpMap, j, within, point); + if (!isValidArgument(newArg)) { + if (strict) + return null; + newResult = result; + shift = 0; + break; + } + newResult[i + resultShift + j]= newArg; } result= newResult; resultShift += shift; @@ -1078,7 +1091,13 @@ public class CPPTemplates { } } else { newArg = instantiateArgument(origArg, tpMap, packOffset, within, point); + if (!isValidArgument(newArg)) { + if (strict) + return null; + newArg = origArg; + } } + if (result != args) { result[i + resultShift]= newArg; } else if (newArg != origArg) { @@ -1122,12 +1141,15 @@ public class CPPTemplates { for (Integer key : positions) { ICPPTemplateArgument arg = orig.getArgument(key); if (arg != null) { - newMap.put(key, instantiateArgument(arg, tpMap, packOffset, within, point)); + ICPPTemplateArgument newArg = instantiateArgument(arg, tpMap, packOffset, within, point); + if (!isValidArgument(newArg)) + newArg = arg; + newMap.put(key, newArg); } else { ICPPTemplateArgument[] args = orig.getPackExpansion(key); if (args != null) { try { - newMap.put(key, instantiateArguments(args, tpMap, packOffset, within, point)); + newMap.put(key, instantiateArguments(args, tpMap, packOffset, within, point, false)); } catch (DOMException e) { newMap.put(key, args); } @@ -1211,7 +1233,7 @@ public class CPPTemplates { final IBinding origClass = classInstance.getSpecializedBinding(); if (origClass instanceof ICPPClassType) { ICPPTemplateArgument[] args = classInstance.getTemplateArguments(); - ICPPTemplateArgument[] newArgs = instantiateArguments(args, tpMap, packOffset, within, point); + ICPPTemplateArgument[] newArgs = instantiateArguments(args, tpMap, packOffset, within, point, false); if (newArgs != args) { CPPTemplateParameterMap tparMap = instantiateArgumentMap(classInstance.getTemplateParameterMap(), tpMap, packOffset, within, point); return new CPPClassInstance((ICPPClassType) origClass, classInstance.getOwner(), tparMap, args); @@ -2061,12 +2083,7 @@ public class CPPTemplates { private static boolean checkInstantiationOfArguments(ICPPTemplateArgument[] args, CPPTemplateParameterMap tpMap, IASTNode point) throws DOMException { - args = instantiateArguments(args, tpMap, -1, null, point); - for (ICPPTemplateArgument arg : args) { - if (!isValidArgument(arg)) - return false; - } - return true; + return instantiateArguments(args, tpMap, -1, null, point, true) != null; } /** @@ -2124,7 +2141,7 @@ public class CPPTemplates { args[i]= arg; transferMap.put(param, arg); } - final ICPPTemplateArgument[] transferredArgs1 = instantiateArguments(targs1, transferMap, -1, null, point); + final ICPPTemplateArgument[] transferredArgs1 = instantiateArguments(targs1, transferMap, -1, null, point, false); // Deduce arguments for specialization 2 final CPPTemplateParameterMap deductionMap= new CPPTemplateParameterMap(2); @@ -2468,7 +2485,7 @@ public class CPPTemplates { if (unknown instanceof ICPPUnknownMemberClassInstance) { ICPPUnknownMemberClassInstance ucli= (ICPPUnknownMemberClassInstance) unknown; ICPPTemplateArgument[] args0 = ucli.getArguments(); - ICPPTemplateArgument[] args1 = instantiateArguments(args0, tpMap, packOffset, within, point); + ICPPTemplateArgument[] args1 = instantiateArguments(args0, tpMap, packOffset, within, point, false); if (args0 != args1 || !ot1.isSameType(ot0)) { args1= SemanticUtil.getSimplifiedArguments(args1); result= new CPPUnknownClassInstance(ot1, ucli.getNameCharArray(), args1); @@ -2486,7 +2503,7 @@ public class CPPTemplates { result= CPPSemantics.resolveUnknownName(s, unknown, point); if (unknown instanceof ICPPUnknownMemberClassInstance && result instanceof ICPPTemplateDefinition) { ICPPTemplateArgument[] args1 = instantiateArguments( - ((ICPPUnknownMemberClassInstance) unknown).getArguments(), tpMap, packOffset, within, point); + ((ICPPUnknownMemberClassInstance) unknown).getArguments(), tpMap, packOffset, within, point, false); if (result instanceof ICPPClassTemplate) { result = instantiate((ICPPClassTemplate) result, args1, point); } @@ -2505,7 +2522,7 @@ public class CPPTemplates { ICPPTemplateArgument[] arguments = dci.getTemplateArguments(); ICPPTemplateArgument[] newArgs; try { - newArgs = instantiateArguments(arguments, tpMap, packOffset, within, point); + newArgs = instantiateArguments(arguments, tpMap, packOffset, within, point, false); } catch (DOMException e) { return e.getProblem(); } From f0e663e7cffc90d6828be98ae5e397b59d14bd12 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Wed, 12 Dec 2012 19:29:09 -0500 Subject: [PATCH 21/23] Bug 395243 - Error involving dependent expressions Change-Id: Iabd115b40d0b7b633c416171a19a981f1e51dee8 Reviewed-on: https://git.eclipse.org/r/9211 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../parser/tests/ast2/AST2TemplateTests.java | 65 ++++++++++++++++++- .../dom/parser/cpp/CPPDeferredFunction.java | 28 +++++--- .../dom/parser/cpp/CPPUnknownConstructor.java | 8 ++- .../parser/cpp/semantics/CPPFunctionSet.java | 2 +- .../parser/cpp/semantics/CPPSemantics.java | 9 +-- .../parser/cpp/semantics/CPPTemplates.java | 32 ++++----- .../dom/parser/cpp/semantics/CPPVisitor.java | 7 +- .../dom/parser/cpp/semantics/EvalBinding.java | 8 +++ .../parser/cpp/semantics/EvalFunctionSet.java | 10 ++- .../core/dom/parser/cpp/semantics/EvalID.java | 30 ++++++--- 10 files changed, 150 insertions(+), 49 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 1b3079dfc0f..19350ee7d27 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -6938,7 +6938,70 @@ public class AST2TemplateTests extends AST2BaseTest { // static const int value = sizeof(waldo(f)); // }; // typedef identity::value>>::type reference; - public void _testDependentExpressions_395243() throws Exception { + public void testDependentExpressions_395243a() throws Exception { + parseAndCheckBindings(); + } + + // typedef char one; + // typedef struct { + // char arr[2]; + // } two; + // template + // struct has_foo_type { + // template + // struct wrap_type { }; + // template + // static one test(wrap_type*); + // template + // static two test(...); + // static const bool value = sizeof(test(0)) == 1; + // }; + // template + // struct traits; + // template <> + // struct traits { + // typedef int bar_type; + // }; + // struct S { + // typedef int foo_type; + // }; + // traits::value>::bar_type a; + public void testDependentExpressions_395243b() throws Exception { + parseAndCheckBindings(); + } + + // template U bar(U); + // template auto waldo(T t) -> decltype(bar(t)); + // struct S { + // void foo() const; + // }; + // struct V { + // S arr[5]; + // }; + // int main() { + // V e; + // auto v = waldo(e); + // for (auto s : v.arr) + // s.foo(); + // } + public void testDependentExpressions_395243c() throws Exception { + parseAndCheckBindings(); + } + + // template class C {}; + // template int begin(C); + // template + // struct A { + // class B { + // void m(); + // }; + // void test() { + // B* v[5]; + // for (auto x : v) + // x->m(); + // } + // }; + public void testDependentExpressions_395243d() throws Exception { parseAndCheckBindings(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java index daf282b6106..88f0d3b79d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java @@ -8,12 +8,11 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; @@ -30,19 +29,32 @@ public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPFuncti private static final ICPPFunctionType FUNCTION_TYPE= new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY); - public static ICPPFunction createForSample(IFunction sample) throws DOMException { - if (sample instanceof ICPPConstructor) - return new CPPUnknownConstructor(((ICPPConstructor) sample).getClassOwner()); + /** + * Creates a CPPDeferredFunction given a set of overloaded functions + * (some of which may be templates) that the function might resolve to. + * At least one candidate must be provided. + * @param candidates a set of overloaded functions, some of which may be templates + * @return the constructed CPPDeferredFunction + */ + public static ICPPFunction createForCandidates(ICPPFunction... candidates) { + if (candidates[0] instanceof ICPPConstructor) + return new CPPUnknownConstructor(((ICPPConstructor) candidates[0]).getClassOwner(), candidates); - final IBinding owner = sample.getOwner(); - return new CPPDeferredFunction(owner, sample.getNameCharArray()); + final IBinding owner = candidates[0].getOwner(); + return new CPPDeferredFunction(owner, candidates[0].getNameCharArray(), candidates); } private final IBinding fOwner; + private final ICPPFunction[] fCandidates; - public CPPDeferredFunction(IBinding owner, char[] name) { + public CPPDeferredFunction(IBinding owner, char[] name, ICPPFunction[] candidates) { super(name); fOwner= owner; + fCandidates = candidates; + } + + public ICPPFunction[] getCandidates() { + return fCandidates; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java index 0dd63fc488a..94b59961cfa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java @@ -8,11 +8,13 @@ * Contributors: * Markus Schorn - initial API and implementation * Thomas Corbat (IFS) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; /** * Represents a reference to a constructor (instance), which cannot be resolved because @@ -21,7 +23,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; public class CPPUnknownConstructor extends CPPDeferredFunction implements ICPPConstructor { public CPPUnknownConstructor(ICPPClassType owner) { - super(owner, owner.getNameCharArray()); + super(owner, owner.getNameCharArray(), null); + } + + public CPPUnknownConstructor(ICPPClassType owner, ICPPFunction[] candidates) { + super(owner, owner.getNameCharArray(), candidates); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java index 8d1842259e7..8b8ec43a81c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java @@ -92,7 +92,7 @@ public class CPPFunctionSet implements ICPPTwoPhaseBinding { public void setToUnknown() { if (fName != null) { - fName.setBinding(new CPPDeferredFunction(null, fName.toCharArray())); + fName.setBinding(new CPPDeferredFunction(null, fName.toCharArray(), fBindings)); } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 247603215af..a447998e76e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -13,6 +13,7 @@ * Sergey Prigogin (Google) * Mike Kucera (IBM) * Thomas Corbat (IFS) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -451,7 +452,7 @@ public class CPPSemantics { final ASTNodeProperty namePropertyInParent = name.getPropertyInParent(); if (binding == null && data.skippedScope != null) { if (data.hasFunctionArguments()) { - binding= new CPPDeferredFunction(data.skippedScope, name.getSimpleID()); + binding= new CPPDeferredFunction(data.skippedScope, name.getSimpleID(), null); } else { if (namePropertyInParent == IASTNamedTypeSpecifier.NAME) { binding= new CPPUnknownMemberClass(data.skippedScope, name.getSimpleID()); @@ -2395,7 +2396,7 @@ public class CPPSemantics { if (viableCount == 1) return fns[0]; setTargetedFunctionsToUnknown(argTypes); - return CPPDeferredFunction.createForSample(fns[0]); + return CPPDeferredFunction.createForCandidates(fns); } IFunction[] ambiguousFunctions= null; // ambiguity, 2 functions are equally good @@ -2403,7 +2404,7 @@ public class CPPSemantics { // Loop over all functions List potentialCosts= null; - IFunction unknownFunction= null; + ICPPFunction unknownFunction= null; final CPPASTTranslationUnit tu = data.getTranslationUnit(); for (ICPPFunction fn : fns) { if (fn == null) @@ -2455,7 +2456,7 @@ public class CPPSemantics { return null; setTargetedFunctionsToUnknown(argTypes); - return CPPDeferredFunction.createForSample(unknownFunction); + return CPPDeferredFunction.createForCandidates(fns); } if (ambiguousFunctions != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 4d3afd83849..61f55dfe0fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -11,6 +11,7 @@ * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) * Thomas Corbat (IFS) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -163,7 +164,6 @@ public class CPPTemplates { static final int PACK_SIZE_DEFER = -1; static final int PACK_SIZE_FAIL = -2; static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; - private static final ICPPFunction[] NO_FUNCTIONS = {}; static enum TypeSelection { PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE } /** @@ -1750,18 +1750,12 @@ public class CPPTemplates { requireTemplate= false; if (func instanceof ICPPFunctionTemplate) { - ICPPFunctionTemplate template= (ICPPFunctionTemplate) func; - try { - if (containsDependentType(fnArgs)) - return new ICPPFunction[] {CPPDeferredFunction.createForSample(template)}; + if (containsDependentType(fnArgs)) + return new ICPPFunction[] {CPPDeferredFunction.createForCandidates(fns)}; + + if (requireTemplate && hasDependentArgument(tmplArgs)) + return new ICPPFunction[] {CPPDeferredFunction.createForCandidates(fns)}; - if (requireTemplate) { - if (hasDependentArgument(tmplArgs)) - return new ICPPFunction[] {CPPDeferredFunction.createForSample(template)}; - } - } catch (DOMException e) { - return NO_FUNCTIONS; - } haveTemplate= true; break; } @@ -1827,15 +1821,11 @@ public class CPPTemplates { // Extract template arguments and parameter types. if (!checkedForDependentType) { - try { - if (isDependentType(conversionType)) { - inst= CPPDeferredFunction.createForSample(template); - done= true; - } - checkedForDependentType= true; - } catch (DOMException e) { - return functions; + if (isDependentType(conversionType)) { + inst= CPPDeferredFunction.createForCandidates(functions); + done= true; } + checkedForDependentType= true; } CPPTemplateParameterMap map= new CPPTemplateParameterMap(1); try { @@ -1893,7 +1883,7 @@ public class CPPTemplates { ICPPTemplateArgument[] args, IASTNode point) { try { if (target != null && isDependentType(target)) { - return CPPDeferredFunction.createForSample(template); + return CPPDeferredFunction.createForCandidates(template); } if (template instanceof ICPPConstructor || args == null) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 4e47369eeae..8afc1bf3d89 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -11,6 +11,7 @@ * Andrew Ferguson (Symbian) * Sergey Prigogin (Google) * Thomas Corbat (IFS) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -2017,11 +2018,13 @@ public class CPPVisitor extends ASTQueries { IBinding b= implicits[0].getBinding(); CPPASTName name= new CPPASTName(); name.setBinding(b); + IASTInitializerClause[] beginCallArguments = new IASTInitializerClause[] { forInit.copy() }; if (b instanceof ICPPMethod && forInit instanceof IASTExpression) { beginExpr= new CPPASTFunctionCallExpression( - new CPPASTFieldReference(name, (IASTExpression) forInit.copy()), NO_ARGS); + new CPPASTFieldReference(name, (IASTExpression) forInit.copy()), + beginCallArguments); } else { - beginExpr= new CPPASTFunctionCallExpression(new CPPASTIdExpression(name), NO_ARGS); + beginExpr= new CPPASTFunctionCallExpression(new CPPASTIdExpression(name), beginCallArguments); } } else { return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java index ea60a5169fc..a4419e5c668 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -362,6 +363,13 @@ public class EvalBinding extends CPPEvaluation { binding = CPPTemplates.createSpecialization((ICPPClassSpecialization) owner, binding, point); } + } else if (binding instanceof ICPPParameter) { + ICPPParameter parameter = (ICPPParameter) binding; + IType originalType = parameter.getType(); + IType type = CPPTemplates.instantiateType(originalType, tpMap, packOffset, within, point); + if (originalType != type) { + return new EvalFixed(type, ValueCategory.LVALUE, Value.create(this)); + } } if (binding == fBinding) return this; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java index f202f82778f..60771fd3cfe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -23,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; @@ -145,12 +147,16 @@ public class EvalFunctionSet extends CPPEvaluation { ICPPClassSpecialization within, int maxdepth, IASTNode point) { ICPPTemplateArgument[] originalArguments = fFunctionSet.getTemplateArguments(); ICPPTemplateArgument[] arguments = originalArguments; - arguments = instantiateArguments(originalArguments, tpMap, packOffset, within, point); + if (originalArguments != null) + arguments = instantiateArguments(originalArguments, tpMap, packOffset, within, point); IBinding originalOwner = fFunctionSet.getOwner(); IBinding owner = originalOwner; - if (originalOwner instanceof ICPPUnknownBinding) { + if (owner instanceof ICPPUnknownBinding) { owner = resolveUnknown((ICPPUnknownBinding) owner, tpMap, packOffset, within, point); + } else if (owner instanceof ICPPClassTemplate) { + owner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) owner), + tpMap, packOffset, within, point); } else if (owner instanceof IType) { IType type = CPPTemplates.instantiateType((IType) owner, tpMap, packOffset, within, point); if (type instanceof IBinding) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 2f78b975479..74760703536 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -48,6 +49,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; @@ -184,15 +186,6 @@ public class EvalID extends CPPEvaluation { return new EvalFunctionSet((CPPFunctionSet) binding, isAddressOf(expr)); } if (binding instanceof ICPPUnknownBinding) { - IBinding owner = binding.getOwner(); - if (owner instanceof IProblemBinding) - return EvalFixed.INCOMPLETE; - - ICPPEvaluation fieldOwner= null; - IType fieldOwnerType= withinNonStaticMethod(expr); - if (fieldOwnerType != null) { - fieldOwner= new EvalFixed(fieldOwnerType, ValueCategory.LVALUE, Value.UNKNOWN); - } ICPPTemplateArgument[] templateArgs = null; final IASTName lastName = name.getLastName(); if (lastName instanceof ICPPASTTemplateId) { @@ -202,6 +195,25 @@ public class EvalID extends CPPEvaluation { return EvalFixed.INCOMPLETE; } } + + if (binding instanceof CPPDeferredFunction) { + CPPDeferredFunction deferredFunction = (CPPDeferredFunction) binding; + if (deferredFunction.getCandidates() != null) { + CPPFunctionSet functionSet = new CPPFunctionSet(deferredFunction.getCandidates(), templateArgs, null); + return new EvalFunctionSet(functionSet, isAddressOf(expr)); + } + } + + IBinding owner = binding.getOwner(); + if (owner instanceof IProblemBinding) + return EvalFixed.INCOMPLETE; + + ICPPEvaluation fieldOwner= null; + IType fieldOwnerType= withinNonStaticMethod(expr); + if (fieldOwnerType != null) { + fieldOwner= new EvalFixed(fieldOwnerType, ValueCategory.LVALUE, Value.UNKNOWN); + } + return new EvalID(fieldOwner, owner, name.getSimpleID(), isAddressOf(expr), name instanceof ICPPASTQualifiedName, templateArgs); } From fcd0216d66a632343ea9f9521b963bb2773bfc33 Mon Sep 17 00:00:00 2001 From: Ivan Ivanoff Date: Tue, 8 Jan 2013 09:24:14 -0500 Subject: [PATCH 22/23] bug 397546: NPE at org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderTab.updateData(LanguageSettingsProviderTab.java:1084) --- .../providers/LanguageSettingsProviderTab.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index d858baa05ed..bced35b4906 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -1081,11 +1081,13 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { return; ICConfigurationDescription cfgDescription = getConfigurationDescription(); - String cfgId = cfgDescription.getId(); - if (!initialProvidersByCfg.containsKey(cfgId)) { - if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - List initialProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); - initialProvidersByCfg.put(cfgId, initialProviders); + if (cfgDescription != null) { + String cfgId = cfgDescription.getId(); + if (!initialProvidersByCfg.containsKey(cfgId)) { + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List initialProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + initialProvidersByCfg.put(cfgId, initialProviders); + } } } From 33514e1c849b21f8a9be6e96668d13f51e434d48 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 8 Jan 2013 12:54:59 -0500 Subject: [PATCH 23/23] bug 396411: Resolve variables before checking if path is absolute in MBSLanguageSettingsProvider --- .../MBSLanguageSettingsProvider.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java index e529345df1d..3c66105c2ed 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java @@ -15,6 +15,9 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.AbstractExecutableExtensionBase; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.cdtvariables.CdtVariableException; +import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -26,6 +29,7 @@ import org.eclipse.cdt.core.settings.model.ICPathEntry; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.util.CDataUtil; +import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -73,12 +77,24 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase if (!new Path(pathStr).isAbsolute()) { // We need to add project-rooted entry for relative path as MBS counts it this way in some UI // The relative entry below also should be added for indexer to resolve from source file locations - IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager(); - String projectRootedPath = mngr.generateVariableExpression("workspace_loc", rc.getProject().getName()) + Path.SEPARATOR + pathStr; //$NON-NLS-1$ - ICLanguageSettingEntry projectRootedEntry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, projectRootedPath, projectRootedPath, null, entry.getFlags()); - if (! list.contains(projectRootedEntry)) { - list.add(projectRootedEntry); + + ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager(); + try { + // Substitute build/environment variables + String location = varManager.resolveValue(pathStr, "", null, cfgDescription); //$NON-NLS-1$ + if (!new Path(location).isAbsolute()) { + IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager(); + String projectRootedPath = mngr.generateVariableExpression("workspace_loc", rc.getProject().getName()) + Path.SEPARATOR + pathStr; //$NON-NLS-1$ + ICLanguageSettingEntry projectRootedEntry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, projectRootedPath, projectRootedPath, null, entry.getFlags()); + if (! list.contains(projectRootedEntry)) { + list.add(projectRootedEntry); + } + } + } catch (CdtVariableException e) { + // Swallow exceptions but also log them + ManagedBuilderCorePlugin.log(e); } + } } if (! list.contains(entry)) {