[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
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
Although K&R C still isn't fully
supported and the patch needs the following (and will be submitted as a
separate patch):
- getDeclarations(IBinding) support
for K&R C
- check types for K&R C with pointers,
etc
- add test code from GCC Torture tests
(mainly the snavigator/demo/monop project)
- support semantic problems such as
K&R C parameter declaration that has a different type than the prototype
Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada
Index: parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java,v
retrieving revision 1.37
diff -u -r1.37 ParserTestSuite.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java 19 Jan 2005 15:21:33 -0000 1.37
+++ parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java 19 Jan 2005 18:21:34 -0000
@@ -17,6 +17,7 @@
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 @@
suite.addTestSuite( QuickParser2Tests.class );
suite.addTestSuite( CompleteParser2Tests.class );
suite.addTestSuite( DOMLocationTests.class );
+ suite.addTestSuite( AST2KnRTests.class );
return suite;
}
}
Index: parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java,v
retrieving revision 1.13
diff -u -r1.13 AST2BaseTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java 19 Jan 2005 15:21:32 -0000 1.13
+++ parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java 19 Jan 2005 18:21:34 -0000
@@ -45,11 +45,13 @@
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 @@
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 @@
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 @@
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 );
Index: parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java,v
retrieving revision 1.29
diff -u -r1.29 AST2Tests.java
--- parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java 17 Jan 2005 19:07:14 -0000 1.29
+++ parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java 19 Jan 2005 18:21:35 -0000
@@ -27,6 +27,7 @@
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 @@
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 @@
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 @@
//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 @@
//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 @@
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 @@
//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 @@
//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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
{
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() );
Index: parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
diff -N parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,304 @@
+/**********************************************************************
+ * 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 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$
+ }
+
+}
Index: parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java,v
retrieving revision 1.3
diff -u -r1.3 IASTFunctionDeclarator.java
--- parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java 25 Nov 2004 22:07:17 -0000 1.3
+++ parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java 19 Jan 2005 18:20:53 -0000
@@ -18,17 +18,4 @@
*/
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 );
}
Index: parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java,v
retrieving revision 1.4
diff -u -r1.4 ICPPASTFunctionDeclarator.java
--- parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java 7 Dec 2004 01:02:35 -0000 1.4
+++ parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java 19 Jan 2005 18:20:53 -0000
@@ -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 @@
*
* @author Doug Schaefer
*/
-public interface ICPPASTFunctionDeclarator extends IASTFunctionDeclarator {
+public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarator {
public boolean isConst();
Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java,v
retrieving revision 1.1
diff -u -r1.1 CASTFunctionDeclarator.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java 10 Dec 2004 03:53:09 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java 19 Jan 2005 18:20:55 -0000
@@ -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;
Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java,v
retrieving revision 1.4
diff -u -r1.4 CFunction.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java 17 Jan 2005 19:07:16 -0000 1.4
+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java 19 Jan 2005 18:20:55 -0000
@@ -16,6 +16,8 @@
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.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 @@
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 @@
* @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)
Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java,v
retrieving revision 1.10
diff -u -r1.10 CVisitor.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java 17 Jan 2005 19:07:16 -0000 1.10
+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java 19 Jan 2005 18:20:55 -0000
@@ -36,6 +36,7 @@
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.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 @@
}
} 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 @@
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 @@
// 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 @@
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 @@
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 @@
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 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 @@
}
} 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 @@
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 @@
* @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 @@
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
+ }
+
}
Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCParserExtensionConfiguration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCParserExtensionConfiguration.java,v
retrieving revision 1.1
diff -u -r1.1 GCCParserExtensionConfiguration.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCParserExtensionConfiguration.java 10 Dec 2004 03:53:09 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCParserExtensionConfiguration.java 19 Jan 2005 18:20:55 -0000
@@ -42,5 +42,12 @@
public boolean supportAlignOfUnaryExpression() {
return true;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration#supportKRCSyntax()
+ */
+ public boolean supportKnRC() {
+ return true;
+ }
}
Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java,v
retrieving revision 1.15
diff -u -r1.15 GNUCSourceParser.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java 18 Jan 2005 19:46:43 -0000 1.15
+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java 19 Jan 2005 18:20:56 -0000
@@ -41,6 +41,7 @@
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;
@@ -84,6 +85,7 @@
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
+import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IGCCToken;
@@ -92,6 +94,7 @@
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserMode;
+import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
@@ -1700,6 +1703,105 @@
boolean encounteredVarArgs = false;
IASTExpression bitField = null;
boolean isFunction = false;
+
+ int numKnRCParms = 0;
+ if (LT(2) == IToken.tLPAREN)
+ numKnRCParms = countKnRCParms();
+
+ if ( numKnRCParms > 0 ) { // KnR C parameters were found so handle the declarator accordingly
+ if (LT(1) == IToken.tIDENTIFIER) {
+ declaratorName = createName(identifier());
+ } else
+ declaratorName = createName();
+
+ IASTName[] parmNames = new IASTName[numKnRCParms];
+ IASTDeclaration[] parmDeclarations = new IASTDeclaration[numKnRCParms];
+
+ // TODO need to create a temporary scope object here
+ IToken last = consume(IToken.tLPAREN);
+ boolean seenParameter = false;
+ for (int i=0; i<parmNames.length; i++) {
+ switch (LT(1)) {
+ case IToken.tCOMMA:
+ last = consume();
+ seenParameter = false;
+ case IToken.tIDENTIFIER:
+ if (seenParameter)
+ throwBacktrack(startingOffset, last.getEndOffset() - startingOffset);
+
+ parmNames[i] = createName(identifier());
+
+ seenParameter = true;
+ default:
+ break;
+ }
+ }
+
+ if (LT(1) == IToken.tRPAREN)
+ last = consume();
+
+ // now that the parameter names are parsed, parse the parameter declarations
+ for (int i=0; i<numKnRCParms && LT(1) != IToken.tLBRACE; i++) { // max parameter declarations same as parameter name count (could be less)
+ try {
+ boolean hasValidDecltors = true;
+ IASTStatement stmt = parseDeclarationOrExpressionStatement();
+ if ( stmt instanceof IASTDeclarationStatement ) {
+ IASTDeclaration declaration = ((IASTDeclarationStatement)stmt).getDeclaration();
+
+ if (declaration instanceof IASTSimpleDeclaration) {
+ IASTDeclarator[] decltors = ((IASTSimpleDeclaration)declaration).getDeclarators();
+ for (int k=0; k<decltors.length; k++){
+ boolean decltorOk = false;
+ for (int j=0; j<parmNames.length; j++) {
+ if ( CharArrayUtils.equals(decltors[k].getName().toCharArray(), parmNames[j].toCharArray()) ) {
+ decltorOk = true;
+ break;
+ }
+ }
+ if (!decltorOk)
+ hasValidDecltors = false;
+ }
+ }
+ } else {
+ hasValidDecltors = false;
+ }
+
+ if (hasValidDecltors) {
+ parmDeclarations[i] = ((IASTDeclarationStatement)stmt).getDeclaration();
+ } else {
+ parmDeclarations[i] = createKnRCProblemDeclaration(((ASTNode)stmt).getLength(), ((ASTNode)stmt).getOffset());
+ }
+ } catch (BacktrackException b) {
+ parmDeclarations[i] = createKnRCProblemDeclaration(b.getLength(), b.getOffset());
+ }
+
+ }
+
+ ICASTKnRFunctionDeclarator functionDecltor = createKnRFunctionDeclarator();
+ for (int i = 0; i < parmDeclarations.length; ++i) {
+ if (parmDeclarations[i] != null && !(parmDeclarations[i] instanceof IASTProblemDeclaration)) {
+ parmDeclarations[i].setParent(functionDecltor);
+ parmDeclarations[i].setPropertyInParent(ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER);
+ }
+ }
+ functionDecltor.setParameterDeclarations(parmDeclarations);
+ functionDecltor.setParameterNames(parmNames);
+ if (declaratorName != null) {
+ functionDecltor.setName(declaratorName);
+ declaratorName.setParent(functionDecltor);
+ declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
+ }
+
+ for (int i = 0; i < parmNames.length; ++i) {
+ parmNames[i].setParent(functionDecltor);
+ parmNames[i].setPropertyInParent(ICASTKnRFunctionDeclarator.PARAMETER_NAME);
+ }
+
+ return functionDecltor;
+
+ }
+
+
overallLoop: do {
consumePointerOperators(pointerOps);
@@ -1784,13 +1886,13 @@
IASTDeclarator d = null;
if (isFunction) {
- IASTFunctionDeclarator fc = createFunctionDeclarator();
+ IASTStandardFunctionDeclarator fc = createFunctionDeclarator();
fc.setVarArgs(encounteredVarArgs);
for (int i = 0; i < parameters.size(); ++i) {
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
.get(i);
p.setParent(fc);
- p.setPropertyInParent(IASTFunctionDeclarator.FUNCTION_PARAMETER);
+ p.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER);
fc.addParameterDeclaration(p);
}
d = fc;
@@ -1844,11 +1946,18 @@
/**
* @return
*/
- protected IASTFunctionDeclarator createFunctionDeclarator() {
+ protected IASTStandardFunctionDeclarator createFunctionDeclarator() {
return new CASTFunctionDeclarator();
}
/**
+ * @return
+ */
+ protected ICASTKnRFunctionDeclarator createKnRFunctionDeclarator() {
+ return new CASTKnRFunctionDeclarator();
+ }
+
+ /**
* @param t
* @return
*/
@@ -2294,5 +2403,73 @@
((ASTNode) result).setOffsetAndLength(offset, length);
return result;
}
-
+
+ private int countKnRCParms() {
+ IToken mark = null;
+ int parmCount = 0;
+ boolean previousWasIdentifier = false;
+
+ try {
+ mark = mark();
+
+ if (LT(1) == IToken.tIDENTIFIER)
+ consume(); // consume the declarator
+ if (LT(1) == IToken.tLPAREN)
+ consume(); // consume the IToken.tLPAREN
+
+ // starts at the beginning of the parameter list
+ for (;;) {
+ if (LT(1) == IToken.tCOMMA) {
+ consume();
+ previousWasIdentifier = false;
+ } else if (LT(1) == IToken.tIDENTIFIER) {
+ consume();
+ if (previousWasIdentifier==true) {
+ backup(mark);
+ return 0; // i.e. KnR C won't have int f(typedef x) char x; {}
+ }
+ previousWasIdentifier = true;
+ parmCount++;
+ } else if (LT(1) == IToken.tRPAREN) {
+ consume();
+ break;
+ } else {
+ backup(mark);
+ return 0; // i.e. KnR C won't have int f(char) char x; {}
+ }
+ }
+
+ // if the next token is a tSEMI then the declaration was a regular declaration statement i.e. int f(type_def);
+ if (LT(1) == IToken.tSEMI) {
+ backup(mark);
+ return 0;
+ }
+
+ // look ahead for the start of the function body, if end of file is found then return 0 parameters found (implies not KnR C)
+ while (LT(1) != IToken.tLBRACE) { consume(); }
+
+ backup(mark);
+ return parmCount;
+ } catch (EndOfFileException eof) {
+ if (mark != null)
+ backup(mark);
+
+ return 0;
+ }
+ }
+
+ private IASTProblemDeclaration createKnRCProblemDeclaration(int length, int offset) throws EndOfFileException {
+ IASTProblem p = createProblem(IASTProblem.SYNTAX_ERROR, offset, length);
+ IASTProblemDeclaration pd = createProblemDeclaration();
+ pd.setProblem(p);
+ ((ASTNode) pd).setOffsetAndLength(((ASTNode) p).getOffset(), ((ASTNode) p).getLength());
+ p.setParent(pd);
+ p.setPropertyInParent(IASTProblemHolder.PROBLEM);
+
+ // consume until LBRACE is found (to leave off at the function body and continue from there)
+ while (LT(1) != IToken.tLBRACE) consume();
+
+ return pd;
+ }
+
}
Index: parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java,v
retrieving revision 1.4
diff -u -r1.4 CPPFunction.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java 24 Dec 2004 00:13:43 -0000 1.4
+++ parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java 19 Jan 2005 18:20:57 -0000
@@ -16,7 +16,7 @@
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 @@
* @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 @@
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++ ){
Index: parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java,v
retrieving revision 1.8
diff -u -r1.8 CPPSemantics.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java 18 Jan 2005 22:00:09 -0000 1.8
+++ parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java 19 Jan 2005 18:20:57 -0000
@@ -29,6 +29,7 @@
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.IASTName;
@@ -68,6 +69,7 @@
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
+import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectMap;
@@ -742,13 +744,15 @@
}
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;
+ }
}
}
}
Index: parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java,v
retrieving revision 1.15
diff -u -r1.15 CPPVisitor.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java 18 Jan 2005 22:00:09 -0000 1.15
+++ parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java 19 Jan 2005 18:20:57 -0000
@@ -41,6 +41,7 @@
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 @@
}
} 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 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 );
}
Index: parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java,v
retrieving revision 1.12
diff -u -r1.12 GNUCPPSourceParser.java
--- parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java 18 Jan 2005 19:46:43 -0000 1.12
+++ parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java 19 Jan 2005 18:20:58 -0000
@@ -41,7 +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;
@@ -2613,7 +2613,7 @@
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 @@
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 @@
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);
Index: parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java
diff -N parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java 1 Jan 1970 00:00:00 -0000
@@ -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 );
+}
Index: parser/org/eclipse/cdt/core/dom/ast/gnu/c/ICASTKnRFunctionDeclarator.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/dom/ast/gnu/c/ICASTKnRFunctionDeclarator.java
diff -N parser/org/eclipse/cdt/core/dom/ast/gnu/c/ICASTKnRFunctionDeclarator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/dom/ast/gnu/c/ICASTKnRFunctionDeclarator.java 1 Jan 1970 00:00:00 -0000
@@ -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();
+}
Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java
diff -N parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java 1 Jan 1970 00:00:00 -0000
@@ -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;
+ }
+
+}
Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java
diff -N parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java 1 Jan 1970 00:00:00 -0000
@@ -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;
+ }
+
+}