mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 14:15:23 +02:00
Fixed Bug 80992 - [Parser2] C Parser only handles 1 type-qualifier in array modifier
This commit is contained in:
parent
3d9e0a2190
commit
02b95b6d5c
2 changed files with 37 additions and 22 deletions
|
@ -45,7 +45,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
|
@ -61,6 +60,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
|
||||
|
@ -70,7 +70,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
@ -1411,5 +1410,19 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals( ((IBasicType)((IFunctionType)((IPointerType)((ITypedef)((IFunctionType)signal3_t).getParameterTypes()[1]).getType()).getType()).getParameterTypes()[0]).getType(), IBasicType.t_int );
|
||||
|
||||
}
|
||||
|
||||
public void testBug80992() throws Exception
|
||||
{
|
||||
StringBuffer buffer =new StringBuffer( "const int x = 10;\n"); //$NON-NLS-1$
|
||||
buffer.append( "int y [ const static x ];"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
|
||||
IASTDeclaration [] declarations = tu.getDeclarations();
|
||||
IASTSimpleDeclaration y = (IASTSimpleDeclaration) declarations[1];
|
||||
ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator)y.getDeclarators()[0]).getArrayModifiers()[0];
|
||||
assertTrue( mod.isConst() );
|
||||
assertTrue( mod.isStatic() );
|
||||
assertFalse( mod.isRestrict() );
|
||||
assertFalse( mod.isVolatile() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1776,16 +1776,29 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
//eat the '['
|
||||
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
||||
|
||||
int modifier = -1;
|
||||
boolean isStatic = false;
|
||||
boolean isConst = false;
|
||||
boolean isRestrict = false;
|
||||
boolean isVolatile = false;
|
||||
|
||||
outerLoop: do {
|
||||
switch (LT(1)) {
|
||||
case IToken.t_static:
|
||||
isStatic = true;
|
||||
consume();
|
||||
break;
|
||||
case IToken.t_const:
|
||||
isConst = true;
|
||||
consume();
|
||||
break;
|
||||
case IToken.t_volatile:
|
||||
isVolatile = true;
|
||||
consume();
|
||||
break;
|
||||
case IToken.t_restrict:
|
||||
modifier = consume().getType();
|
||||
continue;
|
||||
isRestrict = true;
|
||||
consume();
|
||||
break;
|
||||
default:
|
||||
break outerLoop;
|
||||
}
|
||||
|
@ -1794,7 +1807,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTExpression exp = null;
|
||||
|
||||
if (LT(1) != IToken.tRBRACKET) {
|
||||
if (modifier != -1 )
|
||||
if (!( isStatic || isRestrict || isConst || isVolatile ))
|
||||
exp = assignmentExpression();
|
||||
else
|
||||
exp = constantExpression();
|
||||
|
@ -1802,26 +1815,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
consume(IToken.tRBRACKET);
|
||||
|
||||
IASTArrayModifier arrayMod = null;
|
||||
if( modifier == -1 )
|
||||
if(!( isStatic || isRestrict || isConst || isVolatile ))
|
||||
arrayMod = createArrayModifier();
|
||||
else
|
||||
{
|
||||
ICASTArrayModifier temp = createCArrayModifier();
|
||||
switch( modifier )
|
||||
{
|
||||
case IToken.t_static:
|
||||
temp.setConst( true );
|
||||
break;
|
||||
case IToken.t_const:
|
||||
temp.setConst( true );
|
||||
break;
|
||||
case IToken.t_volatile:
|
||||
temp.setVolatile( true );
|
||||
break;
|
||||
case IToken.t_restrict:
|
||||
temp.setRestrict( true );
|
||||
break;
|
||||
}
|
||||
temp.setStatic( isStatic );
|
||||
temp.setConst( isConst );
|
||||
temp.setVolatile( isVolatile );
|
||||
temp.setRestrict(isRestrict);
|
||||
arrayMod = temp;
|
||||
}
|
||||
((ASTNode)arrayMod).setOffset( startOffset );
|
||||
|
|
Loading…
Add table
Reference in a new issue