mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Victor Mozgin.
K&R Support. God help us.
This commit is contained in:
parent
f7b57711f9
commit
5ef908593a
14 changed files with 343 additions and 25 deletions
|
@ -1,3 +1,14 @@
|
||||||
|
2003-06-16 Victor Mozgin
|
||||||
|
Implemented support for old K&R-style C function declarations.
|
||||||
|
Added oldKRParametersBegin() and oldKRParametersEnd() to DOMBuilder.
|
||||||
|
Added OldKRParameterDeclarationClause.java to dom/org/eclipse/cdt/internal/core/dom.
|
||||||
|
Added handling of OldKRParameterDeclarationClause to ParameterDeclarationClause.
|
||||||
|
|
||||||
|
2003-06-14 Victor Mozgin
|
||||||
|
Added support for pointers to members to DOMBuilder.
|
||||||
|
Added new kind of pointer operator : t_pointer_to_member (PointerOperator).
|
||||||
|
Added nameSpecifier field and set/get operations to PointerOperator.
|
||||||
|
|
||||||
2003-06-13 Andrew Niefer
|
2003-06-13 Andrew Niefer
|
||||||
Added search\org.eclipse.cdt.core.search
|
Added search\org.eclipse.cdt.core.search
|
||||||
search\org.eclipse.cdt.internal.core.search
|
search\org.eclipse.cdt.internal.core.search
|
||||||
|
@ -6,11 +17,6 @@
|
||||||
with skeleton classes based on the JDT search as a beginning for
|
with skeleton classes based on the JDT search as a beginning for
|
||||||
implementing C/CPP search.
|
implementing C/CPP search.
|
||||||
|
|
||||||
2003-06-14 Victor Mozgin
|
|
||||||
Added support for pointers to members to DOMBuilder.
|
|
||||||
Added new kind of pointer operator : t_pointer_to_member (PointerOperator).
|
|
||||||
Added nameSpecifier field and set/get operations to PointerOperator.
|
|
||||||
|
|
||||||
2003-06-06 Sean Evoy
|
2003-06-06 Sean Evoy
|
||||||
|
|
||||||
Added new interface, IResourceBuildInfo, so clients could
|
Added new interface, IResourceBuildInfo, so clients could
|
||||||
|
|
|
@ -55,6 +55,23 @@ public class DOMBuilder implements IParserCallback, ISourceElementRequestor
|
||||||
public void argumentsEnd(Object parameterDeclarationClause) {
|
public void argumentsEnd(Object parameterDeclarationClause) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersBegin()
|
||||||
|
*/
|
||||||
|
public Object oldKRParametersBegin( Object parameterDeclarationClause ) {
|
||||||
|
ParameterDeclarationClause clause = ((ParameterDeclarationClause)parameterDeclarationClause);
|
||||||
|
OldKRParameterDeclarationClause KRclause = new OldKRParameterDeclarationClause( clause );
|
||||||
|
domScopes.push(KRclause);
|
||||||
|
return KRclause;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersEnd()
|
||||||
|
*/
|
||||||
|
public void oldKRParametersEnd(Object oldKRParameterDeclarationClause) {
|
||||||
|
domScopes.pop();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classBegin(java.lang.String, org.eclipse.cdt.internal.core.newparser.Token)
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classBegin(java.lang.String, org.eclipse.cdt.internal.core.newparser.Token)
|
||||||
*/
|
*/
|
||||||
|
@ -318,6 +335,7 @@ public class DOMBuilder implements IParserCallback, ISourceElementRequestor
|
||||||
ParameterDeclaration d = (ParameterDeclaration)declaration;
|
ParameterDeclaration d = (ParameterDeclaration)declaration;
|
||||||
d.getOwnerScope().addDeclaration(d);
|
d.getOwnerScope().addDeclaration(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.eclipse.cdt.internal.core.dom;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author vmozgin
|
||||||
|
*
|
||||||
|
* To change this generated comment edit the template variable "typecomment":
|
||||||
|
* Window>Preferences>Java>Templates.
|
||||||
|
* To enable and disable the creation of type comments go to
|
||||||
|
* Window>Preferences>Java>Code Generation.
|
||||||
|
*/
|
||||||
|
public class OldKRParameterDeclarationClause implements IScope {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.core.dom.IScope#addDeclaration(org.eclipse.cdt.internal.core.dom.Declaration)
|
||||||
|
*/
|
||||||
|
public void addDeclaration( Declaration declaration) {
|
||||||
|
declarations.add( declaration );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.core.dom.IScope#getDeclarations()
|
||||||
|
*/
|
||||||
|
public List getDeclarations() {
|
||||||
|
return Collections.unmodifiableList( declarations );
|
||||||
|
}
|
||||||
|
|
||||||
|
private List declarations = new LinkedList();
|
||||||
|
private ParameterDeclarationClause owner;
|
||||||
|
|
||||||
|
OldKRParameterDeclarationClause( ParameterDeclarationClause owner )
|
||||||
|
{
|
||||||
|
this.owner = owner;
|
||||||
|
this.owner.addOldKRParms( this );
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,4 +37,19 @@ public class ParameterDeclarationClause implements IScope {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.owner.addParms( this );
|
this.owner.addParms( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OldKRParameterDeclarationClause oldKRparms = null;
|
||||||
|
|
||||||
|
public void addOldKRParms( OldKRParameterDeclarationClause oldKRparms )
|
||||||
|
{
|
||||||
|
this.oldKRparms = oldKRparms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the parms.
|
||||||
|
* @return OldKRParameterDeclarationClause
|
||||||
|
*/
|
||||||
|
public OldKRParameterDeclarationClause getOldKRParms() {
|
||||||
|
return oldKRparms;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,14 @@
|
||||||
Added proper support for function pointers as parameters.
|
Added proper support for function pointers as parameters.
|
||||||
This fixes PR 38921 and 39002.
|
This fixes PR 38921 and 39002.
|
||||||
|
|
||||||
|
2003-06-16 Victor Mozgin
|
||||||
|
Implemented support for old K&R-style C function declarations.
|
||||||
|
Added oldKRParametersBegin() and oldKRParametersEnd() to IParserCallback.
|
||||||
|
Added getParameterTypes() with support of K&R to CModelBuilder.
|
||||||
|
Fixed ExpressionEvaluator and NullSourceElementRequestor for additions to IParserCallback.
|
||||||
|
Added handling of K&R syntax to the parser.
|
||||||
|
This fixes PR 7541, 35320 and 38434.
|
||||||
|
|
||||||
2003-06-14 Victor Mozgin
|
2003-06-14 Victor Mozgin
|
||||||
Fixed handling of parameter lists for typedefs for functions.
|
Fixed handling of parameter lists for typedefs for functions.
|
||||||
More errorhandling in CModelBuilder.
|
More errorhandling in CModelBuilder.
|
||||||
|
|
|
@ -56,7 +56,10 @@ public interface IParserCallback {
|
||||||
public Object argumentsBegin( Object declarator );
|
public Object argumentsBegin( Object declarator );
|
||||||
public void argumentsEnd(Object parameterDeclarationClause);
|
public void argumentsEnd(Object parameterDeclarationClause);
|
||||||
|
|
||||||
public Object functionBodyBegin(Object declaration);
|
public Object oldKRParametersBegin( Object parameterDeclarationClause );
|
||||||
|
public void oldKRParametersEnd(Object oldKRParameterDeclarationClause);
|
||||||
|
|
||||||
|
public Object functionBodyBegin(Object declaration);
|
||||||
public void functionBodyEnd(Object functionBody);
|
public void functionBodyEnd(Object functionBody);
|
||||||
|
|
||||||
public Object classSpecifierBegin(Object container, IToken classKey);
|
public Object classSpecifierBegin(Object container, IToken classKey);
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.cdt.internal.core.dom.ITemplateParameterListOwner;
|
||||||
import org.eclipse.cdt.internal.core.dom.Inclusion;
|
import org.eclipse.cdt.internal.core.dom.Inclusion;
|
||||||
import org.eclipse.cdt.internal.core.dom.Macro;
|
import org.eclipse.cdt.internal.core.dom.Macro;
|
||||||
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.OldKRParameterDeclarationClause;
|
||||||
import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
|
import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
|
||||||
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
||||||
import org.eclipse.cdt.internal.core.dom.PointerOperator;
|
import org.eclipse.cdt.internal.core.dom.PointerOperator;
|
||||||
|
@ -52,6 +53,7 @@ import org.eclipse.cdt.internal.core.parser.Name;
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
import org.eclipse.cdt.internal.core.parser.Parser;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
|
||||||
|
|
||||||
public class CModelBuilder {
|
public class CModelBuilder {
|
||||||
|
|
||||||
protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
|
protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
|
||||||
|
@ -873,7 +875,12 @@ public class CModelBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String[] getParameterTypes(Declarator declarator)
|
private String[] getParameterTypes(Declarator declarator)
|
||||||
|
{
|
||||||
|
return getParameterTypes(declarator, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getParameterTypes(Declarator declarator, HashMap mapOfKRParams)
|
||||||
{
|
{
|
||||||
if (declarator == null) return null;
|
if (declarator == null) return null;
|
||||||
|
|
||||||
|
@ -886,7 +893,26 @@ public class CModelBuilder {
|
||||||
|
|
||||||
for (int j = 0; j < parameterList.size(); ++j) {
|
for (int j = 0; j < parameterList.size(); ++j) {
|
||||||
ParameterDeclaration param = (ParameterDeclaration) parameterList.get(j);
|
ParameterDeclaration param = (ParameterDeclaration) parameterList.get(j);
|
||||||
parameterTypes[j] = getType(param, (Declarator) param.getDeclarators().get(0));
|
Declarator decl = (Declarator) param.getDeclarators().get(0);
|
||||||
|
parameterTypes[j] = getType(param, decl);
|
||||||
|
|
||||||
|
if ( (mapOfKRParams != null)
|
||||||
|
&& (mapOfKRParams.size() > 0)
|
||||||
|
&& (decl.getName() == null))
|
||||||
|
{
|
||||||
|
// We have some K&R-style parameter declarations,
|
||||||
|
// and the current parameter has been declared with a single identifier,
|
||||||
|
// (like ...(argname)...)
|
||||||
|
// It has been parsed as a typename, so 'argname' is a name of the type,
|
||||||
|
// and parameter name is empty. But for this particular case,
|
||||||
|
// 'argname' is a name, and its type we have to lookup in the map
|
||||||
|
// of old K&R-style parameter declarations.
|
||||||
|
// If we can't find it, we keep parameter name in the signature
|
||||||
|
String oldKRParamType = (String)mapOfKRParams.get(parameterTypes[j]);
|
||||||
|
if (oldKRParamType != null) {
|
||||||
|
parameterTypes[j] = oldKRParamType;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -905,7 +931,41 @@ public class CModelBuilder {
|
||||||
currentDeclarator = currentDeclarator.getDeclarator();
|
currentDeclarator = currentDeclarator.getDeclarator();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getParameterTypes(innermostPDCDeclarator);
|
HashMap mapOfKRParams = null;
|
||||||
|
|
||||||
|
if ( declarator != null
|
||||||
|
&& declarator.getParms() != null
|
||||||
|
&& declarator.getParms().getOldKRParms() != null) {
|
||||||
|
|
||||||
|
mapOfKRParams = new HashMap();
|
||||||
|
|
||||||
|
OldKRParameterDeclarationClause oldKRpdc = declarator.getParms().getOldKRParms();
|
||||||
|
List oldKRParameterList = oldKRpdc.getDeclarations();
|
||||||
|
|
||||||
|
for (int j = 0; j < oldKRParameterList.size(); ++j) {
|
||||||
|
if(oldKRParameterList.get(j) instanceof SimpleDeclaration) { // Must be
|
||||||
|
SimpleDeclaration declKR = (SimpleDeclaration)oldKRParameterList.get(j);
|
||||||
|
|
||||||
|
List declarators = declKR.getDeclarators();
|
||||||
|
Iterator d = declarators.iterator();
|
||||||
|
while (d.hasNext()) {
|
||||||
|
Declarator decl = (Declarator) d.next();
|
||||||
|
|
||||||
|
Name oldKRparamName = getDOMName(decl);
|
||||||
|
String oldKRparamType = getType(declKR, decl);
|
||||||
|
|
||||||
|
if ( (oldKRparamType != null)
|
||||||
|
&& (oldKRparamName != null)
|
||||||
|
&& (oldKRparamName.toString().length() > 0)
|
||||||
|
) {
|
||||||
|
mapOfKRParams.put(oldKRparamName.toString(), oldKRparamType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getParameterTypes(innermostPDCDeclarator, mapOfKRParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getParametersString(String[] parameterTypes)
|
private String getParametersString(String[] parameterTypes)
|
||||||
|
|
|
@ -201,6 +201,17 @@ public class ExpressionEvaluator implements IParserCallback {
|
||||||
*/
|
*/
|
||||||
public void argumentsEnd(Object parameterDeclarationClause) {
|
public void argumentsEnd(Object parameterDeclarationClause) {
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersBegin()
|
||||||
|
*/
|
||||||
|
public Object oldKRParametersBegin( Object parameterDeclarationClause ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersEnd()
|
||||||
|
*/
|
||||||
|
public void oldKRParametersEnd(Object oldKRParameterDeclarationClause) {
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyBegin()
|
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyBegin()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -398,6 +398,19 @@ public class NullSourceElementRequestor implements ISourceElementRequestor, IPar
|
||||||
public void argumentsEnd(Object parameterDeclarationClause) {
|
public void argumentsEnd(Object parameterDeclarationClause) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersBegin()
|
||||||
|
*/
|
||||||
|
public Object oldKRParametersBegin( Object parameterDeclarationClause ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersEnd()
|
||||||
|
*/
|
||||||
|
public void oldKRParametersEnd(Object oldKRParameterDeclarationClause) {
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyBegin(java.lang.Object)
|
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyBegin(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -648,13 +648,13 @@ c, quickParse);
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
simpleDeclaration( container, true, scope ); // try it first with the original strategy
|
simpleDeclaration( container, true, false, scope ); // try it first with the original strategy
|
||||||
}
|
}
|
||||||
catch( Backtrack bt)
|
catch( Backtrack bt)
|
||||||
{
|
{
|
||||||
// did not work
|
// did not work
|
||||||
backup( mark );
|
backup( mark );
|
||||||
simpleDeclaration( container, false, scope ); // try it again with the second strategy
|
simpleDeclaration( container, false, false, scope ); // try it again with the second strategy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -750,9 +750,10 @@ c, quickParse);
|
||||||
*
|
*
|
||||||
* @param container IParserCallback object which serves as the owner scope for this declaration.
|
* @param container IParserCallback object which serves as the owner scope for this declaration.
|
||||||
* @param tryConstructor true == take strategy1 (constructor ) : false == take strategy 2 ( pointer to function)
|
* @param tryConstructor true == take strategy1 (constructor ) : false == take strategy 2 ( pointer to function)
|
||||||
|
* @param forKR Is this for K&R-style parameter declaration (true) or simple declaration (false)
|
||||||
* @throws Backtrack request a backtrack
|
* @throws Backtrack request a backtrack
|
||||||
*/
|
*/
|
||||||
protected void simpleDeclaration( Object container, boolean tryConstructor, IASTScope scope ) throws Backtrack {
|
protected void simpleDeclaration( Object container, boolean tryConstructor, boolean forKR, IASTScope scope ) throws Backtrack {
|
||||||
Object simpleDecl = null;
|
Object simpleDecl = null;
|
||||||
try{ simpleDecl = callback.simpleDeclarationBegin( container, LA(1));} catch( Exception e ) {}
|
try{ simpleDecl = callback.simpleDeclarationBegin( container, LA(1));} catch( Exception e ) {}
|
||||||
declSpecifierSeq(simpleDecl, false, tryConstructor, scope);
|
declSpecifierSeq(simpleDecl, false, tryConstructor, scope);
|
||||||
|
@ -780,9 +781,11 @@ c, quickParse);
|
||||||
consume(IToken.tSEMI);
|
consume(IToken.tSEMI);
|
||||||
break;
|
break;
|
||||||
case IToken.tCOLON:
|
case IToken.tCOLON:
|
||||||
|
if (forKR) throw backtrack;
|
||||||
ctorInitializer(declarator);
|
ctorInitializer(declarator);
|
||||||
// Falling through on purpose
|
// Falling through on purpose
|
||||||
case IToken.tLBRACE:
|
case IToken.tLBRACE:
|
||||||
|
if (forKR) throw backtrack;
|
||||||
Object function = null;
|
Object function = null;
|
||||||
try{ function = callback.functionBodyBegin(simpleDecl ); } catch( Exception e ) {}
|
try{ function = callback.functionBodyBegin(simpleDecl ); } catch( Exception e ) {}
|
||||||
if (quickParse) {
|
if (quickParse) {
|
||||||
|
@ -812,6 +815,7 @@ c, quickParse);
|
||||||
try{ callback.simpleDeclarationEnd(simpleDecl, (Token)lastToken);} catch( Exception e ) {}
|
try{ callback.simpleDeclarationEnd(simpleDecl, (Token)lastToken);} catch( Exception e ) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method parses a constructor chain
|
* This method parses a constructor chain
|
||||||
* ctorinitializer: : meminitializerlist
|
* ctorinitializer: : meminitializerlist
|
||||||
|
@ -1486,6 +1490,7 @@ c, quickParse);
|
||||||
* (exceptionSpecification)*
|
* (exceptionSpecification)*
|
||||||
* | directDeclarator "[" (constantExpression)? "]"
|
* | directDeclarator "[" (constantExpression)? "]"
|
||||||
* | "(" declarator")"
|
* | "(" declarator")"
|
||||||
|
* | directDeclarator "(" parameterDeclarationClause ")" (oldKRParameterDeclaration)*
|
||||||
*
|
*
|
||||||
* declaratorId
|
* declaratorId
|
||||||
* : name
|
* : name
|
||||||
|
@ -1693,10 +1698,19 @@ c, quickParse);
|
||||||
return declarator;
|
return declarator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const-volatile marker on the method
|
IToken beforeCVModifier = mark();
|
||||||
|
IToken cvModifier = null;
|
||||||
|
IToken afterCVModifier = beforeCVModifier;
|
||||||
|
|
||||||
|
// const-volatile
|
||||||
|
// 2 options: either this is a marker for the method,
|
||||||
|
// or it might be the beginning of old K&R style parameter declaration, see
|
||||||
|
// void getenv(name) const char * name; {}
|
||||||
|
// This will be determined further below
|
||||||
if( LT(1) == IToken.t_const || LT(1) == IToken.t_volatile )
|
if( LT(1) == IToken.t_const || LT(1) == IToken.t_volatile )
|
||||||
{
|
{
|
||||||
try{ callback.declaratorCVModifier( declarator, consume() );} catch( Exception e ) {}
|
cvModifier = consume();
|
||||||
|
afterCVModifier = mark();
|
||||||
}
|
}
|
||||||
|
|
||||||
//check for throws clause here
|
//check for throws clause here
|
||||||
|
@ -1738,6 +1752,34 @@ c, quickParse);
|
||||||
try{ callback.declaratorPureVirtual( declarator ); } catch( Exception e ) { }
|
try{ callback.declaratorPureVirtual( declarator ); } catch( Exception e ) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (afterCVModifier != currToken || LT(1) == IToken.tSEMI) {
|
||||||
|
// There were C++-specific clauses after const/volatile modifier
|
||||||
|
// Then it is a marker for the method
|
||||||
|
try{ callback.declaratorCVModifier( declarator, cvModifier );} catch( Exception e ) {}
|
||||||
|
// In this case (method) we can't expect K&R parameter declarations,
|
||||||
|
// but we'll check anyway, for errorhandling
|
||||||
|
} else {
|
||||||
|
// let's try this modifier as part of K&R parameter declaration
|
||||||
|
backup(beforeCVModifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LT(1) != IToken.tSEMI) {
|
||||||
|
// try K&R-style parameter declarations
|
||||||
|
Object oldKRParameterDeclarationClause = null;
|
||||||
|
try { oldKRParameterDeclarationClause = callback.oldKRParametersBegin(clause);} catch( Exception e ) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
simpleDeclaration(oldKRParameterDeclarationClause, false, true, null);
|
||||||
|
} while (LT(1) != IToken.tLBRACE);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Something is wrong,
|
||||||
|
// this is not a proper K&R declaration clause
|
||||||
|
backup(afterCVModifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{ callback.oldKRParametersEnd(oldKRParameterDeclarationClause);} catch( Exception e ) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IToken.tLBRACKET:
|
case IToken.tLBRACKET:
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
2003-06-17 Brent Nicolle
|
2003-06-17 Brent Nicolle
|
||||||
Added Interface tests of IStructure.java.
|
Added Interface tests of IStructure.java.
|
||||||
|
|
||||||
|
2003-06-17 Victor Mozgin
|
||||||
|
Added DeclaratorsTests.java (invocation in AllCoreTests).
|
||||||
|
Added DeclaratorsTests.cpp to org.eclipse.cdt.core.model.tests.resources.
|
||||||
|
|
||||||
2003-06-16 Vladimir Hirsl
|
2003-06-16 Vladimir Hirsl
|
||||||
Added /build, /parser, /failures and /suite directories to the library.
|
Added /build, /parser, /failures and /suite directories to the library.
|
||||||
Copied resources from /model/org.eclipse.cdt.core.model.tests.resources
|
Copied resources from /model/org.eclipse.cdt.core.model.tests.resources
|
||||||
|
@ -8,9 +12,9 @@
|
||||||
Added class AISResultPrinter to format test results.
|
Added class AISResultPrinter to format test results.
|
||||||
Class AutomatedIntegrationSuite now implements IPlatformRunnable.
|
Class AutomatedIntegrationSuite now implements IPlatformRunnable.
|
||||||
|
|
||||||
2003-06-17 Victor Mozgin
|
2003-06-16 Victor Mozgin
|
||||||
Added DeclaratorsTests.java (invocation in AllCoreTests).
|
Added testOldKRFunctionDeclarations() to DOMTests.
|
||||||
Added DeclaratorsTests.cpp to org.eclipse.cdt.core.model.tests.resources.
|
Added testKRFunctionDeclarations() to TranslationUnitTests.
|
||||||
|
|
||||||
2003-06-14 Victor Mozgin
|
2003-06-14 Victor Mozgin
|
||||||
Moved testBugSingleton192() from LokiFailures to DOMTests.
|
Moved testBugSingleton192() from LokiFailures to DOMTests.
|
||||||
|
|
|
@ -16,6 +16,7 @@ import junit.framework.TestSuite;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.IFunction;
|
||||||
import org.eclipse.cdt.core.model.IInclude;
|
import org.eclipse.cdt.core.model.IInclude;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||||
|
@ -51,8 +52,8 @@ public class TranslationUnitTests extends TestCase {
|
||||||
*/
|
*/
|
||||||
String[] expectedStringList= {"stdio.h", "unistd.h", "func2p",
|
String[] expectedStringList= {"stdio.h", "unistd.h", "func2p",
|
||||||
"globalvar", "myenum", "mystruct", "mystruct_t", "myunion", "mytype",
|
"globalvar", "myenum", "mystruct", "mystruct_t", "myunion", "mytype",
|
||||||
"func1", "func2", "main", "func3"};
|
"func1", "func2", "main", "func3", "KRFunction"};
|
||||||
int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65};
|
int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65,70};
|
||||||
/* This is a list of that the types of the above list of elements is
|
/* This is a list of that the types of the above list of elements is
|
||||||
* expected to be.
|
* expected to be.
|
||||||
*/
|
*/
|
||||||
|
@ -60,7 +61,8 @@ public class TranslationUnitTests extends TestCase {
|
||||||
ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE,
|
ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE,
|
||||||
ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF,
|
ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF,
|
||||||
ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION,
|
ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION,
|
||||||
ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION};
|
ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION,
|
||||||
|
ICElement.C_FUNCTION};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,6 +165,7 @@ public class TranslationUnitTests extends TestCase {
|
||||||
suite.addTest(new TranslationUnitTests("testGetElement"));
|
suite.addTest(new TranslationUnitTests("testGetElement"));
|
||||||
suite.addTest(new TranslationUnitTests("testBug23478A"));
|
suite.addTest(new TranslationUnitTests("testBug23478A"));
|
||||||
suite.addTest(new TranslationUnitTests("testBug23478B"));
|
suite.addTest(new TranslationUnitTests("testBug23478B"));
|
||||||
|
suite.addTest(new TranslationUnitTests("testKRFunctionDeclarations"));
|
||||||
// TODO: suite.addTest(new TranslationUnitTests("testGetElementAtLine"));
|
// TODO: suite.addTest(new TranslationUnitTests("testGetElementAtLine"));
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -359,4 +362,16 @@ public class TranslationUnitTests extends TestCase {
|
||||||
assertTrue(myExp.getExtraString(), !myExp.gotExtra());
|
assertTrue(myExp.getExtraString(), !myExp.gotExtra());
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Simple sanity test for old K&R-style C function declaration
|
||||||
|
*/
|
||||||
|
public void testKRFunctionDeclarations() throws CModelException {
|
||||||
|
ITranslationUnit myTranslationUnit = CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||||
|
|
||||||
|
assertTrue(myTranslationUnit.getElement("KRFunction") instanceof IFunction);
|
||||||
|
IFunction myKRFunction = (IFunction)myTranslationUnit.getElement("KRFunction");
|
||||||
|
assertEquals(myKRFunction.getSignature(), "KRFunction(const char*, int(*)(float), parm3)");
|
||||||
|
assertEquals(myKRFunction.getReturnType(), "bool");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,3 +66,9 @@ void func3()
|
||||||
{
|
{
|
||||||
printf("This is not really here\n");
|
printf("This is not really here\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KRFunction( parm1, parm2, parm3 )
|
||||||
|
const char* parm1;
|
||||||
|
int (*parm2)(float);
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.internal.core.dom.Inclusion;
|
||||||
import org.eclipse.cdt.internal.core.dom.LinkageSpecification;
|
import org.eclipse.cdt.internal.core.dom.LinkageSpecification;
|
||||||
import org.eclipse.cdt.internal.core.dom.Macro;
|
import org.eclipse.cdt.internal.core.dom.Macro;
|
||||||
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.OldKRParameterDeclarationClause;
|
||||||
import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
|
import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
|
||||||
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
||||||
import org.eclipse.cdt.internal.core.dom.PointerOperator;
|
import org.eclipse.cdt.internal.core.dom.PointerOperator;
|
||||||
|
@ -2159,4 +2160,80 @@ public class DOMTests extends BaseDOMTest {
|
||||||
parse("template <class B,C> A::nested::operator int() {} ");
|
parse("template <class B,C> A::nested::operator int() {} ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testOldKRFunctionDeclarations() throws Exception
|
||||||
|
{
|
||||||
|
// Parse and get the translaton unit
|
||||||
|
Writer code = new StringWriter();
|
||||||
|
code.write("bool myFunction( parm1, parm2, parm3 )\n");
|
||||||
|
code.write("const char* parm1;\n");
|
||||||
|
code.write("int (*parm2)(float);\n");
|
||||||
|
code.write("{}");
|
||||||
|
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( 3, parameterDecls.size() );
|
||||||
|
ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 );
|
||||||
|
assertNotNull( parm1.getDeclSpecifier().getName() );
|
||||||
|
assertEquals( "parm1", parm1.getDeclSpecifier().getName().toString() );
|
||||||
|
List parm1Decls = parm1.getDeclarators();
|
||||||
|
assertEquals( 1, parm1Decls.size() );
|
||||||
|
|
||||||
|
ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 );
|
||||||
|
assertNotNull( parm2.getDeclSpecifier().getName() );
|
||||||
|
assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() );
|
||||||
|
List parm2Decls = parm2.getDeclarators();
|
||||||
|
assertEquals( 1, parm2Decls.size() );
|
||||||
|
|
||||||
|
ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 );
|
||||||
|
assertNotNull( parm3.getDeclSpecifier().getName() );
|
||||||
|
assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() );
|
||||||
|
List parm3Decls = parm3.getDeclarators();
|
||||||
|
assertEquals( 1, parm3Decls.size() );
|
||||||
|
|
||||||
|
OldKRParameterDeclarationClause clause = pdc.getOldKRParms();
|
||||||
|
assertNotNull( clause );
|
||||||
|
assertEquals( clause.getDeclarations().size(), 2 );
|
||||||
|
SimpleDeclaration decl1 = (SimpleDeclaration)clause.getDeclarations().get(0);
|
||||||
|
assertEquals( decl1.getDeclarators().size(), 1 );
|
||||||
|
assertTrue(decl1.getDeclSpecifier().isConst());
|
||||||
|
assertFalse(decl1.getDeclSpecifier().isVolatile());
|
||||||
|
assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char);
|
||||||
|
Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 );
|
||||||
|
assertEquals( declarator1.getName().toString(), "parm1" );
|
||||||
|
Expression initValue1 = declarator1.getExpression();
|
||||||
|
List ptrOps1 = declarator1.getPointerOperators();
|
||||||
|
assertNotNull( ptrOps1 );
|
||||||
|
assertEquals( 1, ptrOps1.size() );
|
||||||
|
PointerOperator po1 = (PointerOperator)ptrOps1.get(0);
|
||||||
|
assertNotNull( po1 );
|
||||||
|
assertFalse( po1.isConst() );
|
||||||
|
assertFalse( po1.isVolatile() );
|
||||||
|
assertEquals( po1.getType(), PointerOperator.t_pointer );
|
||||||
|
|
||||||
|
SimpleDeclaration declaration = (SimpleDeclaration)clause.getDeclarations().get(1);
|
||||||
|
assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int );
|
||||||
|
assertEquals( declaration.getDeclarators().size(), 1);
|
||||||
|
assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() );
|
||||||
|
assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() );
|
||||||
|
assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "parm2" );
|
||||||
|
ParameterDeclarationClause clause2 = ((Declarator)declaration.getDeclarators().get(0)).getParms();
|
||||||
|
assertEquals( clause2.getDeclarations().size(), 1 );
|
||||||
|
assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), 1 );
|
||||||
|
assertNull( ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() );
|
||||||
|
assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_float );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue