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:
parent
8006bc409b
commit
8d833f012a
19 changed files with 3202 additions and 2293 deletions
|
@ -17,6 +17,7 @@ import junit.framework.TestSuite;
|
||||||
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
||||||
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
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.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.AST2Tests;
|
||||||
import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
|
import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
|
||||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationTests;
|
import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationTests;
|
||||||
|
@ -63,6 +64,7 @@ public class ParserTestSuite extends TestCase {
|
||||||
suite.addTestSuite( QuickParser2Tests.class );
|
suite.addTestSuite( QuickParser2Tests.class );
|
||||||
suite.addTestSuite( CompleteParser2Tests.class );
|
suite.addTestSuite( CompleteParser2Tests.class );
|
||||||
suite.addTestSuite( DOMLocationTests.class );
|
suite.addTestSuite( DOMLocationTests.class );
|
||||||
|
suite.addTestSuite( AST2KnRTests.class );
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ISourceCodeParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration;
|
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.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.GNUCSourceParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
|
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.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
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.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.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
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();
|
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 string
|
||||||
* @param c
|
* @param c
|
||||||
* @return
|
* @return
|
||||||
* @throws ParserException
|
* @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
|
CodeReader codeReader = new CodeReader(code
|
||||||
.toCharArray());
|
.toCharArray());
|
||||||
ScannerInfo scannerInfo = new ScannerInfo();
|
ScannerInfo scannerInfo = new ScannerInfo();
|
||||||
|
@ -85,6 +91,9 @@ public class AST2BaseTest extends TestCase {
|
||||||
if( lang == ParserLanguage.CPP )
|
if( lang == ParserLanguage.CPP )
|
||||||
{
|
{
|
||||||
ICPPParserExtensionConfiguration config = null;
|
ICPPParserExtensionConfiguration config = null;
|
||||||
|
if (useGNUExtensions)
|
||||||
|
config = new GPPParserExtensionConfiguration();
|
||||||
|
else
|
||||||
config = new ANSICPPParserExtensionConfiguration();
|
config = new ANSICPPParserExtensionConfiguration();
|
||||||
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE,
|
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE,
|
||||||
NULL_LOG,
|
NULL_LOG,
|
||||||
|
@ -93,6 +102,10 @@ public class AST2BaseTest extends TestCase {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ICParserExtensionConfiguration config = null;
|
ICParserExtensionConfiguration config = null;
|
||||||
|
|
||||||
|
if (useGNUExtensions)
|
||||||
|
config = new GCCParserExtensionConfiguration();
|
||||||
|
else
|
||||||
config = new ANSICParserExtensionConfiguration();
|
config = new ANSICParserExtensionConfiguration();
|
||||||
|
|
||||||
parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE,
|
parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE,
|
||||||
|
|
|
@ -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$
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.IASTForStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
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$
|
assertEquals("f", name_f.toString()); //$NON-NLS-1$
|
||||||
|
|
||||||
// parameter - int y
|
// 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
|
IASTSimpleDeclSpecifier declspec_y = (IASTSimpleDeclSpecifier) decl_y
|
||||||
.getDeclSpecifier();
|
.getDeclSpecifier();
|
||||||
assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_y.getType());
|
assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_y.getType());
|
||||||
|
@ -629,7 +631,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
IASTName x_1 = typeSpec.getName();
|
IASTName x_1 = typeSpec.getName();
|
||||||
|
|
||||||
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
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();
|
IASTName x_2 = param.getDeclarator().getName();
|
||||||
|
|
||||||
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
|
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
|
||||||
|
@ -692,7 +695,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
|
|
||||||
//void f(
|
//void f(
|
||||||
IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
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();
|
IASTName f_name1 = dtor.getName();
|
||||||
// int a );
|
// int a );
|
||||||
IASTParameterDeclaration param1 = dtor.getParameters()[0];
|
IASTParameterDeclaration param1 = dtor.getParameters()[0];
|
||||||
|
@ -701,7 +704,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
|
|
||||||
//void f(
|
//void f(
|
||||||
IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
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();
|
IASTName f_name2 = dtor.getName();
|
||||||
// int b );
|
// int b );
|
||||||
IASTParameterDeclaration param2 = dtor.getParameters()[0];
|
IASTParameterDeclaration param2 = dtor.getParameters()[0];
|
||||||
|
@ -764,7 +768,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
|
||||||
|
|
||||||
IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations()[0];
|
IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||||
IASTFunctionDeclarator fDtor = fDef.getDeclarator();
|
assertTrue(fDef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
|
||||||
|
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator)fDef.getDeclarator();
|
||||||
IASTName fName = fDtor.getName();
|
IASTName fName = fDtor.getName();
|
||||||
|
|
||||||
IASTParameterDeclaration a = fDtor.getParameters()[0];
|
IASTParameterDeclaration a = fDtor.getParameters()[0];
|
||||||
|
@ -812,7 +817,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
|
|
||||||
//void f();
|
//void f();
|
||||||
IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||||
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) fdecl.getDeclarators()[0];
|
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) fdecl.getDeclarators()[0];
|
||||||
IASTName name_f = fdtor.getName();
|
IASTName name_f = fdtor.getName();
|
||||||
|
|
||||||
//void g() {
|
//void g() {
|
||||||
|
@ -828,7 +833,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
|
|
||||||
//void f() {}
|
//void f() {}
|
||||||
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[2];
|
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[2];
|
||||||
fdtor = fdef.getDeclarator();
|
assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
|
||||||
|
fdtor = (IASTStandardFunctionDeclarator)fdef.getDeclarator();
|
||||||
IASTName name_fdef = fdtor.getName();
|
IASTName name_fdef = fdtor.getName();
|
||||||
|
|
||||||
//bindings
|
//bindings
|
||||||
|
@ -1024,8 +1030,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration)tu.getDeclarations()[1];
|
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration)tu.getDeclarations()[1];
|
||||||
IASTName name_X1 = decl1.getDeclarators()[0].getName();
|
IASTName name_X1 = decl1.getDeclarators()[0].getName();
|
||||||
IASTName name_f = decl2.getDeclarators()[0].getName();
|
IASTName name_f = decl2.getDeclarators()[0].getName();
|
||||||
IASTName name_X2 = ((IASTNamedTypeSpecifier)((IASTFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
|
IASTName name_X2 = ((IASTNamedTypeSpecifier)((IASTStandardFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
|
||||||
IASTName name_x = ((IASTFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
IASTName name_x = ((IASTStandardFunctionDeclarator)decl2.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
||||||
|
|
||||||
IASTName[] decls = tu.getDeclarations(name_X1.resolveBinding());
|
IASTName[] decls = tu.getDeclarations(name_X1.resolveBinding());
|
||||||
assertEquals( decls.length, 1 );
|
assertEquals( decls.length, 1 );
|
||||||
|
@ -1207,7 +1213,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals( tu.getDeclarations().length, 1 );
|
assertEquals( tu.getDeclarations().length, 1 );
|
||||||
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||||
assertEquals( d.getDeclarators().length, 1 );
|
assertEquals( d.getDeclarators().length, 1 );
|
||||||
IASTFunctionDeclarator f = (IASTFunctionDeclarator) d.getDeclarators()[0];
|
IASTStandardFunctionDeclarator f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
|
||||||
assertNull( f.getName().toString() );
|
assertNull( f.getName().toString() );
|
||||||
assertNotNull( f.getNestedDeclarator() );
|
assertNotNull( f.getNestedDeclarator() );
|
||||||
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
||||||
|
@ -1223,7 +1229,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals( tu.getDeclarations().length, 1 );
|
assertEquals( tu.getDeclarations().length, 1 );
|
||||||
d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||||
assertEquals( d.getDeclarators().length, 1 );
|
assertEquals( d.getDeclarators().length, 1 );
|
||||||
f = (IASTFunctionDeclarator) d.getDeclarators()[0];
|
f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
|
||||||
assertNull( f.getName().toString() );
|
assertNull( f.getName().toString() );
|
||||||
assertNotNull( f.getNestedDeclarator() );
|
assertNotNull( f.getNestedDeclarator() );
|
||||||
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
||||||
|
@ -1521,19 +1527,19 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||||
IFunction f = (IFunction) decl.getDeclarators()[0].getName().resolveBinding();
|
IFunction f = (IFunction) decl.getDeclarators()[0].getName().resolveBinding();
|
||||||
IASTName name_f = decl.getDeclarators()[0].getName();
|
IASTName name_f = decl.getDeclarators()[0].getName();
|
||||||
IASTName name_i = ((IASTFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
IASTName name_i = ((IASTStandardFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
||||||
IASTName name_c = ((IASTFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[1].getDeclarator().getName();
|
IASTName name_c = ((IASTStandardFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[1].getDeclarator().getName();
|
||||||
|
|
||||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
|
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
|
||||||
IVariable g = (IVariable) decl.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding();
|
IVariable g = (IVariable) decl.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding();
|
||||||
IASTName name_g = decl.getDeclarators()[0].getNestedDeclarator().getName();
|
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];
|
decl = (IASTSimpleDeclaration) tu.getDeclarations()[3];
|
||||||
IVariable h = (IVariable) decl.getDeclarators()[0].getNestedDeclarator().getNestedDeclarator().getName().resolveBinding();
|
IVariable h = (IVariable) decl.getDeclarators()[0].getNestedDeclarator().getNestedDeclarator().getName().resolveBinding();
|
||||||
IASTName name_h = decl.getDeclarators()[0].getNestedDeclarator().getNestedDeclarator().getName();
|
IASTName name_h = decl.getDeclarators()[0].getNestedDeclarator().getNestedDeclarator().getName();
|
||||||
IASTName name_A3 = ((IASTElaboratedTypeSpecifier)((IASTFunctionDeclarator)decl.getDeclarators()[0].getNestedDeclarator()).getParameters()[0].getDeclSpecifier()).getName();
|
IASTName name_A3 = ((IASTElaboratedTypeSpecifier)((IASTStandardFunctionDeclarator)decl.getDeclarators()[0].getNestedDeclarator()).getParameters()[0].getDeclSpecifier()).getName();
|
||||||
IASTName name_d = ((IASTFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
IASTName name_d = ((IASTStandardFunctionDeclarator)decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
||||||
|
|
||||||
IFunctionType t_f = f.getType();
|
IFunctionType t_f = f.getType();
|
||||||
IType t_f_return = t_f.getReturnType();
|
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 s t;\n" ); //$NON-NLS-1$
|
||||||
buffer.append( "typedef t y;\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$
|
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 S_decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
|
||||||
IASTSimpleDeclaration x_decl = (IASTSimpleDeclaration)tu.getDeclarations()[3];
|
IASTSimpleDeclaration x_decl = (IASTSimpleDeclaration)tu.getDeclarations()[3];
|
||||||
|
@ -1827,7 +1833,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertTrue( ((IPointerType)ft.getParameterTypes()[0]).isConst() );
|
assertTrue( ((IPointerType)ft.getParameterTypes()[0]).isConst() );
|
||||||
|
|
||||||
// test tu.getDeclarations(IBinding)
|
// 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());
|
IASTName[] decls = tu.getDeclarations(name_parm.resolveBinding());
|
||||||
assertEquals( decls.length, 1 );
|
assertEquals( decls.length, 1 );
|
||||||
assertEquals( decls[0], name_parm );
|
assertEquals( decls[0], name_parm );
|
||||||
|
@ -1892,7 +1898,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals( ((IBasicType)gt_parm).getType(), IBasicType.t_void );
|
assertEquals( ((IBasicType)gt_parm).getType(), IBasicType.t_void );
|
||||||
|
|
||||||
// test tu.getDeclarations(IBinding)
|
// 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 name_g_call = ((IASTIdExpression)((IASTFunctionCallExpression)((IASTReturnStatement)((IASTCompoundStatement)def.getBody()).getStatements()[0]).getReturnValue()).getFunctionNameExpression()).getName();
|
||||||
IASTName[] decls = tu.getDeclarations(name_g_call.resolveBinding());
|
IASTName[] decls = tu.getDeclarations(name_g_call.resolveBinding());
|
||||||
assertEquals( decls.length, 1 );
|
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$
|
IASTTranslationUnit tu = parse( "int (*v[])(int *x, int *y);", ParserLanguage.C ); //$NON-NLS-1$
|
||||||
|
|
||||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
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();
|
IType vt_1 = v.getType();
|
||||||
assertTrue( vt_1 instanceof IArrayType );
|
assertTrue( vt_1 instanceof IArrayType );
|
||||||
|
@ -1927,9 +1934,9 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals( ((IBasicType)vpt_2_2).getType(), IBasicType.t_int );
|
assertEquals( ((IBasicType)vpt_2_2).getType(), IBasicType.t_int );
|
||||||
|
|
||||||
// test tu.getDeclarations(IBinding)
|
// 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.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 {
|
public void testTypedefExample4a() throws Exception {
|
||||||
|
@ -2043,7 +2050,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
// test tu.getDeclarations(IBinding)
|
// test tu.getDeclarations(IBinding)
|
||||||
IASTName name_pfv = decl2.getDeclarators()[0].getNestedDeclarator().getName();
|
IASTName name_pfv = decl2.getDeclarators()[0].getNestedDeclarator().getName();
|
||||||
IASTName name_pfv1 = ((IASTNamedTypeSpecifier)decl3.getDeclSpecifier()).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());
|
IASTName[] decls = tu.getDeclarations(name_pfv1.resolveBinding());
|
||||||
assertEquals( decls.length, 1 );
|
assertEquals( decls.length, 1 );
|
||||||
|
@ -2118,7 +2125,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
{
|
{
|
||||||
StringBuffer buffer =new StringBuffer(); //$NON-NLS-1$
|
StringBuffer buffer =new StringBuffer(); //$NON-NLS-1$
|
||||||
buffer.append( "int y ( int [ const *] );"); //$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.isConst() );
|
||||||
assertTrue( mod.isVariableSized() );
|
assertTrue( mod.isVariableSized() );
|
||||||
assertFalse( mod.isStatic() );
|
assertFalse( mod.isStatic() );
|
||||||
|
|
|
@ -18,17 +18,4 @@ package org.eclipse.cdt.core.dom.ast;
|
||||||
*/
|
*/
|
||||||
public interface IASTFunctionDeclarator extends IASTDeclarator {
|
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 );
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 );
|
||||||
|
}
|
|
@ -11,7 +11,7 @@
|
||||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
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;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
*
|
*
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*/
|
*/
|
||||||
public interface ICPPASTFunctionDeclarator extends IASTFunctionDeclarator {
|
public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarator {
|
||||||
|
|
||||||
|
|
||||||
public boolean isConst();
|
public boolean isConst();
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -9,14 +9,14 @@
|
||||||
* IBM Rational Software - Initial API and implementation */
|
* IBM Rational Software - Initial API and implementation */
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
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;
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class CASTFunctionDeclarator extends CASTDeclarator implements
|
public class CASTFunctionDeclarator extends CASTDeclarator implements
|
||||||
IASTFunctionDeclarator {
|
IASTStandardFunctionDeclarator {
|
||||||
|
|
||||||
private IASTParameterDeclaration [] parameters = null;
|
private IASTParameterDeclaration [] parameters = null;
|
||||||
private static final int DEFAULT_PARAMETERS_LIST_SIZE = 2;
|
private static final int DEFAULT_PARAMETERS_LIST_SIZE = 2;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,6 +16,8 @@ import java.util.List;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
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.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created on Nov 5, 2004
|
* Created on Nov 5, 2004
|
||||||
|
@ -45,7 +48,7 @@ public class CFunction implements IFunction {
|
||||||
return ( definition != null ) ? definition : declarators[0];
|
return ( definition != null ) ? definition : declarators[0];
|
||||||
}
|
}
|
||||||
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
|
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
|
||||||
if( fnDeclarator instanceof IASTFunctionDefinition )
|
if( fnDeclarator instanceof IASTFunctionDefinition || fnDeclarator instanceof ICASTKnRFunctionDeclarator )
|
||||||
definition = fnDeclarator;
|
definition = fnDeclarator;
|
||||||
else {
|
else {
|
||||||
if( declarators == null ){
|
if( declarators == null ){
|
||||||
|
@ -80,16 +83,36 @@ public class CFunction implements IFunction {
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||||
*/
|
*/
|
||||||
public List getParameters() {
|
public List getParameters() {
|
||||||
|
List result = null;
|
||||||
|
|
||||||
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
|
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
|
||||||
IASTParameterDeclaration[] params = dtor.getParameters();
|
if (dtor instanceof IASTStandardFunctionDeclarator) {
|
||||||
|
IASTParameterDeclaration[] params = ((IASTStandardFunctionDeclarator)dtor).getParameters();
|
||||||
int size = params.length;
|
int size = params.length;
|
||||||
List result = new ArrayList( size );
|
result = new ArrayList( size );
|
||||||
if( size > 0 ){
|
if( size > 0 ){
|
||||||
for( int i = 0; i < size; i++ ){
|
for( int i = 0; i < size; i++ ){
|
||||||
IASTParameterDeclaration p = params[i];
|
IASTParameterDeclaration p = params[i];
|
||||||
result.add( p.getDeclarator().getName().resolveBinding() );
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.IASTForStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
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.ICFunctionScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICScope;
|
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.IGNUASTCompoundStatementExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||||
|
|
||||||
|
@ -297,7 +299,8 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
} else if ( parent instanceof IASTSimpleDeclaration ) {
|
} else if ( parent instanceof IASTSimpleDeclaration ) {
|
||||||
if ( (declarator.getName() != null && declarator.getName().resolveBinding() == binding) ) {
|
if ( (declarator.getName() != null && declarator.getName().resolveBinding() == binding) ) {
|
||||||
if ( declarator instanceof IASTFunctionDeclarator ) {
|
if ( declarator instanceof IASTStandardFunctionDeclarator ||
|
||||||
|
declarator instanceof ICASTKnRFunctionDeclarator ) {
|
||||||
functionDeclared = true;
|
functionDeclared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,12 +500,30 @@ public class CVisitor {
|
||||||
private static IBinding createBinding(IASTDeclarator declarator, IASTName name) {
|
private static IBinding createBinding(IASTDeclarator declarator, IASTName name) {
|
||||||
IBinding binding = null;
|
IBinding binding = null;
|
||||||
IASTNode parent = declarator.getParent();
|
IASTNode parent = declarator.getParent();
|
||||||
if( declarator instanceof IASTFunctionDeclarator ){
|
if( declarator instanceof IASTStandardFunctionDeclarator ){
|
||||||
binding = resolveBinding( parent, CURRENT_SCOPE );
|
binding = resolveBinding( parent, CURRENT_SCOPE );
|
||||||
if( binding != null )
|
if( binding != null ) {
|
||||||
((CFunction)binding).addDeclarator( (IASTFunctionDeclarator) declarator );
|
((CFunction)binding).addDeclarator( (IASTStandardFunctionDeclarator) declarator );
|
||||||
else
|
} else {
|
||||||
binding = createBinding(declarator);
|
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 ){
|
} else if( parent instanceof IASTSimpleDeclaration ){
|
||||||
binding = createBinding( (IASTSimpleDeclaration) parent, name );
|
binding = createBinding( (IASTSimpleDeclaration) parent, name );
|
||||||
} else if( parent instanceof IASTParameterDeclaration ){
|
} 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
|
// 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.
|
// identifier has block scope, which terminates at the end of the associated block.
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
if ( parent instanceof IASTFunctionDeclarator ) {
|
if ( parent instanceof IASTStandardFunctionDeclarator ) {
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
if ( parent instanceof IASTFunctionDefinition ) {
|
if ( parent instanceof IASTFunctionDefinition ) {
|
||||||
ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
|
ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
|
||||||
|
@ -598,7 +619,13 @@ public class CVisitor {
|
||||||
CScope scope = (CScope) CVisitor.getContainingScope( simpleDeclaration );
|
CScope scope = (CScope) CVisitor.getContainingScope( simpleDeclaration );
|
||||||
binding = scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, name.toCharArray() );
|
binding = scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, name.toCharArray() );
|
||||||
if( binding == null ){
|
if( binding == null ){
|
||||||
|
// 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 );
|
binding = new CVariable( name );
|
||||||
|
}
|
||||||
|
|
||||||
scope.addBinding( binding );
|
scope.addBinding( binding );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -637,7 +664,7 @@ public class CVisitor {
|
||||||
return findBinding( blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits );
|
return findBinding( blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits );
|
||||||
} else if( node instanceof IASTParameterDeclaration ){
|
} else if( node instanceof IASTParameterDeclaration ){
|
||||||
IASTParameterDeclaration param = (IASTParameterDeclaration) node;
|
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
|
if ( fDtor.getName().resolveBinding() instanceof IFunction ) { // possible to have IASTParameterDeclaration whose parent is an IVariable
|
||||||
IFunction function = (IFunction) fDtor.getName().resolveBinding();
|
IFunction function = (IFunction) fDtor.getName().resolveBinding();
|
||||||
|
@ -733,6 +760,14 @@ public class CVisitor {
|
||||||
return ((IASTForStatement)parent).getScope();
|
return ((IASTForStatement)parent).getScope();
|
||||||
} else if( parent instanceof IASTCompositeTypeSpecifier ){
|
} else if( parent instanceof IASTCompositeTypeSpecifier ){
|
||||||
return ((IASTCompositeTypeSpecifier)parent).getScope();
|
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;
|
return null;
|
||||||
|
@ -773,7 +808,7 @@ public class CVisitor {
|
||||||
*/
|
*/
|
||||||
public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) {
|
public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) {
|
||||||
IASTNode parent = parameterDeclaration.getParent();
|
IASTNode parent = parameterDeclaration.getParent();
|
||||||
if( parent instanceof IASTFunctionDeclarator ){
|
if( parent instanceof IASTStandardFunctionDeclarator ){
|
||||||
parent = ((IASTDeclarator)parent).getParent();
|
parent = ((IASTDeclarator)parent).getParent();
|
||||||
if ( parent instanceof IASTFunctionDefinition ) {
|
if ( parent instanceof IASTFunctionDefinition ) {
|
||||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
|
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
|
||||||
|
@ -917,6 +952,8 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
} else if( declaration instanceof IASTFunctionDefinition ){
|
} else if( declaration instanceof IASTFunctionDefinition ){
|
||||||
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
|
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
|
||||||
|
|
||||||
|
if (functionDef.getDeclarator() instanceof IASTStandardFunctionDeclarator) {
|
||||||
CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) functionDef.getDeclarator();
|
CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) functionDef.getDeclarator();
|
||||||
|
|
||||||
//check the function itself
|
//check the function itself
|
||||||
|
@ -934,6 +971,28 @@ public class CVisitor {
|
||||||
return declName.resolveBinding();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1063,8 +1122,8 @@ public class CVisitor {
|
||||||
if( declarator.getInitializer() != null )
|
if( declarator.getInitializer() != null )
|
||||||
if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
|
if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
|
||||||
|
|
||||||
if( declarator instanceof IASTFunctionDeclarator ){
|
if( declarator instanceof IASTStandardFunctionDeclarator ){
|
||||||
IASTParameterDeclaration [] list = ((IASTFunctionDeclarator)declarator).getParameters();
|
IASTParameterDeclaration [] list = ((IASTStandardFunctionDeclarator)declarator).getParameters();
|
||||||
for( int i = 0; i < list.length; i++ ){
|
for( int i = 0; i < list.length; i++ ){
|
||||||
IASTParameterDeclaration param = list[i];
|
IASTParameterDeclaration param = list[i];
|
||||||
if( !visitDeclSpecifier( param.getDeclSpecifier(), action ) ) return false;
|
if( !visitDeclSpecifier( param.getDeclSpecifier(), action ) ) return false;
|
||||||
|
@ -1425,13 +1484,30 @@ public class CVisitor {
|
||||||
* @return IType[] corresponding to the IASTFunctionDeclarator parameters
|
* @return IType[] corresponding to the IASTFunctionDeclarator parameters
|
||||||
*/
|
*/
|
||||||
private static IType[] getParmTypes( IASTFunctionDeclarator decltor ){
|
private static IType[] getParmTypes( IASTFunctionDeclarator decltor ){
|
||||||
IASTParameterDeclaration parms[] = decltor.getParameters();
|
if ( decltor instanceof IASTStandardFunctionDeclarator ) {
|
||||||
|
IASTParameterDeclaration parms[] = ((IASTStandardFunctionDeclarator)decltor).getParameters();
|
||||||
IType parmTypes[] = new IType[parms.length];
|
IType parmTypes[] = new IType[parms.length];
|
||||||
|
|
||||||
for( int i = 0; i < parms.length; i++ ){
|
for( int i = 0; i < parms.length; i++ ){
|
||||||
parmTypes[i] = createType(parms[i].getDeclarator().getName(), true);
|
parmTypes[i] = createType(parms[i].getDeclarator().getName(), true);
|
||||||
}
|
}
|
||||||
return parmTypes;
|
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();
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,4 +43,11 @@ public class GCCParserExtensionConfiguration implements
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration#supportKRCSyntax()
|
||||||
|
*/
|
||||||
|
public boolean supportKnRC() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.IASTForStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
|
@ -84,6 +85,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
|
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.c.ICASTTypedefNameSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
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.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||||
|
@ -92,6 +94,7 @@ import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
import org.eclipse.cdt.core.parser.ParseError;
|
import org.eclipse.cdt.core.parser.ParseError;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
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.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
|
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
|
||||||
|
@ -171,9 +174,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
((CASTNode) newDesignators.get(0)).getOffset(),
|
((CASTNode) newDesignators.get(0)).getOffset(),
|
||||||
((CASTNode) newDesignators.get(0)).getLength());
|
((CASTNode) newDesignators.get(0)).getLength());
|
||||||
for (int i = 0; i < newDesignators.size(); ++i) {
|
for (int i = 0; i < newDesignators.size(); ++i) {
|
||||||
ICASTDesignator d = (ICASTDesignator) newDesignators.get(i);
|
ICASTDesignator d = (ICASTDesignator) newDesignators
|
||||||
|
.get(i);
|
||||||
d.setParent(desigInitializer);
|
d.setParent(desigInitializer);
|
||||||
d.setPropertyInParent(ICASTDesignatedInitializer.DESIGNATOR);
|
d
|
||||||
|
.setPropertyInParent(ICASTDesignatedInitializer.DESIGNATOR);
|
||||||
desigInitializer.addDesignator(d);
|
desigInitializer.addDesignator(d);
|
||||||
}
|
}
|
||||||
desigInitializer.setOperandInitializer(initializer);
|
desigInitializer.setOperandInitializer(initializer);
|
||||||
|
@ -214,8 +219,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTExpression assignmentExpression = assignmentExpression();
|
IASTExpression assignmentExpression = assignmentExpression();
|
||||||
IASTInitializerExpression result = createInitializerExpression();
|
IASTInitializerExpression result = createInitializerExpression();
|
||||||
result.setExpression(assignmentExpression);
|
result.setExpression(assignmentExpression);
|
||||||
((ASTNode) result).setOffsetAndLength(((ASTNode) assignmentExpression)
|
((ASTNode) result).setOffsetAndLength(
|
||||||
.getOffset(), ((ASTNode) assignmentExpression).getLength());
|
((ASTNode) assignmentExpression).getOffset(),
|
||||||
|
((ASTNode) assignmentExpression).getLength());
|
||||||
assignmentExpression.setParent(result);
|
assignmentExpression.setParent(result);
|
||||||
assignmentExpression
|
assignmentExpression
|
||||||
.setPropertyInParent(IASTInitializerExpression.INITIALIZER_EXPRESSION);
|
.setPropertyInParent(IASTInitializerExpression.INITIALIZER_EXPRESSION);
|
||||||
|
@ -266,17 +272,19 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
n.setParent(designator);
|
n.setParent(designator);
|
||||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
designatorList = new ArrayList(
|
||||||
|
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
} else if (LT(1) == IToken.tLBRACKET) {
|
} else if (LT(1) == IToken.tLBRACKET) {
|
||||||
IToken mark = consume(IToken.tLBRACKET);
|
IToken mark = consume(IToken.tLBRACKET);
|
||||||
int offset = mark.getOffset();
|
int offset = mark.getOffset();
|
||||||
IASTExpression constantExpression = expression();
|
IASTExpression constantExpression = expression();
|
||||||
if (LT(1) == IToken.tRBRACKET) {
|
if (LT(1) == IToken.tRBRACKET) {
|
||||||
int lastOffset = consume(IToken.tRBRACKET).getEndOffset();
|
int lastOffset = consume(IToken.tRBRACKET)
|
||||||
|
.getEndOffset();
|
||||||
ICASTArrayDesignator designator = createArrayDesignator();
|
ICASTArrayDesignator designator = createArrayDesignator();
|
||||||
((ASTNode) designator).setOffsetAndLength(offset, lastOffset
|
((ASTNode) designator).setOffsetAndLength(offset,
|
||||||
- offset);
|
lastOffset - offset);
|
||||||
designator.setSubscriptExpression(constantExpression);
|
designator.setSubscriptExpression(constantExpression);
|
||||||
constantExpression.setParent(designator);
|
constantExpression.setParent(designator);
|
||||||
constantExpression
|
constantExpression
|
||||||
|
@ -293,7 +301,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTExpression constantExpression1 = expression();
|
IASTExpression constantExpression1 = expression();
|
||||||
consume(IToken.tELLIPSIS);
|
consume(IToken.tELLIPSIS);
|
||||||
IASTExpression constantExpression2 = expression();
|
IASTExpression constantExpression2 = expression();
|
||||||
int lastOffset = consume(IToken.tRBRACKET).getEndOffset();
|
int lastOffset = consume(IToken.tRBRACKET)
|
||||||
|
.getEndOffset();
|
||||||
IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator();
|
IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator();
|
||||||
((ASTNode) designator).setOffsetAndLength(startOffset,
|
((ASTNode) designator).setOffsetAndLength(startOffset,
|
||||||
lastOffset - startOffset);
|
lastOffset - startOffset);
|
||||||
|
@ -315,15 +324,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken identifier = identifier();
|
IToken identifier = identifier();
|
||||||
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
||||||
ICASTFieldDesignator designator = createFieldDesignator();
|
ICASTFieldDesignator designator = createFieldDesignator();
|
||||||
((ASTNode) designator).setOffsetAndLength(
|
((ASTNode) designator).setOffsetAndLength(identifier
|
||||||
identifier.getOffset(), lastOffset
|
.getOffset(), lastOffset - identifier.getOffset());
|
||||||
- identifier.getOffset());
|
|
||||||
IASTName n = createName(identifier);
|
IASTName n = createName(identifier);
|
||||||
designator.setName(n);
|
designator.setName(n);
|
||||||
n.setParent(designator);
|
n.setParent(designator);
|
||||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
designatorList = new ArrayList(
|
||||||
|
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,15 +344,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken identifier = identifier();
|
IToken identifier = identifier();
|
||||||
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
||||||
ICASTFieldDesignator designator = createFieldDesignator();
|
ICASTFieldDesignator designator = createFieldDesignator();
|
||||||
((ASTNode) designator).setOffsetAndLength(
|
((ASTNode) designator).setOffsetAndLength(identifier
|
||||||
identifier.getOffset(), lastOffset
|
.getOffset(), lastOffset - identifier.getOffset());
|
||||||
- identifier.getOffset());
|
|
||||||
IASTName n = createName(identifier);
|
IASTName n = createName(identifier);
|
||||||
designator.setName(n);
|
designator.setName(n);
|
||||||
n.setParent(designator);
|
n.setParent(designator);
|
||||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
designatorList = new ArrayList(
|
||||||
|
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
} else if (LT(1) == IToken.tLBRACKET) {
|
} else if (LT(1) == IToken.tLBRACKET) {
|
||||||
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
||||||
|
@ -363,7 +372,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
constantExpression2
|
constantExpression2
|
||||||
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION);
|
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
designatorList = new ArrayList(
|
||||||
|
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -489,8 +499,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
int length = figureEndOffset(declSpec, declarators) - firstOffset;
|
int length = figureEndOffset(declSpec, declarators) - firstOffset;
|
||||||
if (consumedSemi)
|
if (consumedSemi)
|
||||||
length = semiOffset - firstOffset;
|
length = semiOffset - firstOffset;
|
||||||
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset,
|
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset, length);
|
||||||
length);
|
|
||||||
simpleDeclaration.setDeclSpecifier(declSpec);
|
simpleDeclaration.setDeclSpecifier(declSpec);
|
||||||
declSpec.setParent(simpleDeclaration);
|
declSpec.setParent(simpleDeclaration);
|
||||||
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
||||||
|
@ -573,15 +582,17 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTProblem p = failParse(b);
|
IASTProblem p = failParse(b);
|
||||||
IASTProblemDeclaration pd = createProblemDeclaration();
|
IASTProblemDeclaration pd = createProblemDeclaration();
|
||||||
pd.setProblem(p);
|
pd.setProblem(p);
|
||||||
((CASTNode) pd).setOffsetAndLength(((CASTNode) p).getOffset(),
|
((CASTNode) pd).setOffsetAndLength(((CASTNode) p)
|
||||||
((CASTNode) p).getLength());
|
.getOffset(), ((CASTNode) p).getLength());
|
||||||
p.setParent(pd);
|
p.setParent(pd);
|
||||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||||
pd.setParent(translationUnit);
|
pd.setParent(translationUnit);
|
||||||
pd.setPropertyInParent(IASTTranslationUnit.OWNED_DECLARATION);
|
pd
|
||||||
|
.setPropertyInParent(IASTTranslationUnit.OWNED_DECLARATION);
|
||||||
translationUnit.addDeclaration(pd);
|
translationUnit.addDeclaration(pd);
|
||||||
errorHandling();
|
errorHandling();
|
||||||
if (lastBacktrack != -1 && lastBacktrack == LA(1).hashCode()) {
|
if (lastBacktrack != -1
|
||||||
|
&& lastBacktrack == LA(1).hashCode()) {
|
||||||
// we haven't progressed from the
|
// we haven't progressed from the
|
||||||
// last backtrack
|
// last backtrack
|
||||||
// try and find tne next definition
|
// try and find tne next definition
|
||||||
|
@ -641,7 +652,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
conditionalExpression);
|
conditionalExpression);
|
||||||
case IToken.tSTARASSIGN:
|
case IToken.tSTARASSIGN:
|
||||||
return assignmentOperatorExpression(
|
return assignmentOperatorExpression(
|
||||||
IASTBinaryExpression.op_multiplyAssign, conditionalExpression);
|
IASTBinaryExpression.op_multiplyAssign,
|
||||||
|
conditionalExpression);
|
||||||
case IToken.tDIVASSIGN:
|
case IToken.tDIVASSIGN:
|
||||||
return assignmentOperatorExpression(
|
return assignmentOperatorExpression(
|
||||||
IASTBinaryExpression.op_divideAssign, conditionalExpression);
|
IASTBinaryExpression.op_divideAssign, conditionalExpression);
|
||||||
|
@ -672,7 +684,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
conditionalExpression);
|
conditionalExpression);
|
||||||
case IToken.tBITORASSIGN:
|
case IToken.tBITORASSIGN:
|
||||||
return assignmentOperatorExpression(
|
return assignmentOperatorExpression(
|
||||||
IASTBinaryExpression.op_binaryOrAssign, conditionalExpression);
|
IASTBinaryExpression.op_binaryOrAssign,
|
||||||
|
conditionalExpression);
|
||||||
}
|
}
|
||||||
return conditionalExpression;
|
return conditionalExpression;
|
||||||
}
|
}
|
||||||
|
@ -897,8 +910,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTTypeId t = typeId(false);
|
IASTTypeId t = typeId(false);
|
||||||
int lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
int lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST);
|
IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST);
|
||||||
firstExpression = buildTypeIdInitializerExpression(t, i, offset,
|
firstExpression = buildTypeIdInitializerExpression(t, i,
|
||||||
lastOffset);
|
offset, lastOffset);
|
||||||
break;
|
break;
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(m);
|
backup(m);
|
||||||
|
@ -1530,8 +1543,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* "}"
|
* "}"
|
||||||
*
|
*
|
||||||
* @param owner
|
* @param owner
|
||||||
* IParserCallback object that represents the declaration that owns
|
* IParserCallback object that represents the declaration that
|
||||||
* this classSpecifier
|
* owns this classSpecifier
|
||||||
*
|
*
|
||||||
* @return TODO
|
* @return TODO
|
||||||
* @throws BacktrackException
|
* @throws BacktrackException
|
||||||
|
@ -1700,12 +1713,16 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
boolean encounteredVarArgs = false;
|
boolean encounteredVarArgs = false;
|
||||||
IASTExpression bitField = null;
|
IASTExpression bitField = null;
|
||||||
boolean isFunction = false;
|
boolean isFunction = false;
|
||||||
|
IASTName[] parmNames = null;
|
||||||
|
IASTDeclaration[] parmDeclarations = null;
|
||||||
|
int numKnRCParms = 0;
|
||||||
|
|
||||||
overallLoop: do {
|
overallLoop: do {
|
||||||
|
|
||||||
consumePointerOperators(pointerOps);
|
consumePointerOperators(pointerOps);
|
||||||
if( ! pointerOps.isEmpty() )
|
if (!pointerOps.isEmpty()) {
|
||||||
{
|
finalOffset = calculateEndOffset((IASTPointerOperator) pointerOps
|
||||||
finalOffset = calculateEndOffset( (IASTPointerOperator) pointerOps.get( pointerOps.size() - 1 ) );
|
.get(pointerOps.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LT(1) == IToken.tLPAREN) {
|
if (LT(1) == IToken.tLPAREN) {
|
||||||
|
@ -1729,6 +1746,97 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
finalOffset = last.getEndOffset();
|
finalOffset = last.getEndOffset();
|
||||||
isFunction = true;
|
isFunction = true;
|
||||||
boolean seenParameter = false;
|
boolean seenParameter = false;
|
||||||
|
|
||||||
|
// count the number of K&R C parameters (0 K&R C parameters
|
||||||
|
// essentially means it's not K&R C)
|
||||||
|
numKnRCParms = countKnRCParms();
|
||||||
|
|
||||||
|
if (numKnRCParms > 0) { // KnR C parameters were found so
|
||||||
|
// handle the declarator accordingly
|
||||||
|
parmNames = new IASTName[numKnRCParms];
|
||||||
|
parmDeclarations = new IASTDeclaration[numKnRCParms];
|
||||||
|
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
case IToken.tRPAREN:
|
||||||
|
last = consume();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break overallLoop;
|
||||||
|
}
|
||||||
|
|
||||||
parameterDeclarationLoop: for (;;) {
|
parameterDeclarationLoop: for (;;) {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tRPAREN:
|
case IToken.tRPAREN:
|
||||||
|
@ -1766,7 +1874,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
||||||
consumeArrayModifiers(arrayMods);
|
consumeArrayModifiers(arrayMods);
|
||||||
if (!arrayMods.isEmpty())
|
if (!arrayMods.isEmpty())
|
||||||
finalOffset = calculateEndOffset((IASTArrayModifier) arrayMods.get( arrayMods.size() - 1 ));
|
finalOffset = calculateEndOffset((IASTArrayModifier) arrayMods
|
||||||
|
.get(arrayMods.size() - 1));
|
||||||
continue;
|
continue;
|
||||||
case IToken.tCOLON:
|
case IToken.tCOLON:
|
||||||
consume(IToken.tCOLON);
|
consume(IToken.tCOLON);
|
||||||
|
@ -1783,14 +1892,41 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
IASTDeclarator d = null;
|
IASTDeclarator d = null;
|
||||||
if (isFunction) {
|
if (numKnRCParms > 0) {
|
||||||
IASTFunctionDeclarator fc = createFunctionDeclarator();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
d = functionDecltor;
|
||||||
|
} else if (isFunction) {
|
||||||
|
IASTStandardFunctionDeclarator fc = createFunctionDeclarator();
|
||||||
fc.setVarArgs(encounteredVarArgs);
|
fc.setVarArgs(encounteredVarArgs);
|
||||||
for (int i = 0; i < parameters.size(); ++i) {
|
for (int i = 0; i < parameters.size(); ++i) {
|
||||||
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
|
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
|
||||||
.get(i);
|
.get(i);
|
||||||
p.setParent(fc);
|
p.setParent(fc);
|
||||||
p.setPropertyInParent(IASTFunctionDeclarator.FUNCTION_PARAMETER);
|
p
|
||||||
|
.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER);
|
||||||
fc.addParameterDeclaration(p);
|
fc.addParameterDeclaration(p);
|
||||||
}
|
}
|
||||||
d = fc;
|
d = fc;
|
||||||
|
@ -1826,7 +1962,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
|
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
((ASTNode)d).setOffsetAndLength( startingOffset, finalOffset - startingOffset );
|
((ASTNode) d).setOffsetAndLength(startingOffset, finalOffset
|
||||||
|
- startingOffset);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1844,17 +1981,25 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected IASTFunctionDeclarator createFunctionDeclarator() {
|
protected IASTStandardFunctionDeclarator createFunctionDeclarator() {
|
||||||
return new CASTFunctionDeclarator();
|
return new CASTFunctionDeclarator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected ICASTKnRFunctionDeclarator createKnRFunctionDeclarator() {
|
||||||
|
return new CASTKnRFunctionDeclarator();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param t
|
* @param t
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected IASTName createName(IToken t) {
|
protected IASTName createName(IToken t) {
|
||||||
IASTName n = new CASTName(t.getCharImage());
|
IASTName n = new CASTName(t.getCharImage());
|
||||||
((ASTNode) n).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
|
((ASTNode) n).setOffsetAndLength(t.getOffset(), t.getEndOffset()
|
||||||
|
- t.getOffset());
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2295,4 +2440,76 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int countKnRCParms() {
|
||||||
|
IToken mark = null;
|
||||||
|
int parmCount = 0;
|
||||||
|
boolean previousWasIdentifier = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
mark = mark();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
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()
|
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||||
*/
|
*/
|
||||||
public List getParameters() {
|
public List getParameters() {
|
||||||
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarations[0];
|
IASTStandardFunctionDeclarator dtor = ( definition != null ) ? definition : declarations[0];
|
||||||
IASTParameterDeclaration[] params = dtor.getParameters();
|
IASTParameterDeclaration[] params = dtor.getParameters();
|
||||||
int size = params.length;
|
int size = params.length;
|
||||||
List result = new ArrayList( size );
|
List result = new ArrayList( size );
|
||||||
|
@ -136,7 +136,7 @@ public class CPPFunction implements IFunction {
|
||||||
if( binding != null )
|
if( binding != null )
|
||||||
return binding;
|
return binding;
|
||||||
|
|
||||||
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) param.getParent();
|
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||||
IASTParameterDeclaration [] ps = fdtor.getParameters();
|
IASTParameterDeclaration [] ps = fdtor.getParameters();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for( ; i < ps.length; i++ ){
|
for( ; i < ps.length; i++ ){
|
||||||
|
|
|
@ -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.IASTParameterDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
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.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
@ -742,7 +743,8 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
if( checkAux ) {
|
if( checkAux ) {
|
||||||
//check the parameters
|
//check the parameters
|
||||||
IASTParameterDeclaration [] parameters = declarator.getParameters();
|
if ( declarator instanceof IASTStandardFunctionDeclarator ) {
|
||||||
|
IASTParameterDeclaration [] parameters = ((IASTStandardFunctionDeclarator)declarator).getParameters();
|
||||||
for( int i = 0; i < parameters.length; i++ ){
|
for( int i = 0; i < parameters.length; i++ ){
|
||||||
IASTParameterDeclaration parameterDeclaration = parameters[i];
|
IASTParameterDeclaration parameterDeclaration = parameters[i];
|
||||||
if( parameterDeclaration == null ) break;
|
if( parameterDeclaration == null ) break;
|
||||||
|
@ -752,6 +754,7 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if( declaration instanceof ICPPASTNamespaceDefinition ){
|
} else if( declaration instanceof ICPPASTNamespaceDefinition ){
|
||||||
IASTName namespaceName = ((ICPPASTNamespaceDefinition) declaration).getName();
|
IASTName namespaceName = ((ICPPASTNamespaceDefinition) declaration).getName();
|
||||||
if( CharArrayUtils.equals( namespaceName.toCharArray(), data.name ) )
|
if( CharArrayUtils.equals( namespaceName.toCharArray(), data.name ) )
|
||||||
|
|
|
@ -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.IASTForStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
|
@ -310,7 +311,7 @@ public class CPPVisitor {
|
||||||
}
|
}
|
||||||
} else if( parent instanceof IASTParameterDeclaration ){
|
} else if( parent instanceof IASTParameterDeclaration ){
|
||||||
IASTParameterDeclaration param = (IASTParameterDeclaration) parent;
|
IASTParameterDeclaration param = (IASTParameterDeclaration) parent;
|
||||||
IASTFunctionDeclarator fDtor = (IASTFunctionDeclarator) param.getParent();
|
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||||
IFunction function = (IFunction) fDtor.getName().resolveBinding();
|
IFunction function = (IFunction) fDtor.getName().resolveBinding();
|
||||||
binding = ((CPPFunction) function).resolveParameter( param );
|
binding = ((CPPFunction) function).resolveParameter( param );
|
||||||
} else if( parent instanceof IASTSimpleDeclaration ){
|
} else if( parent instanceof IASTSimpleDeclaration ){
|
||||||
|
@ -460,8 +461,8 @@ public class CPPVisitor {
|
||||||
*/
|
*/
|
||||||
public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) {
|
public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) {
|
||||||
IASTNode parent = parameterDeclaration.getParent();
|
IASTNode parent = parameterDeclaration.getParent();
|
||||||
if( parent instanceof IASTFunctionDeclarator ){
|
if( parent instanceof IASTStandardFunctionDeclarator ){
|
||||||
IASTFunctionDeclarator functionDeclarator = (IASTFunctionDeclarator) parent;
|
IASTStandardFunctionDeclarator functionDeclarator = (IASTStandardFunctionDeclarator) parent;
|
||||||
if( functionDeclarator.getNestedDeclarator() != null ){
|
if( functionDeclarator.getNestedDeclarator() != null ){
|
||||||
return getContainingScope( functionDeclarator );
|
return getContainingScope( functionDeclarator );
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.IASTFieldReference;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
|
@ -2613,7 +2613,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||||
|
|
||||||
IASTDeclarator declarator = (IASTDeclarator) declarators.get(0);
|
IASTDeclarator declarator = (IASTDeclarator) declarators.get(0);
|
||||||
if (!(declarator instanceof IASTFunctionDeclarator))
|
if (!(declarator instanceof IASTStandardFunctionDeclarator))
|
||||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||||
|
|
||||||
if (!constructorChain.isEmpty()
|
if (!constructorChain.isEmpty()
|
||||||
|
@ -2635,7 +2635,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declSpec.setParent(funcDefinition);
|
declSpec.setParent(funcDefinition);
|
||||||
declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER);
|
declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER);
|
||||||
|
|
||||||
funcDefinition.setDeclarator((IASTFunctionDeclarator) declarator);
|
funcDefinition.setDeclarator((IASTStandardFunctionDeclarator) declarator);
|
||||||
declarator.setParent(funcDefinition);
|
declarator.setParent(funcDefinition);
|
||||||
declarator.setPropertyInParent(IASTFunctionDefinition.DECLARATOR);
|
declarator.setPropertyInParent(IASTFunctionDefinition.DECLARATOR);
|
||||||
|
|
||||||
|
@ -3670,7 +3670,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
|
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
|
||||||
.get(i);
|
.get(i);
|
||||||
p.setParent(fc);
|
p.setParent(fc);
|
||||||
p.setPropertyInParent(IASTFunctionDeclarator.FUNCTION_PARAMETER);
|
p.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER);
|
||||||
fc.addParameterDeclaration(p);
|
fc.addParameterDeclaration(p);
|
||||||
}
|
}
|
||||||
fc.setConst(isConst);
|
fc.setConst(isConst);
|
||||||
|
|
Loading…
Add table
Reference in a new issue