1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Devin Steffler.

This patch adds basic K&R C support to the GNUCSourceParser.
- added support for K&R C syntax
- added support for ASTProblemDeclaration with faulty K&R C syntax
- added simple tests
This commit is contained in:
John Camelon 2005-01-19 20:24:01 +00:00
parent 8006bc409b
commit 8d833f012a
19 changed files with 3202 additions and 2293 deletions

View file

@ -17,6 +17,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTests;
import org.eclipse.cdt.core.parser.tests.ast2.AST2KnRTests;
import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationTests;
@ -63,6 +64,7 @@ public class ParserTestSuite extends TestCase {
suite.addTestSuite( QuickParser2Tests.class );
suite.addTestSuite( CompleteParser2Tests.class );
suite.addTestSuite( DOMLocationTests.class );
suite.addTestSuite( AST2KnRTests.class );
return suite;
}
}

View file

@ -45,11 +45,13 @@ import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
@ -64,13 +66,17 @@ public class AST2BaseTest extends TestCase {
private static final IParserLogService NULL_LOG = new NullLogService();
protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException {
return parse(code, lang, false);
}
/**
* @param string
* @param c
* @return
* @throws ParserException
*/
protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException {
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions ) throws ParserException {
CodeReader codeReader = new CodeReader(code
.toCharArray());
ScannerInfo scannerInfo = new ScannerInfo();
@ -85,7 +91,10 @@ public class AST2BaseTest extends TestCase {
if( lang == ParserLanguage.CPP )
{
ICPPParserExtensionConfiguration config = null;
config = new ANSICPPParserExtensionConfiguration();
if (useGNUExtensions)
config = new GPPParserExtensionConfiguration();
else
config = new ANSICPPParserExtensionConfiguration();
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE,
NULL_LOG,
config );
@ -93,7 +102,11 @@ public class AST2BaseTest extends TestCase {
else
{
ICParserExtensionConfiguration config = null;
config = new ANSICParserExtensionConfiguration();
if (useGNUExtensions)
config = new GCCParserExtensionConfiguration();
else
config = new ANSICParserExtensionConfiguration();
parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE,
NULL_LOG, config );

View file

@ -0,0 +1,327 @@
/**********************************************************************
* Copyright (c) 2005 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.ParserLanguage;
/**
* @author dsteffle
*/
public class AST2KnRTests extends AST2BaseTest {
public void testSimpleKRCTest1() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int f(char x);\n" ); //$NON-NLS-1$
buffer.append( "int f(x) char x;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
IParameter x1 = (IParameter)((IASTStandardFunctionDeclarator)f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName().resolveBinding();
assertNotNull( x1 );
assertNotNull( x2 );
assertNotNull( x3 );
assertNotNull( x4 );
assertEquals( x1, x2 );
assertEquals( x2, x3 );
assertEquals( x3, x4 );
}
public void testSimpleKRCTest2() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int f();\n" ); //$NON-NLS-1$
buffer.append( "int f(x) char x;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
assertNotNull( x2 );
assertNotNull( x3 );
assertNotNull( x4 );
assertEquals( x2, x3 );
assertEquals( x3, x4 );
}
public void testSimpleKRCTest3() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int const *f();\n" ); //$NON-NLS-1$
buffer.append( "int const *f(x) char x;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
assertNotNull( x2 );
assertNotNull( x3 );
assertNotNull( x4 );
assertEquals( x2, x3 );
assertEquals( x3, x4 );
}
public void testKRC_1() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int isroot (x, y) /* comment */ \n" ); //$NON-NLS-1$
buffer.append( "int x;\n" ); //$NON-NLS-1$
buffer.append( "int y;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTFunctionDefinition isroot_def = (IASTFunctionDefinition)tu.getDeclarations()[0];
IASTName ret_x = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
IASTDeclarator isroot_decltor = isroot_def.getDeclarator();
assertTrue( isroot_decltor instanceof ICASTKnRFunctionDeclarator );
IASTDeclarator x1 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
IASTDeclarator y1 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
IParameter x_parm = (IParameter)x1.getName().resolveBinding();
IParameter y_parm = (IParameter)y1.getName().resolveBinding();
assertNotNull( x_parm );
assertNotNull( y_parm );
IASTDeclarator x2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
IASTDeclarator y2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
IParameter x_parm2 = (IParameter)x2.getName().resolveBinding();
IParameter y_parm2 = (IParameter)y2.getName().resolveBinding();
assertNotNull( x_parm2 );
assertNotNull( y_parm2 );
assertNotNull( ret_x.resolveBinding() );
assertEquals( x_parm, x_parm2 );
assertEquals( y_parm, y_parm2 );
assertEquals( ret_x.resolveBinding(), x_parm );
}
public void testKRCWithTypes() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "typedef char c;\n" ); //$NON-NLS-1$
buffer.append( "int isroot (c);\n" ); //$NON-NLS-1$
buffer.append( "int isroot (x) \n" ); //$NON-NLS-1$
buffer.append( "c x;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTSimpleDeclaration c_decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
IASTSimpleDeclaration isroot_decl = (IASTSimpleDeclaration)tu.getDeclarations()[1];
IASTFunctionDefinition isroot_def = (IASTFunctionDefinition)tu.getDeclarations()[2];
IASTName x1 = ((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterNames()[0];
IASTName x2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
IASTName x3 = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
IParameter x1_var = (IParameter)x1.resolveBinding();
IParameter x2_var = (IParameter)x2.resolveBinding();
IParameter x3_var = (IParameter)x3.resolveBinding();
assertNotNull(x1_var);
assertNotNull(x2_var);
assertNotNull(x3_var);
assertEquals(x1_var, x2_var);
assertEquals(x2_var, x3_var);
IASTName c1 = c_decl.getDeclarators()[0].getName();
IASTName c2 = ((IASTNamedTypeSpecifier)((IASTStandardFunctionDeclarator)isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
IASTName c3 = ((IASTNamedTypeSpecifier)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
ITypedef c1_t = (ITypedef)c1.resolveBinding();
ITypedef c2_t = (ITypedef)c2.resolveBinding();
ITypedef c3_t = (ITypedef)c3.resolveBinding();
assertNotNull(c1_t);
assertNotNull(c2_t);
assertNotNull(c3_t);
assertEquals(c1_t, c2_t);
assertEquals(c2_t, c3_t);
assertTrue(c1_t.getType() instanceof IBasicType);
assertEquals(((IBasicType)c1_t.getType()).getType(), IBasicType.t_char);
}
public void testKRCProblem1() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int f(x) char\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// TODO problem bindings, right now both bindings for x are null, similarly for the below KRCProblem tests
// f_kr.getParameterNames()[0].resolveBinding();
// ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
}
public void testKRCProblem2() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int i=0;\n" ); //$NON-NLS-1$
buffer.append( "int f(x) i++;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[1];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
}
public void testKRCProblem3() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int f(x) char y;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
}
public void testKRCProblem4() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int f(x,y,z) char x,y,z; int a;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTSimpleDeclaration);
assertTrue(f_kr.getParameterDeclarations()[1] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// bindings should still be ok
IASTName x1 = f_kr.getParameterNames()[0];
IASTName y1 = f_kr.getParameterNames()[1];
IASTName z1 = f_kr.getParameterNames()[2];
IASTName x2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[0].getName();
IASTName y2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[1].getName();
IASTName z2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[2].getName();
IASTName x3 = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
IParameter x1_parm = (IParameter)x1.resolveBinding();
IParameter x2_parm = (IParameter)x2.resolveBinding();
IParameter x3_parm = (IParameter)x3.resolveBinding();
IParameter y1_parm = (IParameter)y1.resolveBinding();
IParameter y2_parm = (IParameter)y2.resolveBinding();
IParameter z1_parm = (IParameter)z1.resolveBinding();
IParameter z2_parm = (IParameter)z2.resolveBinding();
assertEquals(x1_parm, x2_parm);
assertEquals(x2_parm, x3_parm);
assertEquals(y1_parm, y2_parm);
assertEquals(z1_parm, z2_parm);
}
public void testKRCProblem5() throws Exception {
StringBuffer buffer = new StringBuffer(); //$NON-NLS-1$
buffer.append( "int f(x) char x,a;\n" ); //$NON-NLS-1$
buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
}
}

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
@ -115,7 +116,8 @@ public class AST2Tests extends AST2BaseTest {
assertEquals("f", name_f.toString()); //$NON-NLS-1$
// parameter - int y
IASTParameterDeclaration decl_y = declor_f.getParameters()[0];
assertTrue(declor_f instanceof IASTStandardFunctionDeclarator);
IASTParameterDeclaration decl_y = ((IASTStandardFunctionDeclarator)declor_f).getParameters()[0];
IASTSimpleDeclSpecifier declspec_y = (IASTSimpleDeclSpecifier) decl_y
.getDeclSpecifier();
assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_y.getType());
@ -629,7 +631,8 @@ public class AST2Tests extends AST2BaseTest {
IASTName x_1 = typeSpec.getName();
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[1];
IASTParameterDeclaration param = fdef.getDeclarator().getParameters()[0];
assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
IASTParameterDeclaration param = ((IASTStandardFunctionDeclarator)fdef.getDeclarator()).getParameters()[0];
IASTName x_2 = param.getDeclarator().getName();
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
@ -692,7 +695,7 @@ public class AST2Tests extends AST2BaseTest {
//void f(
IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) f_decl.getDeclarators()[0];
IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) f_decl.getDeclarators()[0];
IASTName f_name1 = dtor.getName();
// int a );
IASTParameterDeclaration param1 = dtor.getParameters()[0];
@ -701,7 +704,8 @@ public class AST2Tests extends AST2BaseTest {
//void f(
IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu.getDeclarations()[1];
dtor = f_defn.getDeclarator();
assertTrue(f_defn.getDeclarator() instanceof IASTStandardFunctionDeclarator);
dtor = (IASTStandardFunctionDeclarator)f_defn.getDeclarator();
IASTName f_name2 = dtor.getName();
// int b );
IASTParameterDeclaration param2 = dtor.getParameters()[0];
@ -764,7 +768,8 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations()[0];
IASTFunctionDeclarator fDtor = fDef.getDeclarator();
assertTrue(fDef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator)fDef.getDeclarator();
IASTName fName = fDtor.getName();
IASTParameterDeclaration a = fDtor.getParameters()[0];
@ -812,7 +817,7 @@ public class AST2Tests extends AST2BaseTest {
//void f();
IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) fdecl.getDeclarators()[0];
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) fdecl.getDeclarators()[0];
IASTName name_f = fdtor.getName();
//void g() {
@ -828,7 +833,8 @@ public class AST2Tests extends AST2BaseTest {
//void f() {}
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[2];
fdtor = fdef.getDeclarator();
assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
fdtor = (IASTStandardFunctionDeclarator)fdef.getDeclarator();
IASTName name_fdef = fdtor.getName();
//bindings
@ -1024,8 +1030,8 @@ public class AST2Tests extends AST2BaseTest {
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration)tu.getDeclarations()[1];
IASTName name_X1 = decl1.getDeclarators()[0].getName();
IASTName name_f = decl2.getDeclarators()[0].getName();
IASTName name_X2 = ((IASTNamedTypeSpecifier)((IASTFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
IASTName name_x = ((IASTFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName name_X2 = ((IASTNamedTypeSpecifier)((IASTStandardFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
IASTName name_x = ((IASTStandardFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName[] decls = tu.getDeclarations(name_X1.resolveBinding());
assertEquals( decls.length, 1 );
@ -1207,7 +1213,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals( tu.getDeclarations().length, 1 );
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
assertEquals( d.getDeclarators().length, 1 );
IASTFunctionDeclarator f = (IASTFunctionDeclarator) d.getDeclarators()[0];
IASTStandardFunctionDeclarator f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
assertNull( f.getName().toString() );
assertNotNull( f.getNestedDeclarator() );
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
@ -1223,7 +1229,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals( tu.getDeclarations().length, 1 );
d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
assertEquals( d.getDeclarators().length, 1 );
f = (IASTFunctionDeclarator) d.getDeclarators()[0];
f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
assertNull( f.getName().toString() );
assertNotNull( f.getNestedDeclarator() );
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
@ -1521,19 +1527,19 @@ public class AST2Tests extends AST2BaseTest {
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
IFunction f = (IFunction) decl.getDeclarators()[0].getName().resolveBinding();
IASTName name_f = decl.getDeclarators()[0].getName();
IASTName name_i = ((IASTFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName name_c = ((IASTFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[1].getDeclarator().getName();
IASTName name_i = ((IASTStandardFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName name_c = ((IASTStandardFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[1].getDeclarator().getName();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
IVariable g = (IVariable) decl.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding();
IASTName name_g = decl.getDeclarators()[0].getNestedDeclarator().getName();
IASTName name_A2 = ((IASTElaboratedTypeSpecifier)((IASTFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
IASTName name_A2 = ((IASTElaboratedTypeSpecifier)((IASTStandardFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[3];
IVariable h = (IVariable) decl.getDeclarators()[0].getNestedDeclarator().getNestedDeclarator().getName().resolveBinding();
IASTName name_h = decl.getDeclarators()[0].getNestedDeclarator().getNestedDeclarator().getName();
IASTName name_A3 = ((IASTElaboratedTypeSpecifier)((IASTFunctionDeclarator)decl.getDeclarators()[0].getNestedDeclarator()).getParameters()[0].getDeclSpecifier()).getName();
IASTName name_d = ((IASTFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName name_A3 = ((IASTElaboratedTypeSpecifier)((IASTStandardFunctionDeclarator)decl.getDeclarators()[0].getNestedDeclarator()).getParameters()[0].getDeclSpecifier()).getName();
IASTName name_d = ((IASTStandardFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IFunctionType t_f = f.getType();
IType t_f_return = t_f.getReturnType();
@ -1774,7 +1780,7 @@ public class AST2Tests extends AST2BaseTest {
buffer.append( "typedef s t;\n" ); //$NON-NLS-1$
buffer.append( "typedef t y;\n" ); //$NON-NLS-1$
buffer.append( "y x = {.a=1,.b=2};\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); // TODO Devin make sure that loop I put in works properly for types
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
IASTSimpleDeclaration x_decl = (IASTSimpleDeclaration)tu.getDeclarations()[3];
@ -1827,7 +1833,7 @@ public class AST2Tests extends AST2BaseTest {
assertTrue( ((IPointerType)ft.getParameterTypes()[0]).isConst() );
// test tu.getDeclarations(IBinding)
IASTName name_parm = ((IASTFunctionDeclarator)def.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName name_parm = ((IASTStandardFunctionDeclarator)def.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName[] decls = tu.getDeclarations(name_parm.resolveBinding());
assertEquals( decls.length, 1 );
assertEquals( decls[0], name_parm );
@ -1892,7 +1898,8 @@ public class AST2Tests extends AST2BaseTest {
assertEquals( ((IBasicType)gt_parm).getType(), IBasicType.t_void );
// test tu.getDeclarations(IBinding)
IASTName name_g = def.getDeclarator().getParameters()[0].getDeclarator().getName();
assertTrue(def.getDeclarator() instanceof IASTStandardFunctionDeclarator);
IASTName name_g = ((IASTStandardFunctionDeclarator)def.getDeclarator()).getParameters()[0].getDeclarator().getName();
IASTName name_g_call = ((IASTIdExpression)((IASTFunctionCallExpression)((IASTReturnStatement)((IASTCompoundStatement)def.getBody()).getStatements()[0]).getReturnValue()).getFunctionNameExpression()).getName();
IASTName[] decls = tu.getDeclarations(name_g_call.resolveBinding());
assertEquals( decls.length, 1 );
@ -1903,7 +1910,7 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( "int (*v[])(int *x, int *y);", ParserLanguage.C ); //$NON-NLS-1$
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IVariable v = (IVariable)((IASTFunctionDeclarator) decl.getDeclarators()[0]).getNestedDeclarator().getName().resolveBinding();
IVariable v = (IVariable)((IASTStandardFunctionDeclarator) decl.getDeclarators()[0]).getNestedDeclarator().getName().resolveBinding();
IType vt_1 = v.getType();
assertTrue( vt_1 instanceof IArrayType );
@ -1927,9 +1934,9 @@ public class AST2Tests extends AST2BaseTest {
assertEquals( ((IBasicType)vpt_2_2).getType(), IBasicType.t_int );
// test tu.getDeclarations(IBinding)
IASTName[] decls = tu.getDeclarations(((IASTFunctionDeclarator) decl.getDeclarators()[0]).getNestedDeclarator().getName().resolveBinding());
IASTName[] decls = tu.getDeclarations(((IASTStandardFunctionDeclarator) decl.getDeclarators()[0]).getNestedDeclarator().getName().resolveBinding());
assertEquals( decls.length, 1 );
assertEquals( decls[0], ((IASTFunctionDeclarator) decl.getDeclarators()[0]).getNestedDeclarator().getName() );
assertEquals( decls[0], ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0]).getNestedDeclarator().getName() );
}
public void testTypedefExample4a() throws Exception {
@ -2043,7 +2050,7 @@ public class AST2Tests extends AST2BaseTest {
// test tu.getDeclarations(IBinding)
IASTName name_pfv = decl2.getDeclarators()[0].getNestedDeclarator().getName();
IASTName name_pfv1 = ((IASTNamedTypeSpecifier)decl3.getDeclSpecifier()).getName();
IASTName name_pfv2 = ((IASTNamedTypeSpecifier)((IASTFunctionDeclarator)decl3.getDeclarators()[0]).getParameters()[1].getDeclSpecifier()).getName();
IASTName name_pfv2 = ((IASTNamedTypeSpecifier)((IASTStandardFunctionDeclarator)decl3.getDeclarators()[0]).getParameters()[1].getDeclSpecifier()).getName();
IASTName[] decls = tu.getDeclarations(name_pfv1.resolveBinding());
assertEquals( decls.length, 1 );
@ -2118,7 +2125,7 @@ public class AST2Tests extends AST2BaseTest {
{
StringBuffer buffer =new StringBuffer(); //$NON-NLS-1$
buffer.append( "int y ( int [ const *] );"); //$NON-NLS-1$
ICASTArrayModifier mod = (ICASTArrayModifier)((IASTArrayDeclarator)((IASTFunctionDeclarator) ((IASTSimpleDeclaration) parse( buffer.toString(), ParserLanguage.C ).getDeclarations()[0]).getDeclarators()[0]).getParameters()[0].getDeclarator() ).getArrayModifiers()[0];
ICASTArrayModifier mod = (ICASTArrayModifier)((IASTArrayDeclarator)((IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) parse( buffer.toString(), ParserLanguage.C ).getDeclarations()[0]).getDeclarators()[0]).getParameters()[0].getDeclarator() ).getArrayModifiers()[0];
assertTrue( mod.isConst() );
assertTrue( mod.isVariableSized() );
assertFalse( mod.isStatic() );

View file

@ -18,17 +18,4 @@ package org.eclipse.cdt.core.dom.ast;
*/
public interface IASTFunctionDeclarator extends IASTDeclarator {
ASTNodeProperty FUNCTION_PARAMETER = new ASTNodeProperty( "Parameter"); //$NON-NLS-1$
/**
* Gets the parameter declarations for the function
*
* @return List of IASTParameterDeclaration
*/
public IASTParameterDeclaration[] getParameters();
public void addParameterDeclaration( IASTParameterDeclaration parameter );
public boolean takesVarArgs();
public void setVarArgs( boolean value );
}

View file

@ -0,0 +1,34 @@
/**********************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.core.dom.ast;
/**
* This is a declarator for a non K&R C function.
*
* @author Doug Schaefer
*/
public interface IASTStandardFunctionDeclarator extends IASTFunctionDeclarator {
public final static ASTNodeProperty FUNCTION_PARAMETER = new ASTNodeProperty( "Parameter"); //$NON-NLS-1$
/**
* Gets the parameter declarations for the function
*
* @return List of IASTParameterDeclaration
*/
public IASTParameterDeclaration[] getParameters();
public void addParameterDeclaration( IASTParameterDeclaration parameter );
public boolean takesVarArgs();
public void setVarArgs( boolean value );
}

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
/**
@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
*
* @author Doug Schaefer
*/
public interface ICPPASTFunctionDeclarator extends IASTFunctionDeclarator {
public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarator {
public boolean isConst();

View file

@ -0,0 +1,32 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.core.dom.ast.gnu.c;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
/**
* This is the declarator for a K&R C Function.
*
* @author dsteffle
*/
public interface ICASTKnRFunctionDeclarator extends IASTFunctionDeclarator {
public static final ASTNodeProperty PARAMETER_NAME = new ASTNodeProperty( "Parameter Name"); //$NON-NLS-1$
public void setParameterNames(IASTName[] names);
public IASTName[] getParameterNames();
public static final ASTNodeProperty FUNCTION_PARAMETER = new ASTNodeProperty( "Parameter"); //$NON-NLS-1$
public void setParameterDeclarations(IASTDeclaration[] decls);
public IASTDeclaration[] getParameterDeclarations();
}

View file

@ -9,14 +9,14 @@
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
/**
* @author jcamelon
*/
public class CASTFunctionDeclarator extends CASTDeclarator implements
IASTFunctionDeclarator {
IASTStandardFunctionDeclarator {
private IASTParameterDeclaration [] parameters = null;
private static final int DEFAULT_PARAMETERS_LIST_SIZE = 2;

View file

@ -0,0 +1,55 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
/**
* A K&R C function declarator.
*
* @author dsteffle
*/
public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKnRFunctionDeclarator {
IASTName[] parameterNames = null;
IASTDeclaration[] parameterDeclarations = null;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator#setParameterNames(org.eclipse.cdt.core.dom.ast.IASTName[])
*/
public void setParameterNames(IASTName[] names) {
parameterNames = names;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator#getParameterNames()
*/
public IASTName[] getParameterNames() {
return parameterNames;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator#setParameterDeclarations(org.eclipse.cdt.core.dom.ast.IASTDeclaration[])
*/
public void setParameterDeclarations(IASTDeclaration[] decls) {
parameterDeclarations = decls;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator#getParameterDeclarations()
*/
public IASTDeclaration[] getParameterDeclarations() {
return parameterDeclarations;
}
}

View file

@ -16,6 +16,8 @@ import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
@ -23,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
/**
* Created on Nov 5, 2004
@ -45,7 +48,7 @@ public class CFunction implements IFunction {
return ( definition != null ) ? definition : declarators[0];
}
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
if( fnDeclarator instanceof IASTFunctionDefinition )
if( fnDeclarator instanceof IASTFunctionDefinition || fnDeclarator instanceof ICASTKnRFunctionDeclarator )
definition = fnDeclarator;
else {
if( declarators == null ){
@ -80,17 +83,37 @@ public class CFunction implements IFunction {
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
*/
public List getParameters() {
List result = null;
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
IASTParameterDeclaration[] params = dtor.getParameters();
int size = params.length;
List result = new ArrayList( size );
if( size > 0 ){
for( int i = 0; i < size; i++ ){
IASTParameterDeclaration p = params[i];
result.add( p.getDeclarator().getName().resolveBinding() );
if (dtor instanceof IASTStandardFunctionDeclarator) {
IASTParameterDeclaration[] params = ((IASTStandardFunctionDeclarator)dtor).getParameters();
int size = params.length;
result = new ArrayList( size );
if( size > 0 ){
for( int i = 0; i < size; i++ ){
IASTParameterDeclaration p = params[i];
result.add( p.getDeclarator().getName().resolveBinding() );
}
}
} else if (dtor instanceof ICASTKnRFunctionDeclarator) {
IASTDeclaration[] params = ((ICASTKnRFunctionDeclarator)dtor).getParameterDeclarations();
int size = params.length;
result = new ArrayList( size );
if( size > 0 ){
for( int i = 0; i < size; i++ ){
IASTDeclaration p = params[i];
if ( p instanceof IASTSimpleDeclaration ) {
IASTDeclarator[] decltors = ((IASTSimpleDeclaration)p).getDeclarators();
for( int j=0; j<decltors.length; j++ ){
result.add( decltors[j].getName().resolveBinding() );
}
}
}
}
}
return result;
return result;
}
/* (non-Javadoc)

View file

@ -0,0 +1,85 @@
/**********************************************************************
* Copyright (c) 2005 IBM Canada and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
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.ICASTTypedefNameSpecifier;
/**
* A K&R C parameter.
*
* @author dsteffle
*/
public class CKnRParameter implements IParameter {
final private IASTDeclaration declaration;
final private IASTName name;
public CKnRParameter(IASTDeclaration declaration, IASTName name) {
this.declaration = declaration;
this.name = name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
*/
public IType getType() {
IASTDeclSpecifier declSpec = null;
if (declaration instanceof IASTSimpleDeclaration)
declSpec = ((IASTSimpleDeclaration)declaration).getDeclSpecifier();
if( declSpec != null && declSpec instanceof ICASTTypedefNameSpecifier ){
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
return (IType) nameSpec.getName().resolveBinding();
} else if( declSpec != null && declSpec instanceof IASTElaboratedTypeSpecifier ){
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec;
return (IType) elabTypeSpec.getName().resolveBinding();
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
return name.toString();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
public char[] getNameCharArray() {
return name.toCharArray();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() {
return CVisitor.getContainingScope( declaration );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
*/
public IASTNode getPhysicalNode() {
return declaration;
}
}

View file

@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
@ -85,6 +86,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -297,7 +299,8 @@ public class CVisitor {
}
} else if ( parent instanceof IASTSimpleDeclaration ) {
if ( (declarator.getName() != null && declarator.getName().resolveBinding() == binding) ) {
if ( declarator instanceof IASTFunctionDeclarator ) {
if ( declarator instanceof IASTStandardFunctionDeclarator ||
declarator instanceof ICASTKnRFunctionDeclarator ) {
functionDeclared = true;
}
@ -497,12 +500,30 @@ public class CVisitor {
private static IBinding createBinding(IASTDeclarator declarator, IASTName name) {
IBinding binding = null;
IASTNode parent = declarator.getParent();
if( declarator instanceof IASTFunctionDeclarator ){
if( declarator instanceof IASTStandardFunctionDeclarator ){
binding = resolveBinding( parent, CURRENT_SCOPE );
if( binding != null )
((CFunction)binding).addDeclarator( (IASTFunctionDeclarator) declarator );
else
if( binding != null ) {
((CFunction)binding).addDeclarator( (IASTStandardFunctionDeclarator) declarator );
} else {
binding = createBinding(declarator);
}
} else if( declarator instanceof ICASTKnRFunctionDeclarator ){
if ( CharArrayUtils.equals(declarator.getName().toCharArray(), name.toCharArray()) ){
binding = resolveBinding( parent, CURRENT_SCOPE );
if( binding != null ) {
((CFunction)binding).addDeclarator( (ICASTKnRFunctionDeclarator) declarator );
} else {
binding = createBinding(declarator);
}
} else { // createBinding for one of the ICASTKnRFunctionDeclarator's parameterNames
binding = resolveKnRParameterBinding((ICASTKnRFunctionDeclarator) declarator, name);
if ( declarator.getParent() instanceof IASTFunctionDefinition ) {
ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)declarator.getParent()).getBody()).getScope();
if ( scope != null && binding != null )
scope.addBinding(binding);
}
}
} else if( parent instanceof IASTSimpleDeclaration ){
binding = createBinding( (IASTSimpleDeclaration) parent, name );
} else if( parent instanceof IASTParameterDeclaration ){
@ -511,7 +532,7 @@ public class CVisitor {
// C99 6.2.1-4: within the list of parameter declarations in a function definition, the
// identifier has block scope, which terminates at the end of the associated block.
parent = parent.getParent();
if ( parent instanceof IASTFunctionDeclarator ) {
if ( parent instanceof IASTStandardFunctionDeclarator ) {
parent = parent.getParent();
if ( parent instanceof IASTFunctionDefinition ) {
ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
@ -598,7 +619,13 @@ public class CVisitor {
CScope scope = (CScope) CVisitor.getContainingScope( simpleDeclaration );
binding = scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, name.toCharArray() );
if( binding == null ){
binding = new CVariable( name );
// if the simpleDeclaration is part of a KRC function declarator, then the binding is to a KRC parameter
if ( simpleDeclaration.getParent() instanceof IASTFunctionDeclarator ) {
binding = resolveKnRParameterBinding((ICASTKnRFunctionDeclarator) simpleDeclaration.getParent(), name); // is resolveKnRParameterBinding still necessary?
} else {
binding = new CVariable( name );
}
scope.addBinding( binding );
}
}
@ -637,7 +664,7 @@ public class CVisitor {
return findBinding( blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits );
} else if( node instanceof IASTParameterDeclaration ){
IASTParameterDeclaration param = (IASTParameterDeclaration) node;
IASTFunctionDeclarator fDtor = (IASTFunctionDeclarator) param.getParent();
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
if ( fDtor.getName().resolveBinding() instanceof IFunction ) { // possible to have IASTParameterDeclaration whose parent is an IVariable
IFunction function = (IFunction) fDtor.getName().resolveBinding();
@ -733,6 +760,14 @@ public class CVisitor {
return ((IASTForStatement)parent).getScope();
} else if( parent instanceof IASTCompositeTypeSpecifier ){
return ((IASTCompositeTypeSpecifier)parent).getScope();
} else if( parent instanceof ICASTKnRFunctionDeclarator ){
parent = declaration.getParent();
if( parent instanceof ICASTKnRFunctionDeclarator ){
parent = ((IASTDeclarator)parent).getParent();
if ( parent instanceof IASTFunctionDefinition ) {
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
}
}
}
return null;
@ -773,7 +808,7 @@ public class CVisitor {
*/
public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) {
IASTNode parent = parameterDeclaration.getParent();
if( parent instanceof IASTFunctionDeclarator ){
if( parent instanceof IASTStandardFunctionDeclarator ){
parent = ((IASTDeclarator)parent).getParent();
if ( parent instanceof IASTFunctionDefinition ) {
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
@ -917,22 +952,46 @@ public class CVisitor {
}
} else if( declaration instanceof IASTFunctionDefinition ){
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) functionDef.getDeclarator();
//check the function itself
IASTName declName = declarator.getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding();
}
//check the parameters
IASTParameterDeclaration [] parameters = declarator.getParameters();
for( int i = 0; i < parameters.length; i++ ){
IASTParameterDeclaration parameterDeclaration = parameters[i];
if( parameterDeclaration == null ) break;
declName = parameterDeclaration.getDeclarator().getName();
if (functionDef.getDeclarator() instanceof IASTStandardFunctionDeclarator) {
CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) functionDef.getDeclarator();
//check the function itself
IASTName declName = declarator.getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding();
}
//check the parameters
IASTParameterDeclaration [] parameters = declarator.getParameters();
for( int i = 0; i < parameters.length; i++ ){
IASTParameterDeclaration parameterDeclaration = parameters[i];
if( parameterDeclaration == null ) break;
declName = parameterDeclaration.getDeclarator().getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding();
}
}
} else if (functionDef.getDeclarator() instanceof ICASTKnRFunctionDeclarator) {
CASTKnRFunctionDeclarator declarator = (CASTKnRFunctionDeclarator) functionDef.getDeclarator();
//check the function itself
IASTName declName = declarator.getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding();
}
//check the parameters
IASTDeclaration [] parameters = declarator.getParameterDeclarations();
for( int i = 0; i < parameters.length; i++ ){
IASTDeclaration parameterDeclaration = parameters[i];
if( parameterDeclaration == null || !(parameters[i] instanceof IASTSimpleDeclaration)) break;
IASTDeclarator[] parmDecltors = ((IASTSimpleDeclaration)parameters[i]).getDeclarators();
for (int j=0; j<parmDecltors.length; j++) {
declName = parmDecltors[j].getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding();
}
}
}
}
}
return null;
@ -1063,8 +1122,8 @@ public class CVisitor {
if( declarator.getInitializer() != null )
if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
if( declarator instanceof IASTFunctionDeclarator ){
IASTParameterDeclaration [] list = ((IASTFunctionDeclarator)declarator).getParameters();
if( declarator instanceof IASTStandardFunctionDeclarator ){
IASTParameterDeclaration [] list = ((IASTStandardFunctionDeclarator)declarator).getParameters();
for( int i = 0; i < list.length; i++ ){
IASTParameterDeclaration param = list[i];
if( !visitDeclSpecifier( param.getDeclSpecifier(), action ) ) return false;
@ -1425,13 +1484,30 @@ public class CVisitor {
* @return IType[] corresponding to the IASTFunctionDeclarator parameters
*/
private static IType[] getParmTypes( IASTFunctionDeclarator decltor ){
IASTParameterDeclaration parms[] = decltor.getParameters();
IType parmTypes[] = new IType[parms.length];
for( int i = 0; i < parms.length; i++ ){
parmTypes[i] = createType(parms[i].getDeclarator().getName(), true);
}
return parmTypes;
if ( decltor instanceof IASTStandardFunctionDeclarator ) {
IASTParameterDeclaration parms[] = ((IASTStandardFunctionDeclarator)decltor).getParameters();
IType parmTypes[] = new IType[parms.length];
for( int i = 0; i < parms.length; i++ ){
parmTypes[i] = createType(parms[i].getDeclarator().getName(), true);
}
return parmTypes;
} else if ( decltor instanceof ICASTKnRFunctionDeclarator ) {
IASTDeclaration parms[] = ((ICASTKnRFunctionDeclarator)decltor).getParameterDeclarations();
IType parmTypes[] = new IType[parms.length];
for( int i = 0; i < parms.length; i++ ){
if ( parms[i] instanceof IASTSimpleDeclaration ) {
IASTDeclarator[] decltors = ((IASTSimpleDeclaration)parms[i]).getDeclarators();
for ( int j = 0; j < decltors.length; j++ ) {
parmTypes[i] = createType(decltors[j].getName(), true);
}
}
}
return parmTypes;
} else {
return null;
}
}
/**
@ -1541,4 +1617,44 @@ public class CVisitor {
return action.getDeclarationNames();
}
private static IBinding resolveKnRParameterBinding(ICASTKnRFunctionDeclarator declarator, IASTName name) {
IASTDeclaration[] parmDeclarations = declarator.getParameterDeclarations();
if ( declarator.getName().resolveBinding() instanceof IFunction ) { // possible to have IASTParameterDeclaration whose parent is an IVariable
IFunction function = (IFunction) declarator.getName().resolveBinding();
if( function.getPhysicalNode() != declarator ) {
IASTDeclaration [] ps = declarator.getParameterDeclarations();
int index = -1;
outerLoop: for( index = 0; index < ps.length; index++ )
for (int j=0; j<parmDeclarations.length; j++)
if( ps[index] == parmDeclarations[j] ) break outerLoop;
List params = function.getParameters();
if( index >= 0 && index < params.size() ){
return (IBinding) params.get( index );
}
}
}
for (int i=0; i<parmDeclarations.length; i++) {
if ( parmDeclarations[i] instanceof IASTSimpleDeclaration ) {
IASTDeclarator[] decltors = ((IASTSimpleDeclaration)parmDeclarations[i]).getDeclarators();
for (int j=0; j<decltors.length; j++) {
if (CharArrayUtils.equals( decltors[j].getName().toCharArray(), name.toCharArray()) ) {
if (decltors[j].getName() instanceof CASTName && ((CASTName)decltors[j].getName()).hasBinding())
return decltors[j].getName().resolveBinding();
return new CKnRParameter( parmDeclarations[i], decltors[j].getName() );
}
}
}
}
// NOTE: without a function prototype a parameter name without a matching declaration currently resolves to a null binding
// i.e. int f(x,y) char x; {} // this compiles/runs, but does not compile when the prototype is included
return null; // nothing found
}
}

View file

@ -42,5 +42,12 @@ public class GCCParserExtensionConfiguration implements
public boolean supportAlignOfUnaryExpression() {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration#supportKRCSyntax()
*/
public boolean supportKnRC() {
return true;
}
}

View file

@ -16,7 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -69,7 +69,7 @@ public class CPPFunction implements IFunction {
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
*/
public List getParameters() {
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarations[0];
IASTStandardFunctionDeclarator dtor = ( definition != null ) ? definition : declarations[0];
IASTParameterDeclaration[] params = dtor.getParameters();
int size = params.length;
List result = new ArrayList( size );
@ -136,7 +136,7 @@ public class CPPFunction implements IFunction {
if( binding != null )
return binding;
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) param.getParent();
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) param.getParent();
IASTParameterDeclaration [] ps = fdtor.getParameters();
int i = 0;
for( ; i < ps.length; i++ ){

View file

@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -742,13 +743,15 @@ public class CPPSemantics {
}
if( checkAux ) {
//check the parameters
IASTParameterDeclaration [] parameters = declarator.getParameters();
for( int i = 0; i < parameters.length; i++ ){
IASTParameterDeclaration parameterDeclaration = parameters[i];
if( parameterDeclaration == null ) break;
declName = parameterDeclaration.getDeclarator().getName();
if( CharArrayUtils.equals( declName.toCharArray(), data.name ) ){
return declName;
if ( declarator instanceof IASTStandardFunctionDeclarator ) {
IASTParameterDeclaration [] parameters = ((IASTStandardFunctionDeclarator)declarator).getParameters();
for( int i = 0; i < parameters.length; i++ ){
IASTParameterDeclaration parameterDeclaration = parameters[i];
if( parameterDeclaration == null ) break;
declName = parameterDeclaration.getDeclarator().getName();
if( CharArrayUtils.equals( declName.toCharArray(), data.name ) ){
return declName;
}
}
}
}

View file

@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
@ -310,7 +311,7 @@ public class CPPVisitor {
}
} else if( parent instanceof IASTParameterDeclaration ){
IASTParameterDeclaration param = (IASTParameterDeclaration) parent;
IASTFunctionDeclarator fDtor = (IASTFunctionDeclarator) param.getParent();
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
IFunction function = (IFunction) fDtor.getName().resolveBinding();
binding = ((CPPFunction) function).resolveParameter( param );
} else if( parent instanceof IASTSimpleDeclaration ){
@ -460,8 +461,8 @@ public class CPPVisitor {
*/
public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) {
IASTNode parent = parameterDeclaration.getParent();
if( parent instanceof IASTFunctionDeclarator ){
IASTFunctionDeclarator functionDeclarator = (IASTFunctionDeclarator) parent;
if( parent instanceof IASTStandardFunctionDeclarator ){
IASTStandardFunctionDeclarator functionDeclarator = (IASTStandardFunctionDeclarator) parent;
if( functionDeclarator.getNestedDeclarator() != null ){
return getContainingScope( functionDeclarator );
}

View file

@ -41,7 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
@ -2613,7 +2613,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
IASTDeclarator declarator = (IASTDeclarator) declarators.get(0);
if (!(declarator instanceof IASTFunctionDeclarator))
if (!(declarator instanceof IASTStandardFunctionDeclarator))
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
if (!constructorChain.isEmpty()
@ -2635,7 +2635,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declSpec.setParent(funcDefinition);
declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER);
funcDefinition.setDeclarator((IASTFunctionDeclarator) declarator);
funcDefinition.setDeclarator((IASTStandardFunctionDeclarator) declarator);
declarator.setParent(funcDefinition);
declarator.setPropertyInParent(IASTFunctionDefinition.DECLARATOR);
@ -3670,7 +3670,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
.get(i);
p.setParent(fc);
p.setPropertyInParent(IASTFunctionDeclarator.FUNCTION_PARAMETER);
p.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER);
fc.addParameterDeclaration(p);
}
fc.setConst(isConst);