mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 06:55:23 +02:00
modified patch from Devin Steffler, bugs 86868, 95635, 95786
This commit is contained in:
parent
5be4c3e645
commit
30b6f0e0af
6 changed files with 2175 additions and 65 deletions
|
@ -4345,6 +4345,36 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( str, col.getName(9).resolveBinding() );
|
||||
}
|
||||
|
||||
public void testBug95786() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void f() {\n"); //$NON-NLS-1$
|
||||
buffer.append("char * value;\n"); //$NON-NLS-1$
|
||||
buffer.append("::operator delete(value);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
assertFalse( col.getName(2).resolveBinding() instanceof IProblemBinding);
|
||||
}
|
||||
|
||||
public void testBug86868() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int foo()\n"); //$NON-NLS-1$
|
||||
buffer.append("try\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("// function body\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("catch (...)\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
assertEquals(tu.getDeclarations().length, 1);
|
||||
}
|
||||
|
||||
public void testBug94779() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "void f( int t ){\n" );
|
||||
|
|
|
@ -288,5 +288,88 @@ public class GCCCompleteParseExtensionsTest extends AST2BaseTest {
|
|||
assertFalse(true);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
public void testBug95635() throws Exception{
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("void f(){ \n");//$NON-NLS-1$
|
||||
writer.write(" char a[10]; \n"); //$NON-NLS-1$
|
||||
writer.write(" __builtin_va_list b; \n"); //$NON-NLS-1$
|
||||
writer.write(" __builtin_abort(); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_exit(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin__Exit(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin__exit(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_conj(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_conjf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_conjl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_creal(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_crealf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_creall(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_cimag(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_cimagf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_cimagl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_imaxabs(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_llabs(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_vscanf(\"\",b);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_vsnprintf(a, 1, \"\", b); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_vsscanf(\"\", \"\", b);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_cosf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_cosl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_expf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_expl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_fabsf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_fabsl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_logf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_logl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sinf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sinl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sqrtf(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sqrtl(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_abs(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_cos(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_exp(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_fabs(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_fprintf((void*)0, \"\");\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_fputs(\"\", (void*)0);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_labs(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_log(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_memcmp((void*)0, (void*)0, 1);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_memcpy((void*)0,(void*)0, 1);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_memset((void*)0, 1, 1);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_printf(\"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_putchar(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_puts(\"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_scanf(\"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sin(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_snprintf(a, 1, \"\");\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sprintf(a, \"\");\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sqrt(1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_sscanf(\"\", \"\"); \n");//$NON-NLS-1$1
|
||||
writer.write(" __builtin_strcat(a, \"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strchr(\"\", 1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strcmp(\"\", \"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strcpy(a, \"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strcspn(\"\", \"\");\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strlen(\"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strncat(a, \"\", 1);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strncmp(\"\", \"\", 1);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strncpy(a, \"\", 1);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strpbrk(\"\", \"\");\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strrchr(\"\", 1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strspn(\"\", \"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strstr(\"\", \"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_strstr(\"\", \"\"); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_vprintf(a, b);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_vsprintf(a, 1, \"\", b); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_isgreater(1,1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_isgreaterequal(1,1);\n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_isless(1,1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_islessequal(1,1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_islessgreater(1,1); \n");//$NON-NLS-1$
|
||||
writer.write(" __builtin_isunordered(1,1); \n");//$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
|
||||
parseGCC( writer.toString() );
|
||||
parseGPP( writer.toString() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
|
@ -31,9 +32,13 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
|
@ -41,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
|
@ -50,6 +56,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
|
||||
|
||||
|
@ -100,11 +107,61 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
if (scope == null)
|
||||
if (scope == null) {
|
||||
scope = new CPPNamespaceScope(this);
|
||||
addBuiltinOperators(scope);
|
||||
}
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
private void addBuiltinOperators(IScope theScope) {
|
||||
// void
|
||||
IType cpp_void = new CPPBasicType(IBasicType.t_void, 0);
|
||||
// void *
|
||||
IType cpp_void_p = new GPPPointerType(new CPPQualifierType(new CPPBasicType(IBasicType.t_void, 0), false, false), new GPPASTPointer());
|
||||
// size_t // assumed: unsigned long int
|
||||
IType cpp_size_t = new CPPBasicType(IBasicType.t_int, CPPBasicType.IS_LONG & CPPBasicType.IS_UNSIGNED);
|
||||
|
||||
// void * operator new (std::size_t);
|
||||
IBinding temp = null;
|
||||
IType[] newParms = new IType[1];
|
||||
newParms[0] = cpp_size_t;
|
||||
IFunctionType newFunctionType = new CPPFunctionType(cpp_void_p, newParms);
|
||||
IParameter[] newTheParms = new IParameter[1];
|
||||
newTheParms[0] = new CPPBuiltinParameter(newParms[0]);
|
||||
temp = new CPPImplicitFunction(ICPPASTOperatorName.OPERATOR_NEW, theScope, newFunctionType, newTheParms, false);
|
||||
try {
|
||||
theScope.addBinding(temp);
|
||||
} catch (DOMException de) {}
|
||||
|
||||
// void * operator new[] (std::size_t);
|
||||
temp = null;
|
||||
temp = new CPPImplicitFunction(ICPPASTOperatorName.OPERATOR_NEW_ARRAY, theScope, newFunctionType, newTheParms, false);
|
||||
try {
|
||||
theScope.addBinding(temp);
|
||||
} catch (DOMException de) {}
|
||||
|
||||
// void operator delete(void*);
|
||||
temp = null;
|
||||
IType[] deleteParms = new IType[1];
|
||||
deleteParms[0] = cpp_size_t;
|
||||
IFunctionType deleteFunctionType = new CPPFunctionType(cpp_void, deleteParms);
|
||||
IParameter[] deleteTheParms = new IParameter[1];
|
||||
deleteTheParms[0] = new CPPBuiltinParameter(deleteParms[0]);
|
||||
temp = new CPPImplicitFunction(ICPPASTOperatorName.OPERATOR_DELETE, theScope, deleteFunctionType, deleteTheParms, false);
|
||||
try {
|
||||
theScope.addBinding(temp);
|
||||
} catch (DOMException de) {}
|
||||
|
||||
// void operator delete[](void*);
|
||||
temp = null;
|
||||
temp = new CPPImplicitFunction(ICPPASTOperatorName.OPERATOR_DELETE_ARRAY, theScope, deleteFunctionType, deleteTheParms, false);
|
||||
try {
|
||||
theScope.addBinding(temp);
|
||||
} catch (DOMException de) {}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
|
@ -4370,7 +4370,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
// least
|
||||
// one of these
|
||||
}
|
||||
while (LT(1) == IToken.t_catch) {
|
||||
|
||||
int nextToken = LT(1);
|
||||
while (nextToken == IToken.t_catch) {
|
||||
int startOffset = consume(IToken.t_catch).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
boolean isEllipsis = false;
|
||||
|
@ -4411,6 +4413,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
.setPropertyInParent(ICPPASTCatchHandler.CATCH_BODY);
|
||||
}
|
||||
collection.add(handler);
|
||||
|
||||
try {
|
||||
nextToken = LT(1);
|
||||
} catch (EndOfFileException eofe) {
|
||||
// if EOF is reached, then return here and let it be encountered elsewhere
|
||||
// (i.e. try/catch won't be added to the declaration if the exception is thrown here)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4011,7 +4011,7 @@ abstract class BaseScanner implements IScanner {
|
|||
argend = skipOverMacroArg();
|
||||
|
||||
char[] arg = EMPTY_CHAR_ARRAY;
|
||||
int arglen = argend - argstart + 1; // TODO Devin argend shouldn't be 65 it should be 55 for 95119
|
||||
int arglen = argend - argstart + 1;
|
||||
if (arglen > 0) {
|
||||
arg = new char[arglen];
|
||||
System.arraycopy(buffer, argstart, arg, 0, arglen);
|
||||
|
|
Loading…
Add table
Reference in a new issue