mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 07:55:24 +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.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||||
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.ICompositeType;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
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.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
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.ICASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
|
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.c.ICFunctionScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
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.CFunction;
|
||||||
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.parser.ParserException;
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
|
@ -1412,4 +1411,18 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 '['
|
//eat the '['
|
||||||
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
||||||
|
|
||||||
int modifier = -1;
|
boolean isStatic = false;
|
||||||
|
boolean isConst = false;
|
||||||
|
boolean isRestrict = false;
|
||||||
|
boolean isVolatile = false;
|
||||||
|
|
||||||
outerLoop: do {
|
outerLoop: do {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.t_static:
|
case IToken.t_static:
|
||||||
|
isStatic = true;
|
||||||
|
consume();
|
||||||
|
break;
|
||||||
case IToken.t_const:
|
case IToken.t_const:
|
||||||
|
isConst = true;
|
||||||
|
consume();
|
||||||
|
break;
|
||||||
case IToken.t_volatile:
|
case IToken.t_volatile:
|
||||||
|
isVolatile = true;
|
||||||
|
consume();
|
||||||
|
break;
|
||||||
case IToken.t_restrict:
|
case IToken.t_restrict:
|
||||||
modifier = consume().getType();
|
isRestrict = true;
|
||||||
continue;
|
consume();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break outerLoop;
|
break outerLoop;
|
||||||
}
|
}
|
||||||
|
@ -1794,7 +1807,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTExpression exp = null;
|
IASTExpression exp = null;
|
||||||
|
|
||||||
if (LT(1) != IToken.tRBRACKET) {
|
if (LT(1) != IToken.tRBRACKET) {
|
||||||
if (modifier != -1 )
|
if (!( isStatic || isRestrict || isConst || isVolatile ))
|
||||||
exp = assignmentExpression();
|
exp = assignmentExpression();
|
||||||
else
|
else
|
||||||
exp = constantExpression();
|
exp = constantExpression();
|
||||||
|
@ -1802,26 +1815,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
consume(IToken.tRBRACKET);
|
consume(IToken.tRBRACKET);
|
||||||
|
|
||||||
IASTArrayModifier arrayMod = null;
|
IASTArrayModifier arrayMod = null;
|
||||||
if( modifier == -1 )
|
if(!( isStatic || isRestrict || isConst || isVolatile ))
|
||||||
arrayMod = createArrayModifier();
|
arrayMod = createArrayModifier();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ICASTArrayModifier temp = createCArrayModifier();
|
ICASTArrayModifier temp = createCArrayModifier();
|
||||||
switch( modifier )
|
temp.setStatic( isStatic );
|
||||||
{
|
temp.setConst( isConst );
|
||||||
case IToken.t_static:
|
temp.setVolatile( isVolatile );
|
||||||
temp.setConst( true );
|
temp.setRestrict(isRestrict);
|
||||||
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;
|
|
||||||
}
|
|
||||||
arrayMod = temp;
|
arrayMod = temp;
|
||||||
}
|
}
|
||||||
((ASTNode)arrayMod).setOffset( startOffset );
|
((ASTNode)arrayMod).setOffset( startOffset );
|
||||||
|
|
Loading…
Add table
Reference in a new issue