1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 12:25:35 +02:00

Fix for 190799 by Richard Miskin, functions with multiple attributes.

This commit is contained in:
Markus Schorn 2007-06-06 11:16:10 +00:00
parent 4271cea90d
commit 2076eb6dc5
3 changed files with 47 additions and 42 deletions

View file

@ -2230,6 +2230,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return parseDeclarationOrExpressionStatement(); return parseDeclarationOrExpressionStatement();
} }
/**
* Accept a sequence of __attribute__ or __declspec
*
* @param allowAttrib if true accept any number of __attribute__
* @param allowDeclspec if true accept any number of __declspec
* @throws BacktrackException
* @throws EndOfFileException
*/
protected void __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec) throws BacktrackException, EndOfFileException {
while (true) {
IToken token = LA(1);
if ( allowAttrib && (token.getType() == IGCCToken.t__attribute__)) {
__attribute__();
} else if (allowDeclspec && (token.getType() == IGCCToken.t__declspec)) {
__declspec();
} else {
break;
}
}
}
protected void __attribute__() throws BacktrackException, EndOfFileException { protected void __attribute__() throws BacktrackException, EndOfFileException {
IToken token = LA(1); IToken token = LA(1);

View file

@ -1591,13 +1591,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} }
case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec
if (supportAttributeSpecifiers) if (supportAttributeSpecifiers)
__attribute__(); __attribute_decl_seq(true, false);
else else
throwBacktrack(LA(1).getOffset(), LA(1).getLength()); throwBacktrack(LA(1).getOffset(), LA(1).getLength());
break; break;
case IGCCToken.t__declspec: // __declspec precedes the identifier case IGCCToken.t__declspec: // __declspec precedes the identifier
if (identifier == null && supportDeclspecSpecifiers) if (identifier == null && supportDeclspecSpecifiers)
__declspec(); __attribute_decl_seq(false, true);
else else
throwBacktrack(LA(1).getOffset(), LA(1).getLength()); throwBacktrack(LA(1).getOffset(), LA(1).getLength());
break; break;
@ -1755,10 +1755,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
throwBacktrack(mark.getOffset(), mark.getLength()); throwBacktrack(mark.getOffset(), mark.getLength());
} }
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ occurs after struct/union/class and before the identifier // if __attribute__ or __declspec occurs after struct/union/class and before the identifier
__attribute__(); __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
if (LT(1) == IGCCToken.t__declspec && supportDeclspecSpecifiers) // if __declspec occurs after struct/union/class and before the identifier
__declspec();
IToken nameToken = null; IToken nameToken = null;
// class name // class name
@ -1766,10 +1764,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
nameToken = identifier(); nameToken = identifier();
} }
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ occurs after struct/union/class identifier and before the { or ; // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ;
__attribute__(); __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
if (LT(1) == IGCCToken.t__declspec && supportDeclspecSpecifiers) // if __declspec occurs after struct/union/class and before the identifier
__declspec();
if (LT(1) != IToken.tLBRACE) { if (LT(1) != IToken.tLBRACE) {
IToken errorPoint = LA(1); IToken errorPoint = LA(1);
@ -1914,11 +1910,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
consumePointerOperators(pointerOps); consumePointerOperators(pointerOps);
// if __attribute__ is after the pointer ops and before the declarator ex: void * __attribute__((__cdecl__)) foo(); // Accept __attribute__ or __declspec after the pointer ops and before the declarator ex: void * __attribute__((__cdecl__)) foo();
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ is after the parameters __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
__attribute__();
if (LT(1) == IGCCToken.t__declspec && supportDeclspecSpecifiers) // if __declspec is after the parameters
__declspec();
if (!pointerOps.isEmpty()) { if (!pointerOps.isEmpty()) {
finalOffset = calculateEndOffset((IASTPointerOperator) pointerOps finalOffset = calculateEndOffset((IASTPointerOperator) pointerOps
@ -2083,13 +2076,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
break; break;
case IGCCToken.t__attribute__: // if __attribute__ is after the declarator case IGCCToken.t__attribute__: // if __attribute__ is after the declarator
if(supportAttributeSpecifiers) if(supportAttributeSpecifiers)
__attribute__(); __attribute_decl_seq(true, false);
else else
throwBacktrack(LA(1).getOffset(), LA(1).getLength()); throwBacktrack(LA(1).getOffset(), LA(1).getLength());
break; break;
case IGCCToken.t__declspec: case IGCCToken.t__declspec:
if(supportDeclspecSpecifiers) if(supportDeclspecSpecifiers)
__declspec(); __attribute_decl_seq(false, true);
else else
throwBacktrack(LA(1).getOffset(), LA(1).getLength()); throwBacktrack(LA(1).getOffset(), LA(1).getLength());
break; break;
@ -2101,11 +2094,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} while (false); } while (false);
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ is after the parameters // Consume any number of __attribute__ and __declspec tokens after the parameters
__attribute__(); __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
if (LT(1) == IGCCToken.t__declspec && supportDeclspecSpecifiers) // if __attribute__ is after the parameters
__declspec();
IASTDeclarator d = null; IASTDeclarator d = null;
if (numKnRCParms > 0) { if (numKnRCParms > 0) {

View file

@ -3501,13 +3501,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} }
case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec
if (supportAttributeSpecifiers) if (supportAttributeSpecifiers)
__attribute__(); __attribute_decl_seq(true, false);
else else
throwBacktrack(LA(1).getOffset(), LA(1).getLength()); throwBacktrack(LA(1).getOffset(), LA(1).getLength());
break; break;
case IGCCToken.t__declspec: // if __declspec appears before identifier case IGCCToken.t__declspec: // if __declspec appears before identifier
if (duple == null && supportDeclspecSpecifiers) if (duple == null && supportDeclspecSpecifiers)
__declspec(); __attribute_decl_seq(false, true);
else else
throwBacktrack(LA(1).getOffset(), LA(1).getLength()); throwBacktrack(LA(1).getOffset(), LA(1).getLength());
break; break;
@ -3895,10 +3895,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
consumePointerOperators(pointerOps); consumePointerOperators(pointerOps);
// if __attribute__ is after the pointer ops and before the declarator ex: void * __attribute__((__cdecl__)) foo(); // if __attribute__ is after the pointer ops and before the declarator ex: void * __attribute__((__cdecl__)) foo();
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ is after the parameters __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
__attribute__();
if (LT(1) == IGCCToken.t__declspec && supportDeclspecSpecifiers) // if __declspec occurs after struct/union/class and before the identifier
__declspec();
if (!pointerOps.isEmpty()) if (!pointerOps.isEmpty())
finalOffset = calculateEndOffset((IASTNode) pointerOps finalOffset = calculateEndOffset((IASTNode) pointerOps
@ -4013,8 +4010,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
break overallLoop; break overallLoop;
} }
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ is after the parameters // Consume any number of __attribute__ tokens after the parameters
__attribute__(); __attribute_decl_seq(supportAttributeSpecifiers, false);
IToken beforeCVModifier = mark(); IToken beforeCVModifier = mark();
IToken[] cvModifiers = new IToken[2]; IToken[] cvModifiers = new IToken[2];
@ -4116,7 +4114,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
break; break;
case IGCCToken.t__attribute__: // if __attribute__ is after the declarator case IGCCToken.t__attribute__: // if __attribute__ is after the declarator
if(supportAttributeSpecifiers) if(supportAttributeSpecifiers)
__attribute__(); __attribute_decl_seq(supportAttributeSpecifiers, false);
else else
throwBacktrack(LA(1).getOffset(), LA(1).getLength()); throwBacktrack(LA(1).getOffset(), LA(1).getLength());
break; break;
@ -4324,10 +4322,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTName name = null; IASTName name = null;
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ occurs after struct/union/class and before the identifier // if __attribute__ or __declspec occurs after struct/union/class and before the identifier
__attribute__(); __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
if (LT(1) == IGCCToken.t__declspec && supportDeclspecSpecifiers) // if __declspec occurs after struct/union/class and before the identifier
__declspec();
// class name // class name
if (LT(1) == IToken.tIDENTIFIER) if (LT(1) == IToken.tIDENTIFIER)
@ -4335,10 +4331,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
else else
name = createName(); name = createName();
if (LT(1) == IGCCToken.t__attribute__ && supportAttributeSpecifiers) // if __attribute__ occurs after struct/union/class identifier and before the { or ; // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ;
__attribute__(); __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
if (LT(1) == IGCCToken.t__declspec && supportDeclspecSpecifiers) // if __declspec occurs after struct/union/class and before the identifier
__declspec();
if (LT(1) != IToken.tCOLON && LT(1) != IToken.tLBRACE) { if (LT(1) != IToken.tCOLON && LT(1) != IToken.tLBRACE) {
IToken errorPoint = LA(1); IToken errorPoint = LA(1);