Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] patches to AST and refactoring

ast-parser-patch... fixes an endless while loop
refactoring...      fixes problems found by myself during testing, 
                    additional testcases

Markus.
Index: parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java,v
retrieving revision 1.45
diff -u -r1.45 LocationMap.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java	4 May 2005 15:28:21 -0000	1.45
+++ parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java	10 May 2005 15:45:22 -0000
@@ -1758,7 +1758,7 @@
             {
                 _CompositeContext parent = c.parent;
                 while (!(parent instanceof _CompositeFileContext))
-                    parent = c.parent;
+                    parent = parent.parent;
                 _CompositeFileContext fc = (_CompositeFileContext) parent;
                 return new FileLocation(fc.reader.filename, reconcileOffset(fc,
                         c, offset), length);                
Index: src/org/eclipse/cdt/internal/refactoring/ASTManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/ASTManager.java,v
retrieving revision 1.5
diff -u -r1.5 ASTManager.java
--- src/org/eclipse/cdt/internal/refactoring/ASTManager.java	22 Apr 2005 17:10:09 -0000	1.5
+++ src/org/eclipse/cdt/internal/refactoring/ASTManager.java	10 May 2005 15:45:23 -0000
@@ -18,6 +18,7 @@
 import org.eclipse.cdt.core.dom.ast.*;
 import org.eclipse.cdt.core.dom.ast.c.*;
 import org.eclipse.cdt.core.dom.ast.cpp.*;
+import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
 import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
@@ -46,6 +47,32 @@
     private HashSet fEqualToValidBinding;
     private HashSet fConflictingBinding;
 
+    public static String nth_of_m(int n, int m) {
+        StringBuffer nofm= new StringBuffer();
+        append_nth_of_m(n, m, nofm);
+        return nofm.toString();
+    }
+
+    static void append_nth_of_m(int n, int m, StringBuffer buf) {
+        buf.append(n);
+        switch(n) {
+            case 1:
+                buf.append("st"); //$NON-NLS-1$
+                break;
+            case 2:
+                buf.append("nd"); //$NON-NLS-1$
+                break;
+            case 3:
+                buf.append("rd"); //$NON-NLS-1$
+                break;
+            default:
+                buf.append("th"); //$NON-NLS-1$
+                break;
+        }
+        buf.append(" of "); //$NON-NLS-1$
+        buf.append(m);
+    }
+    
     public static IASTFileLocation getLocationInTranslationUnit(IASTNode node) {
         return node.getTranslationUnit().flattenLocationsToFile(
                 node.getNodeLocations());
@@ -95,23 +122,31 @@
             if (!(b2 instanceof IFunction)) {
                 return FALSE;
             }
+            boolean isStatic= false;
+            boolean checkSig= true;
             IFunction c1= (IFunction) b1;
             IFunction c2= (IFunction) b2;
-            boolean fileStatic= false;
             if (b1 instanceof ICPPMethod) {
                 if (!(b2 instanceof ICPPMethod)) {
                     return FALSE;
                 }
             }
             else {
-                fileStatic= c1.isStatic() || c2.isStatic();
+                if (b2 instanceof ICPPMethod) {
+                    return FALSE;
+                }
+                isStatic= c1.isStatic() || c2.isStatic();
+                if (!(b1 instanceof ICPPFunction) && !(b2 instanceof ICPPFunction)) {
+                    checkSig= false;
+                }
             }
-            int r1= isSameScope(b1.getScope(), b2.getScope(), fileStatic);
+            
+            int r1= isSameScope(b1.getScope(), b2.getScope(), isStatic);
             if (r1 == FALSE) {
                 return FALSE;
             }
             
-            int r2= hasSameSignature(c1, c2);
+            int r2= checkSig ? hasSameSignature(c1, c2) : TRUE;
             if (r2 == FALSE) {
                 return FALSE;
             }
@@ -120,14 +155,15 @@
             }
             return r1;
         }
-
+        
         if (b1 instanceof IVariable) {
-            IVariable c1= (IVariable) b1;
-            IVariable c2= (IVariable) b2;
             boolean fileStatic= false;
             if (!(b2 instanceof IVariable)) {
                 return FALSE;
             }
+
+            IVariable c1= (IVariable) b1;
+            IVariable c2= (IVariable) b2;
             if (b1 instanceof IField) {
                 if (!(b2 instanceof IField)) {
                     return FALSE;
@@ -148,10 +184,37 @@
             return result == UNKNOWN ? TRUE : result;
         }
 
-        if (!b1.getClass().equals(b2.getClass())) {
-            return FALSE;
+        if (b1 instanceof IEnumerator) {
+            if (!(b2 instanceof IEnumerator)) {
+                return FALSE;
+            }
+            return isSameScope(b1.getScope(), b2.getScope(), false);
         }
-        return isSameScope(b1.getScope(), b2.getScope(), false);
+        
+        if (b1 instanceof ITypedef) {
+            if (!(b2 instanceof ITypedef)) {
+                return FALSE;
+            }
+            return isSameScope(b1.getScope(), b2.getScope(), false);
+        }
+        
+        if (b1 instanceof IMacroBinding) {
+            if (!(b2 instanceof IMacroBinding)) {
+                return FALSE;
+            }
+            IMacroBinding m1= (IMacroBinding) b1;
+            IMacroBinding m2= (IMacroBinding) b2;
+            return isSameScope(m1.getScope(), m2.getScope(), true);
+        }
+        int scopeCmp= isSameScope(b1.getScope(), b2.getScope(), false);
+        if (scopeCmp != TRUE) {
+            return scopeCmp;
+        }
+        
+        if (b1.getClass().equals(b2.getClass())) {
+            return TRUE;
+        }
+        return UNKNOWN;
     }
     
     public static int isSameScope(IScope s1, IScope s2, boolean fileStatic) throws DOMException {
@@ -165,15 +228,22 @@
         if (s1.equals(s2)) {
             return TRUE;
         }
+
+        
+        IASTNode node1= s1.getPhysicalNode();
+        IASTNode node2= s2.getPhysicalNode();
+
+        if (node1 instanceof IASTTranslationUnit &&
+                node2 instanceof IASTTranslationUnit) {
+            return hasSameLocation(node1, node2, fileStatic);
+        }
         
         String name1= getName(s1);
         String name2= getName(s2);
         
         if (s1 instanceof ICPPBlockScope) {
             if (s2 instanceof ICPPBlockScope) {
-                ICPPBlockScope b1= (ICPPBlockScope) s1;
-                ICPPBlockScope b2= (ICPPBlockScope) s2;
-                return hasSameLocation(b1, b2, fileStatic);
+                return hasSameLocation(node1, node2, fileStatic);
             }
             return FALSE;
         }
@@ -181,7 +251,7 @@
             if (s2 instanceof ICPPNamespaceScope) {
                 ICPPNamespaceScope n1= (ICPPNamespaceScope) s1;
                 ICPPNamespaceScope n2= (ICPPNamespaceScope) s2;
-                int r1= hasSameLocation(n1, n2, fileStatic);
+                int r1= hasSameLocation(node1, node2, fileStatic);
                 if (r1 == TRUE) {
                     return r1;
                 }
@@ -198,27 +268,23 @@
         }
 
         // classes
-        if (s1 instanceof ICPPClassScope) {
-            if (s2 instanceof ICPPClassScope) {
-                return isSameScope(s1.getParent(), s2.getParent(), fileStatic);
-            }
-            return FALSE;
-        }
-        if (s1 instanceof ICCompositeTypeScope) {
-            if (s2 instanceof ICCompositeTypeScope) {
+        if (s1 instanceof ICPPClassScope || s1 instanceof ICCompositeTypeScope) {
+            if (s2 instanceof ICPPClassScope || s2 instanceof ICCompositeTypeScope) {
                 return isSameScope(s1.getParent(), s2.getParent(), fileStatic);
             }
             return FALSE;
         }
         if (s1 instanceof ICPPFunctionScope) {
             if (s2 instanceof ICPPFunctionScope) {
-                return hasSameLocation(s1, s2, true);
+                return hasSameLocation(node1, node2, true);
             }
             return FALSE;
         }
-        if (s1 instanceof ICFunctionScope || s1 instanceof ICFunctionPrototypeScope) {
-            if (s2 instanceof ICFunctionScope || s2 instanceof ICFunctionPrototypeScope) {
-                return hasSameLocation(s1, s2, true);
+        if (s1 instanceof ICFunctionScope || s1 instanceof ICFunctionPrototypeScope
+                || s1 instanceof ICScope) {
+            if (s2 instanceof ICFunctionScope || s2 instanceof ICFunctionPrototypeScope
+                    || s2 instanceof ICScope) {
+                return hasSameLocation(node1, node2, true);
             }
             return FALSE;
         }
@@ -470,10 +536,7 @@
         return null;
     }
 
-    private static int hasSameLocation(IScope s1, IScope s2, boolean fileStatic) throws DOMException {
-        IASTNode node1= s1.getPhysicalNode();
-        IASTNode node2= s2.getPhysicalNode();
-
+    private static int hasSameLocation(IASTNode node1, IASTNode node2, boolean fileStatic) throws DOMException {
         if (node1 == null || node2 == null) {
             return UNKNOWN;
         }
@@ -712,6 +775,8 @@
             return;
         }
         
+        SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
+        
         pm.beginTask(Messages.getString("ASTManager.task.analyze"), 2); //$NON-NLS-1$
         IASTTranslationUnit tu= getTranslationUnit(fArgument.getSourceFile(), true, status);
         pm.worked(1);
@@ -784,20 +849,55 @@
             store.addMatch(match);
         }
         
-        monitor.beginTask(Messages.getString("ASTManager.task.generateAst"), //$NON-NLS-1$ 
-                2*store.getFileCount()); 
+        int count= store.getFileCount();
+        String taskName= Messages.getString("ASTManager.task.generateAst"); //$NON-NLS-1$
+        monitor.beginTask(taskName, 2*count);
+        monitor.setTaskName(taskName);
 
         List files= store.getFileList();
+        int cc= 0;
+        long now= System.currentTimeMillis();
+        long update= now;
         for (Iterator iter = files.iterator(); iter.hasNext();) {
+            cc++;
             IFile file = (IFile) iter.next();
             if (store.contains(file)) {
-                IASTTranslationUnit tu= getTranslationUnit(file, false, status);
-                monitor.worked(1);
-                analyzeTextMatchesOfTranslationUnit(tu, store, status);
-                if (status.hasFatalError()) {
-                    return;
+                if ((now=System.currentTimeMillis()) > update) {
+                    String nofm= nth_of_m(cc, count);
+                    String taskname= MessageFormat.format(Messages.getString("ASTManager.subtask.analyzing"),   //$NON-NLS-1$
+                            new Object[] {nofm});
+                    monitor.subTask(taskname); //$NON-NLS-1$
+                    update= now+1000;
+                }
+                boolean doParse= false;
+                Collection fm= store.getMatchesForFile(file);
+                for (Iterator iterator = fm.iterator(); !doParse && iterator.hasNext();) {
+                    CRefactoringMatch match = (CRefactoringMatch) iterator.next();
+                    switch (match.getLocation()) {
+                    case CRefactory.OPTION_IN_COMMENT:
+                    case CRefactory.OPTION_IN_INCLUDE_DIRECTIVE:
+                    case CRefactory.OPTION_IN_STRING_LITERAL:
+                        break;
+                    default:
+                        doParse= true;
+                    }
+                }
+
+                if (doParse) {
+                    IASTTranslationUnit tu= getTranslationUnit(file, false, status);
+                    monitor.worked(1);
+                    analyzeTextMatchesOfTranslationUnit(tu, store, status);
+                    if (status.hasFatalError()) {
+                        return;
+                    }
+                    monitor.worked(1);
+                }
+                else {
+                    monitor.worked(2);
+                }
+                if (monitor.isCanceled()) {
+                    throw new OperationCanceledException();
                 }
-                monitor.worked(1);
             }
             else {
                 monitor.worked(2);
@@ -819,9 +919,8 @@
         if (fArgument.getArgumentKind() == CRefactory.ARGUMENT_MACRO) {
             analyzeRenameToMatches(tu, store, paths, status);
         }
-        else {
-            analyzeLanguageMatches(tu, store, paths, status);
-        }
+
+        analyzeLanguageMatches(tu, store, paths, status);
 
         for (Iterator iter = paths.iterator(); iter.hasNext();) {
             IPath path = (IPath) iter.next();
@@ -865,11 +964,40 @@
             else if (lookfor.equals(macroNameStr)) {
                 IPath path= analyzeAstMatch(macroName, store, false, status);
                 pathsVisited.add(path);
-    
-                IASTName[] refs= tu.getReferences(macroName.getBinding());
-                for (int j = 0; j < refs.length; j++) {
-                    path= analyzeAstMatch(refs[j], store, false, status);
-                    pathsVisited.add(path);
+                IBinding macroBinding= macroName.getBinding();
+                if (macroBinding != null) {
+                    IASTName[] refs= tu.getReferences(macroBinding);
+                    for (int j = 0; j < refs.length; j++) {
+                        path= analyzeAstMatch(refs[j], store, false, status);
+                        pathsVisited.add(path);
+                    }
+                }
+            }
+            if (mdef instanceof IASTPreprocessorFunctionStyleMacroDefinition) {
+                boolean nameIsPar= false;
+                IASTPreprocessorFunctionStyleMacroDefinition fm= (IASTPreprocessorFunctionStyleMacroDefinition) mdef;
+                IASTFunctionStyleMacroParameter[] pars= fm.getParameters();
+                if (pars != null) {
+                    for (int j = 0; !nameIsPar && j<pars.length; j++) {
+                        IASTFunctionStyleMacroParameter par = pars[j];
+                        String name= par.getParameter();
+                        if (lookfor.equals(name)) {
+                            nameIsPar= true;
+                        }
+                    }
+                    if (nameIsPar) {
+                        IASTFileLocation floc= mdef.getNodeLocations()[0].asFileLocation();
+                        int offset= floc.getNodeOffset();
+                        int end= offset+ floc.getNodeLength();
+                        Collection matches= store.getMatchesForPath(new Path(floc.getFileName()));
+                        for (Iterator iter = matches.iterator(); iter.hasNext();) {
+                            CRefactoringMatch match = (CRefactoringMatch) iter.next();
+                            int mo= match.getOffset();
+                            if (mo>=offset && mo<end) {
+                                match.setASTInformation(CRefactoringMatch.AST_REFERENCE_OTHER);
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -922,15 +1050,13 @@
             IASTFileLocation floc= loc.asFileLocation();
             if (floc != null) {
                 path= new Path(floc.getFileName());
-                if (path != null) {
+                if (loc instanceof IASTMacroExpansion) {
+                    IASTMacroExpansion me= (IASTMacroExpansion) loc;
+                    int offset= backrelateNameToMacroCallArgument(name, me);
+                    match= store.findMatch(path, offset + (isDestructor ? 1 : 0));
+                }
+                else {
                     match= store.findMatch(path, floc.getNodeOffset() + (isDestructor ? 1 : 0));
-                    // bug 90978 IASTMacroExpansions should be handled right away,
-                    // as a workaround look with fileOffset first.
-                    if (match==null && loc instanceof IASTMacroExpansion) {
-                        IASTMacroExpansion me= (IASTMacroExpansion) loc;
-                        int offset= backrelateNameToMacroCallArgument(name, me);
-                        match= store.findMatch(path, offset + (isDestructor ? 1 : 0));
-                    }
                 }
             }
         }
@@ -1002,9 +1128,16 @@
     public void handleProblemBinding(IASTTranslationUnit tu, final IProblemBinding pb, RefactoringStatus status) {
         if (tu != null) {
             if (fProblemUnits.add(tu.getFilePath())) {
-                status.addWarning(MessageFormat.format(
-                        Messages.getString("ASTManager.warning.parsingErrors"), //$NON-NLS-1$
-                        new Object[] {tu.getFilePath()}));
+                String msg= pb.getMessage();
+                if (msg != null && msg.length() > 0) {
+                    msg= MessageFormat.format(Messages.getString("ASTManager.warning.parsingErrors.detailed"), new Object[]{msg}); //$NON-NLS-1$
+                }
+                else {
+                    msg= MessageFormat.format(
+                            Messages.getString("ASTManager.warning.parsingErrors"), //$NON-NLS-1$
+                            new Object[] {tu.getFilePath()});
+                }
+                status.addWarning(msg);
             }
         }
     }
Index: src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java,v
retrieving revision 1.2
diff -u -r1.2 ASTNameVisitor.java
--- src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java	15 Apr 2005 13:55:27 -0000	1.2
+++ src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java	10 May 2005 15:45:23 -0000
@@ -95,18 +95,11 @@
         int off= floc.getNodeOffset();
         int len = floc.getNodeLength();
         if (locs[0] instanceof IASTMacroExpansion && node instanceof IASTName) {
-            // workaround bug 90978
-            IASTMacroExpansion me= (IASTMacroExpansion) locs[0];
-            if (node.toString().equals(me.getMacroDefinition().getName().toString())) {
-                // stick to the file-location
-            }
-            else {
-                IASTName name= (IASTName) node;
-                off= 
-                    ASTManager.backrelateNameToMacroCallArgument(name, 
-                            (IASTMacroExpansion) locs[0]);
-                len= name.toCharArray().length;
-            }
+            IASTName name= (IASTName) node;
+            off= 
+                ASTManager.backrelateNameToMacroCallArgument(name, 
+                        (IASTMacroExpansion) locs[0]);
+            len= name.toCharArray().length;
         }
         return off <= fOffset && fOffset < off+len;
     }
Index: src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java,v
retrieving revision 1.2
diff -u -r1.2 CRefactoringMatchStore.java
--- src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java	22 Apr 2005 17:10:09 -0000	1.2
+++ src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java	10 May 2005 15:45:23 -0000
@@ -34,12 +34,12 @@
     public void addMatch(CRefactoringMatch match) {
         IPath path= resolvePath(match.getFile());
         if (path != null) {
-            Map matchesForPath= getMatchesForPath(path, true);
+            Map matchesForPath= getMapForPath(path, true);
             matchesForPath.put(match, match);
         }
     }
-
-    private Map getMatchesForPath(IPath path, boolean create) {
+        
+    private Map getMapForPath(IPath path, boolean create) {
         Map map= (Map) fPathToMatches.get(path);
         if (map == null && create) {
             map= new TreeMap(fOffsetComparator);
@@ -72,6 +72,20 @@
         return fFileToPathMap.containsKey(file);
     }
 
+    public Collection getMatchesForFile(IFile file) {
+        return getMatchesForPath((IPath) fFileToPathMap.get(file));
+    }
+
+    public Collection getMatchesForPath(IPath path) {
+        if (path != null) {
+            Map map= (Map) fPathToMatches.get(path);
+            if (map != null) {
+                return map.keySet();
+            }
+        }
+        return Collections.EMPTY_LIST;
+    }
+
     public CRefactoringMatch findMatch(IPath path, int nodeOffset) {
         Map map= (Map) fPathToMatches.get(path);
         if (map != null) {
Index: src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java,v
retrieving revision 1.2
diff -u -r1.2 CRenameTextProcessor.java
--- src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java	15 Apr 2005 13:55:27 -0000	1.2
+++ src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java	10 May 2005 15:45:23 -0000
@@ -172,9 +172,6 @@
                 continue;
             case CRefactoringMatch.IN_COMMENT:
             case CRefactoringMatch.POTENTIAL:
-                if (getManager().getDisablePotentialMatches()) {
-                    continue;
-                }
                 break;
             case CRefactoringMatch.AST_REFERENCE:
                 break;
Index: src/org/eclipse/cdt/internal/refactoring/messages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/messages.properties,v
retrieving revision 1.3
diff -u -r1.3 messages.properties
--- src/org/eclipse/cdt/internal/refactoring/messages.properties	22 Apr 2005 17:10:09 -0000	1.3
+++ src/org/eclipse/cdt/internal/refactoring/messages.properties	10 May 2005 15:45:23 -0000
@@ -74,5 +74,7 @@
 CRenameRefactoringInputPage.label.updateWithin=Update within:
 ASTManager.task.analyze=Analyzing source code
 ASTManager.task.generateAst=Generating AST
-ASTManager.warning.parsingErrors=There are parsing errors in file ''{0}'', the refactoring may not be accurate.
+ASTManager.subtask.analyzing=Analyzing {0} files
+ASTManager.warning.parsingErrors=Parsing error in file ''{0}'', the refactoring may not be accurate.
+ASTManager.warning.parsingErrors.detailed=Parsing Error: {0}
 ASTManager.error.macro.name.conflict=''{0}'' conflicts with the name of an existing macro\!
Index: src/org/eclipse/cdt/internal/refactoring/scanner/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/scanner/Scanner.java,v
retrieving revision 1.2
diff -u -r1.2 Scanner.java
--- src/org/eclipse/cdt/internal/refactoring/scanner/Scanner.java	15 Apr 2005 13:55:27 -0000	1.2
+++ src/org/eclipse/cdt/internal/refactoring/scanner/Scanner.java	10 May 2005 15:45:24 -0000
@@ -316,26 +316,7 @@
 
                 switch (c) {
                 case '\'':
-                    c = getChar(true);
-                    int next = getChar(true);
-                    if (c == '\\') {
-                        if (next >= '0' && next <= '7') {
-                            do {
-                                next = getChar(true);
-                            } while (next >= '0' && next <= '7');
-                        } else if (next == 'x' || next == 'X' || next == 'u' || next == 'U') {
-                            do {
-                                next = getChar(true);
-                            } while ((next >= '0' && next <= '9') || (next >= 'a' && next <= 'f')
-                                || (next >= 'A' && next <= 'F'));
-                        } else {
-                            next = getChar(true);
-                        }
-                    }
-                    if (next == '\'') {
-                        return newToken(Token.tCHAR);
-                    }
-                    ungetChar(next);
+					matchCharLiteral();
                     return newToken(Token.tCHAR);
 
 
@@ -550,6 +531,29 @@
         return null;
     }
 
+    private void matchCharLiteral() {
+        int c;
+        c = getChar(true);
+        int next = getChar(true);
+        if (c == '\\') {
+        	if (next >= '0' && next <= '7') {
+        		do {
+        			next = getChar(true);
+        		} while (next >= '0' && next <= '7');
+        	} else if (next == 'x' || next == 'X' || next == 'u' || next == 'U') {
+        		do {
+        			next = getChar(true);
+        		} while ((next >= '0' && next <= '9') || (next >= 'a' && next <= 'f')
+        			|| (next >= 'A' && next <= 'F'));
+        	} else {
+        		next = getChar(true);
+        	}
+        }
+        if (next != '\'') {
+            ungetChar(next);
+        }
+    }
+
     private void matchStringLiteral() {
         // string
         boolean escaped= false;
@@ -602,6 +606,17 @@
         boolean done= false;
         while (!done) {
             switch(c) {
+                case '\'':
+                    if (fTokenBuffer.length() > 1) {
+                        if (fPreprocessorToken==0) {
+                            fPreprocessorToken= categorizePreprocessor(fTokenBuffer);
+                        }
+                        ungetChar(c);
+                        return newPreprocessorToken();
+                    }
+                    matchCharLiteral();
+                    return newToken(Token.tCHAR);
+                        
                 case '"': 
                     if (fTokenBuffer.length() > 1) {
                         if (fPreprocessorToken==0) {
Index: src/org/eclipse/cdt/refactoring/CRefactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/refactoring/CRefactory.java,v
retrieving revision 1.3
diff -u -r1.3 CRefactory.java
--- src/org/eclipse/cdt/refactoring/CRefactory.java	22 Apr 2005 17:10:09 -0000	1.3
+++ src/org/eclipse/cdt/refactoring/CRefactory.java	10 May 2005 15:45:24 -0000
@@ -63,7 +63,6 @@
     
     private static CRefactory sInstance= new CRefactory();
     private HashSet fEditorIDs= new HashSet();
-    private boolean fDisablePotentialMatches= false;
     private ICRefactoringSearch fTextSearch;
     private String[] fAffectedProjectNatures;
     private IParserConfigurationProvider[] fParserConfigurationProviders= new IParserConfigurationProvider[0];
@@ -189,14 +188,6 @@
         now.addAll(Arrays.asList(fParserConfigurationProviders));
         now.add(pcp);
         fParserConfigurationProviders= 
-            (IParserConfigurationProvider[]) now.toArray(new String[now.size()]);
+            (IParserConfigurationProvider[]) now.toArray(new IParserConfigurationProvider[now.size()]);
     }
-
-    public void setDisablePotentialMatches(boolean val) {
-        fDisablePotentialMatches= val;
-    }
-    
-    public boolean getDisablePotentialMatches() {
-        return fDisablePotentialMatches;
-    }    
 }
Index: src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java,v
retrieving revision 1.3
diff -u -r1.3 RefactoringTests.java
--- src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java	25 Apr 2005 16:01:24 -0000	1.3
+++ src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java	10 May 2005 15:47:43 -0000
@@ -15,7 +15,6 @@
 
 import org.eclipse.cdt.core.tests.BaseTestFramework;
 import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
-import org.eclipse.cdt.refactoring.CRefactory;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.ltk.core.refactoring.*;
 import org.eclipse.text.edits.*;
@@ -35,7 +34,6 @@
     protected void setUp() throws Exception {
         super.setUp();
         disableIndexing();
-        CRefactory.getInstance().setDisablePotentialMatches(true);
     }
 
     protected void tearDown() throws Exception {
@@ -44,30 +42,45 @@
     }
 
     protected void assertTotalChanges(int numChanges, Change changes) throws Exception {
-        int count = 0;
-        if( changes != null )
-            count = countChanges( changes );
-        assertEquals( numChanges, count );
+        assertTotalChanges(numChanges, 0, changes);
     }
 
-    private int countChanges(Change change) {
-        int count = 0;
+    protected void assertTotalChanges(int numChanges, int potChanges, Change changes) throws Exception {
+        int count[]= {0,0};
+        if( changes != null ) {
+            countChanges( changes, count);
+        }
+        assertEquals( numChanges, count[0] );
+        assertEquals("potential changes: ", potChanges, count[1]); //$NON-NLS-1$
+    }
+
+    private void countChanges(Change change, int[] count) {
         if( change instanceof CompositeChange ){
             Change [] children = ((CompositeChange) change).getChildren();
             for( int i = 0; i < children.length; i++ ){
-                count += countChanges( children[i] );
+                countChanges( children[i], count);
             }
         } else if( change instanceof TextFileChange ){
-            count += countEdits( ((TextFileChange) change).getEdit() );
+            TextFileChange tfc= (TextFileChange) change;
+            TextEditChangeGroup[] tecgs= tfc.getTextEditChangeGroups();
+            for (int i = 0; i < tecgs.length; i++) {
+                TextEditChangeGroup group = tecgs[i];
+                countChanges(group, count);
+            }
         }
-        return count;
     }
 
-    private int countEdits(TextEdit edit) {
-        if( edit instanceof MultiTextEdit ){
-            return ((MultiTextEdit) edit).getChildrenSize();
-        } 
-        return 1;
+    private void countChanges(TextEditChangeGroup edit, int[] count) {
+        String name= edit.getName();
+        if (name.indexOf("potential") != -1) { //$NON-NLS-1$
+            count[1]++;
+        }
+        else if (name.indexOf("comment") != -1) { //$NON-NLS-1$
+            count[1]++;
+        }
+        else {
+            count[0]++;
+        }
     }
 
     protected void assertChange(Change changes, IFile file, int startOffset, int numChars, String newText) throws Exception {
Index: src/org/eclipse/cdt/refactoring/tests/RenameFunctionTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameFunctionTests.java,v
retrieving revision 1.2
diff -u -r1.2 RenameFunctionTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameFunctionTests.java	27 Apr 2005 19:29:32 -0000	1.2
+++ src/org/eclipse/cdt/refactoring/tests/RenameFunctionTests.java	10 May 2005 15:47:45 -0000
@@ -17,6 +17,7 @@
 import junit.framework.TestSuite;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
 
 /**
@@ -33,6 +34,7 @@
     public static Test suite( boolean cleanup ) {
         TestSuite suite = new TestSuite("RenameFunctionTests"); //$NON-NLS-1$
         suite.addTest(new RenameFunctionTests("testFunctionNameConflicts") ); //$NON-NLS-1$
+        suite.addTest(new RenameFunctionTests("testFunctionsPlainC") ); //$NON-NLS-1$
         suite.addTest(new RenameFunctionTests("testFunctionNameConflictsPlainC") ); //$NON-NLS-1$
         suite.addTest(new RenameFunctionTests("testMethodNameConflicts1") ); //$NON-NLS-1$
         suite.addTest(new RenameFunctionTests("testMethodNameConflicts2") ); //$NON-NLS-1$
@@ -250,6 +252,30 @@
         assertRefactoringOk(status); 
     }
     
+    public void testFunctionsPlainC() throws Exception {
+        createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+        createCDefs("c_def.h"); //$NON-NLS-1$
+        StringWriter writer = new StringWriter();
+        writer.write("#include \"c_fwd.h\"   \n"); //$NON-NLS-1$
+        writer.write("#include \"c_def.h\"   \n"); //$NON-NLS-1$
+        writer.write("int v1(); int v2(); int v3();  \n"); //$NON-NLS-1$
+        writer.write("int func_proto();         \n"); //$NON-NLS-1$
+        writer.write("static int s2();          \n"); //$NON-NLS-1$
+        writer.write("void func_def(){         \n"); //$NON-NLS-1$
+        writer.write("     int w1; v1();        \n"); //$NON-NLS-1$
+        writer.write("}                         \n"); //$NON-NLS-1$
+        String contents = writer.toString();
+        IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
+        
+        int offset1= contents.indexOf("func_proto"); //$NON-NLS-1$
+        Change change= getRefactorChanges(cpp, offset1, "xxx");  //$NON-NLS-1$
+        assertTotalChanges(2, change);
+
+        offset1= contents.indexOf("func_def"); //$NON-NLS-1$
+        change= getRefactorChanges(cpp, offset1, "xxx");  //$NON-NLS-1$
+        assertTotalChanges(2, change);
+    }
+        
 
     public void testFunctionNameConflictsPlainC() throws Exception {
         createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
Index: src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java,v
retrieving revision 1.1
diff -u -r1.1 RenameMacroTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java	15 Apr 2005 13:55:35 -0000	1.1
+++ src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java	10 May 2005 15:47:45 -0000
@@ -36,6 +36,7 @@
         suite.addTest(new RenameMacroTests("testMacroRename") ); //$NON-NLS-1$
         suite.addTest(new RenameMacroTests("testMacroNameConflicts") ); //$NON-NLS-1$
         suite.addTest(new RenameMacroTests("testIncludeGuard"));  //$NON-NLS-1$
+        suite.addTest(new RenameMacroTests("testClassMacroClash"));  //$NON-NLS-1$
 
         if (cleanup) {
             suite.addTest( new RefactoringTests("cleanupProject") );    //$NON-NLS-1$
@@ -155,10 +156,31 @@
         int offset2= contents.indexOf("_guard", offset1+1); //$NON-NLS-1$
         Change ch= getRefactorChanges(cpp, offset2, "WELT");  //$NON-NLS-1$
         // mstodo for now the match within the ifndef is reported as potential.
-        assertTotalChanges(1, ch);
+        assertTotalChanges(1, 2, ch);
         int off= offset1;
 //        assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$
         off= contents.indexOf("_guard", off+1); //$NON-NLS-1$
         assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$
     }
+
+    public void testClassMacroClash() throws Exception {
+        StringWriter writer = new StringWriter();
+        writer.write("class CC {int a;};         \n"); //$NON-NLS-1$
+        String contents = writer.toString();
+        IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+        writer = new StringWriter();
+        writer.write("#define CC mm              \n"); //$NON-NLS-1$
+        writer.write("int CC;                   \n"); //$NON-NLS-1$
+        String contents2 = writer.toString();
+        IFile cpp2= importFile("test2.cpp", contents2 ); //$NON-NLS-1$
+
+        int offset1= contents.indexOf("CC"); //$NON-NLS-1$
+        Change ch= getRefactorChanges(cpp, offset1, "CCC");  //$NON-NLS-1$
+        assertTotalChanges(1, ch);
+
+        int offset2= contents2.indexOf("CC"); //$NON-NLS-1$
+        ch= getRefactorChanges(cpp2, offset2, "CCC");  //$NON-NLS-1$
+        assertTotalChanges(2, ch);
+    }
 }
Index: src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java,v
retrieving revision 1.3
diff -u -r1.3 RenameRegressionTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java	15 Apr 2005 13:55:35 -0000	1.3
+++ src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java	10 May 2005 15:47:48 -0000
@@ -121,7 +121,7 @@
         IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
         Change changes = getRefactorChanges( file, contents.indexOf( "boo" ), "ooga" ); //$NON-NLS-1$ //$NON-NLS-2$
         
-        assertTotalChanges( 2, changes );
+        assertTotalChanges( 2, 2, changes );
         assertChange( changes, file, contents.indexOf("boo"), 3, "ooga" );  //$NON-NLS-1$//$NON-NLS-2$
         assertChange( changes, file, contents.indexOf("boo++"), 3, "ooga" );  //$NON-NLS-1$//$NON-NLS-2$
     }
Index: src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java,v
retrieving revision 1.2
diff -u -r1.2 RenameVariableTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java	15 Apr 2005 13:55:35 -0000	1.2
+++ src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java	10 May 2005 15:47:51 -0000
@@ -45,7 +45,7 @@
         suite.addTest(new RenameVariableTests("testMemberNameConflicts1") ); //$NON-NLS-1$
         suite.addTest(new RenameVariableTests("testMemberNameConflicts2") ); //$NON-NLS-1$
 
-        suite.addTest(new RenameVariableTests("testReferenceViaMacro1") ); //$NON-NLS-1$
+        suite.addTest(new RenameVariableTests("testReferenceViaMacro") ); //$NON-NLS-1$
         suite.addTest(new RenameVariableTests("testReferenceViaMacro2") ); //$NON-NLS-1$
         suite.addTest(new FailingTest(new RenameVariableTests("testReferenceViaMacro3"), 90956) ); //$NON-NLS-1$
         suite.addTest(new RenameVariableTests("testReferenceViaMacro4") ); //$NON-NLS-1$
@@ -1355,7 +1355,7 @@
         assertRefactoringOk(status);
     }
     
-    public void testReferenceViaMacro1() throws Exception {
+    public void testReferenceViaMacro() throws Exception {
         StringWriter writer = new StringWriter();
         writer.write("#define PASSON(x) (x)         \n"); //$NON-NLS-1$
         writer.write("#define INC(x) PASSON(/*pc*/x)++         \n"); //$NON-NLS-1$
@@ -1424,7 +1424,7 @@
         
         int offset =  contents.indexOf("v1") ; //$NON-NLS-1$
         Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
-        assertTotalChanges( 1, changes );
+        assertTotalChanges( 1, 1, changes );
         assertChange( changes, cpp, offset, 2, "z" );  //$NON-NLS-1$
     }
 

Back to the top