mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
Patch for John Camelon - see ChangeLog
This commit is contained in:
parent
4ea2c26883
commit
7dcd5eaebe
11 changed files with 137 additions and 24 deletions
|
@ -126,7 +126,7 @@ public class DOMBuilder implements IParserCallback
|
|||
/**
|
||||
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#functionBodyBegin()
|
||||
*/
|
||||
public void functionBodyBegin() {
|
||||
public void functionBodyBegin(Object declaration) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,4 +323,10 @@ public class DOMBuilder implements IParserCallback
|
|||
((ElaboratedTypeSpecifier)elab).setName( currName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void simpleDeclSpecifierName(Object declaration) {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,7 @@
|
|||
2003-03-18 John Camelon
|
||||
Updated IParserCallback (and implementations) to add a typeName to DeclSpecifier.
|
||||
Updated IParserCallback and NewModelBuilder to distinguish between Function declarations and definitions.
|
||||
|
||||
2003-03-17 Doug Schaefer
|
||||
Changed EOF to be a Backtrack exception instead of a token so simplify
|
||||
error handling.
|
||||
|
|
|
@ -102,7 +102,9 @@ public class NewModelBuilder implements IParserCallback {
|
|||
/**
|
||||
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#beginFunctionBody()
|
||||
*/
|
||||
public void functionBodyBegin() {
|
||||
public void functionBodyBegin(Object declaration) {
|
||||
SimpleDeclarationWrapper wrapper = (SimpleDeclarationWrapper)declaration;
|
||||
wrapper.setFunctionDefinition(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -346,4 +348,14 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
|
|||
public void elaboratedTypeSpecifierName(Object elab) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void simpleDeclSpecifierName(Object declaration) {
|
||||
DeclSpecifier declSpecifier = (DeclSpecifier)declaration;
|
||||
declSpecifier.setName( currName );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
|
|||
private CElement parent = null;
|
||||
int kind;
|
||||
private Name name = null;
|
||||
private boolean functionDefinition = false;
|
||||
|
||||
public SimpleDeclarationWrapper( CElement item )
|
||||
{
|
||||
|
@ -197,4 +198,20 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
|
|||
this.kind = kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the functionDefinition.
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isFunctionDefinition() {
|
||||
return functionDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the functionDefinition.
|
||||
* @param functionDefinition The functionDefinition to set
|
||||
*/
|
||||
public void setFunctionDefinition(boolean functionDefinition) {
|
||||
this.functionDefinition = functionDefinition;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ public class ExpressionEvaluator implements IParserCallback {
|
|||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyBegin()
|
||||
*/
|
||||
public void functionBodyBegin() {
|
||||
public void functionBodyBegin(Object declaration) {
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyEnd()
|
||||
|
@ -300,4 +300,10 @@ public class ExpressionEvaluator implements IParserCallback {
|
|||
public void elaboratedTypeSpecifierName(Object container) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void simpleDeclSpecifierName(Object declaration) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ public interface IParserCallback {
|
|||
public void macro(String macroName, int offset);
|
||||
|
||||
public Object simpleDeclarationBegin(Object Container);
|
||||
public void simpleDeclSpecifier(Object Container, Token specifier);
|
||||
public void simpleDeclSpecifierName( Object declaration );
|
||||
public void simpleDeclarationEnd(Object declaration);
|
||||
|
||||
|
||||
public Object parameterDeclarationBegin( Object Container );
|
||||
public void parameterDeclarationEnd( Object declaration );
|
||||
|
||||
public void simpleDeclSpecifier(Object Container, Token specifier);
|
||||
|
||||
public void nameBegin(Token firstToken);
|
||||
public void nameEnd(Token lastToken);
|
||||
|
||||
|
@ -38,7 +38,7 @@ public interface IParserCallback {
|
|||
public Object argumentsBegin( Object declarator );
|
||||
public void argumentsEnd(Object parameterDeclarationClause);
|
||||
|
||||
public void functionBodyBegin();
|
||||
public void functionBodyBegin(Object declaration);
|
||||
public void functionBodyEnd();
|
||||
|
||||
public Object classSpecifierBegin(Object container, Token classKey);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class NullParserCallback implements IParserCallback {
|
|||
/**
|
||||
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#beginFunctionBody()
|
||||
*/
|
||||
public void functionBodyBegin() {
|
||||
public void functionBodyBegin(Object declaration) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,4 +216,10 @@ public class NullParserCallback implements IParserCallback {
|
|||
public void elaboratedTypeSpecifierName(Object elab) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void simpleDeclSpecifierName(Object declaration) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ c, quick);
|
|||
*/
|
||||
public void simpleDeclaration( Object container ) throws Exception {
|
||||
Object simpleDecl = callback.simpleDeclarationBegin( container);
|
||||
declSpecifierSeq(simpleDecl);
|
||||
declSpecifierSeq(simpleDecl, false);
|
||||
|
||||
if (LT(1) != Token.tSEMI)
|
||||
try {
|
||||
|
@ -210,7 +210,7 @@ c, quick);
|
|||
}
|
||||
// Falling through on purpose
|
||||
case Token.tLBRACE:
|
||||
callback.functionBodyBegin();
|
||||
callback.functionBodyBegin(simpleDecl );
|
||||
if (quickParse) {
|
||||
// speed up the parser by skiping the body
|
||||
// simply look for matching brace and return
|
||||
|
@ -242,7 +242,7 @@ c, quick);
|
|||
public void parameterDeclaration( Object containerObject ) throws Exception
|
||||
{
|
||||
Object parameterDecl = callback.parameterDeclarationBegin( containerObject );
|
||||
declSpecifierSeq( parameterDecl );
|
||||
declSpecifierSeq( parameterDecl, true );
|
||||
|
||||
if (LT(1) != Token.tSEMI)
|
||||
try {
|
||||
|
@ -273,7 +273,7 @@ c, quick);
|
|||
* - folded elaboratedTypeSpecifier into classSpecifier and enumSpecifier
|
||||
* - find template names in name
|
||||
*/
|
||||
public void declSpecifierSeq( Object decl ) throws Exception {
|
||||
public void declSpecifierSeq( Object decl, boolean parm ) throws Exception {
|
||||
boolean encounteredTypename = false;
|
||||
boolean encounteredRawType = false;
|
||||
declSpecifiers:
|
||||
|
@ -291,16 +291,16 @@ c, quick);
|
|||
case Token.t_friend:
|
||||
case Token.t_const:
|
||||
case Token.t_volatile:
|
||||
case Token.t_signed:
|
||||
case Token.t_unsigned:
|
||||
case Token.t_short:
|
||||
callback.simpleDeclSpecifier(decl, consume());
|
||||
break;
|
||||
case Token.t_char:
|
||||
case Token.t_wchar_t:
|
||||
case Token.t_bool:
|
||||
case Token.t_short:
|
||||
case Token.t_int:
|
||||
case Token.t_long:
|
||||
case Token.t_signed:
|
||||
case Token.t_unsigned:
|
||||
case Token.t_float:
|
||||
case Token.t_double:
|
||||
case Token.t_void:
|
||||
|
@ -316,21 +316,19 @@ c, quick);
|
|||
// handle nested later:
|
||||
case Token.tIDENTIFIER:
|
||||
// TODO - Kludgy way to handle constructors/destructors
|
||||
if (!encounteredRawType && LT(2) != Token.tCOLONCOLON && LT(2) != Token.tLPAREN)
|
||||
// handle nested later:
|
||||
if ((parm && !encounteredRawType) || (!encounteredRawType && LT(2) != Token.tCOLONCOLON && LT(2) != Token.tLPAREN))
|
||||
{
|
||||
// handle nested later:
|
||||
if( ! encounteredTypename )
|
||||
{
|
||||
callback.simpleDeclSpecifier(decl,consume());
|
||||
callback.simpleDeclSpecifier(decl,LA(1));
|
||||
name();
|
||||
callback.simpleDeclSpecifierName( decl );
|
||||
encounteredTypename = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
return;
|
||||
case Token.t_class:
|
||||
case Token.t_struct:
|
||||
case Token.t_union:
|
||||
|
|
|
@ -45,7 +45,8 @@ public class DeclSpecifier {
|
|||
}
|
||||
|
||||
private boolean checkBit(int mask) {
|
||||
return (declSpecifierSeq & mask) == 1;
|
||||
int masked =(declSpecifierSeq & mask);
|
||||
return (masked == 1);
|
||||
}
|
||||
|
||||
public void setAuto(boolean b) { setBit(b, isAuto); }
|
||||
|
@ -201,5 +202,23 @@ public class DeclSpecifier {
|
|||
public List getDeclarators();
|
||||
|
||||
};
|
||||
|
||||
Name name = null;
|
||||
|
||||
/**
|
||||
* Returns the name.
|
||||
* @return Name
|
||||
*/
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
* @param name The name to set
|
||||
*/
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-03-18 John Camelon
|
||||
Updated DOMTests to validate simple case of a function declaration with multiple parameters.
|
||||
* parser/org/eclipse/cdt/core/parser/tests/DOMTests.java
|
||||
|
||||
2003-03-11 John Camelon
|
||||
Updated DOMTests for core.internal.parser change of merging DeclarationSpecifier and DeclSpecifier
|
||||
Organized imports
|
||||
|
|
|
@ -242,6 +242,47 @@ public class DOMTests extends TestCase {
|
|||
assertNull( parm1Declarator.getName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test code: bool myFunction( int parm1, double parm2 );
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testFunctionDeclarationWithParameters() throws Exception
|
||||
{
|
||||
// Parse and get the translaton unit
|
||||
Writer code = new StringWriter();
|
||||
code.write("bool myFunction( int parm1, double parm2 );");
|
||||
TranslationUnit translationUnit = parse(code.toString());
|
||||
|
||||
// Get the declaration
|
||||
List declarations = translationUnit.getDeclarations();
|
||||
assertEquals(1, declarations.size());
|
||||
SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0);
|
||||
assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_bool );
|
||||
List declarators = simpleDeclaration.getDeclarators();
|
||||
assertEquals( 1, declarators.size() );
|
||||
Declarator functionDeclarator = (Declarator)declarators.get( 0 );
|
||||
assertEquals( functionDeclarator.getName().toString(), "myFunction" );
|
||||
ParameterDeclarationClause pdc = functionDeclarator.getParms();
|
||||
assertNotNull( pdc );
|
||||
List parameterDecls = pdc.getDeclarations();
|
||||
assertEquals( 2, parameterDecls.size() );
|
||||
ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 );
|
||||
assertEquals( DeclSpecifier.t_int, parm1.getDeclSpecifier().getType() );
|
||||
List parm1Decls = parm1.getDeclarators();
|
||||
assertEquals( 1, parm1Decls.size() );
|
||||
Declarator parm1Declarator = (Declarator) parm1Decls.get(0);
|
||||
assertEquals( "parm1", parm1Declarator.getName().toString() );
|
||||
|
||||
ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 );
|
||||
assertEquals( DeclSpecifier.t_double, parm2.getDeclSpecifier().getType() );
|
||||
List parm2Decls = parm2.getDeclarators();
|
||||
assertEquals( 1, parm2Decls.size() );
|
||||
Declarator parm2Declarator = (Declarator) parm2Decls.get(0);
|
||||
assertEquals( "parm2", parm2Declarator.getName().toString() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test code: "class A { int floor( double input ), someInt; };"
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue