mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 15:05:36 +02:00
Fixes CArrayType.getArraySizeExpression(), bug 273797.
This commit is contained in:
parent
71638ab566
commit
1e31821df4
9 changed files with 92 additions and 123 deletions
|
@ -6279,4 +6279,25 @@ public class AST2Tests extends AST2BaseTest {
|
|||
public void testPredefinedMacroNamesC() throws Exception {
|
||||
parseAndCheckBindings(getAboveComment(), ParserLanguage.C);
|
||||
}
|
||||
|
||||
//
|
||||
// int MyGlobal[10];
|
||||
//
|
||||
public void testBug273797() throws Exception {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C);
|
||||
IASTName n = ((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclarators()[0].getName();
|
||||
IVariable v = (IVariable) n.resolveBinding();
|
||||
|
||||
ICArrayType t = (ICArrayType)v.getType();
|
||||
assertFalse(t.isConst());
|
||||
assertFalse(t.isRestrict());
|
||||
assertFalse(t.isVolatile());
|
||||
assertFalse(t.isVariableLength());
|
||||
assertFalse(t.isStatic());
|
||||
|
||||
IASTExpression e = t.getArraySizeExpression();
|
||||
assertNotNull(e);
|
||||
assertTrue(e instanceof IASTLiteralExpression);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public interface ICNodeFactory extends INodeFactory {
|
|||
|
||||
public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
|
||||
|
||||
public ICASTArrayModifier newModifiedArrayModifier(IASTExpression expr);
|
||||
public ICASTArrayModifier newArrayModifier(IASTExpression expr);
|
||||
|
||||
public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
|
||||
|
||||
|
|
|
@ -1,30 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
* c-specific modifier for array specifiers.
|
||||
*/
|
||||
public class CASTArrayModifier extends ASTNode implements IASTArrayModifier, IASTAmbiguityParent {
|
||||
public class CASTArrayModifier extends ASTNode implements ICASTArrayModifier, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression exp;
|
||||
|
||||
private boolean isVolatile;
|
||||
private boolean isRestrict;
|
||||
private boolean isStatic;
|
||||
private boolean isConst;
|
||||
private boolean isVarSized;
|
||||
|
||||
public CASTArrayModifier() {
|
||||
}
|
||||
|
@ -36,6 +40,11 @@ public class CASTArrayModifier extends ASTNode implements IASTArrayModifier, IAS
|
|||
public CASTArrayModifier copy() {
|
||||
CASTArrayModifier copy = new CASTArrayModifier(exp == null ? null : exp.copy());
|
||||
copy.setOffsetAndLength(this);
|
||||
copy.isVolatile = isVolatile;
|
||||
copy.isRestrict = isRestrict;
|
||||
copy.isStatic = isStatic;
|
||||
copy.isConst = isConst;
|
||||
copy.isVarSized = isVarSized;
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
@ -51,6 +60,51 @@ public class CASTArrayModifier extends ASTNode implements IASTArrayModifier, IAS
|
|||
expression.setPropertyInParent(CONSTANT_EXPRESSION);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConst() {
|
||||
return isConst;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return isStatic;
|
||||
}
|
||||
|
||||
public boolean isRestrict() {
|
||||
return isRestrict;
|
||||
}
|
||||
|
||||
public boolean isVolatile() {
|
||||
return isVolatile;
|
||||
}
|
||||
|
||||
public void setConst(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isConst = value;
|
||||
}
|
||||
|
||||
public void setVolatile(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isVolatile = value;
|
||||
}
|
||||
|
||||
public void setRestrict(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isRestrict = value;
|
||||
}
|
||||
|
||||
public void setStatic(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isStatic = value;
|
||||
}
|
||||
|
||||
public boolean isVariableSized() {
|
||||
return isVarSized;
|
||||
}
|
||||
|
||||
public void setVariableSized(boolean value) {
|
||||
assertNotFrozen();
|
||||
isVarSized = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTModifiedArrayModifier extends CASTArrayModifier implements ICASTArrayModifier {
|
||||
|
||||
private boolean isVolatile;
|
||||
private boolean isRestrict;
|
||||
private boolean isStatic;
|
||||
private boolean isConst;
|
||||
private boolean varSized;
|
||||
|
||||
public CASTModifiedArrayModifier() {
|
||||
}
|
||||
|
||||
public CASTModifiedArrayModifier(IASTExpression exp) {
|
||||
super(exp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CASTModifiedArrayModifier copy() {
|
||||
IASTExpression exp = getConstantExpression();
|
||||
CASTModifiedArrayModifier copy = new CASTModifiedArrayModifier(exp == null ? null : exp.copy());
|
||||
copy.isVolatile = isVolatile;
|
||||
copy.isRestrict = isRestrict;
|
||||
copy.isStatic = isStatic;
|
||||
copy.isConst = isConst;
|
||||
copy.varSized = varSized;
|
||||
copy.setOffsetAndLength(this);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public boolean isConst() {
|
||||
return isConst;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return isStatic;
|
||||
}
|
||||
|
||||
public boolean isRestrict() {
|
||||
return isRestrict;
|
||||
}
|
||||
|
||||
public boolean isVolatile() {
|
||||
return isVolatile;
|
||||
}
|
||||
|
||||
public void setConst(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isConst = value;
|
||||
}
|
||||
|
||||
public void setVolatile(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isVolatile = value;
|
||||
}
|
||||
|
||||
public void setRestrict(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isRestrict = value;
|
||||
}
|
||||
|
||||
public void setStatic(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isStatic = value;
|
||||
}
|
||||
|
||||
public boolean isVariableSized() {
|
||||
return varSized;
|
||||
}
|
||||
|
||||
public void setVariableSized(boolean value) {
|
||||
assertNotFrozen();
|
||||
varSized = value;
|
||||
}
|
||||
}
|
|
@ -69,7 +69,7 @@ public class CArrayType implements ICArrayType, ITypeContainer {
|
|||
this.type = t;
|
||||
}
|
||||
|
||||
public void setModifiedArrayModifier(ICASTArrayModifier mod) {
|
||||
public void setModifier(ICASTArrayModifier mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||
|
@ -172,14 +171,10 @@ public class CNodeFactory implements ICNodeFactory {
|
|||
return new CASTArrayDeclarator(name);
|
||||
}
|
||||
|
||||
public IASTArrayModifier newArrayModifier(IASTExpression expr) {
|
||||
public ICASTArrayModifier newArrayModifier(IASTExpression expr) {
|
||||
return new CASTArrayModifier(expr);
|
||||
}
|
||||
|
||||
public ICASTArrayModifier newModifiedArrayModifier(IASTExpression expr) {
|
||||
return new CASTModifiedArrayModifier(expr);
|
||||
}
|
||||
|
||||
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
|
||||
return new CASTFunctionDeclarator(name);
|
||||
}
|
||||
|
|
|
@ -1437,7 +1437,7 @@ public class CVisitor extends ASTQueries {
|
|||
for (IASTArrayModifier mod : mods) {
|
||||
CArrayType arrayType = new CArrayType(lastType);
|
||||
if (mod instanceof ICASTArrayModifier) {
|
||||
arrayType.setModifiedArrayModifier((ICASTArrayModifier)mod);
|
||||
arrayType.setModifier((ICASTArrayModifier)mod);
|
||||
}
|
||||
lastType= arrayType;
|
||||
}
|
||||
|
|
|
@ -1711,23 +1711,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
throw backtrack;
|
||||
}
|
||||
|
||||
|
||||
IASTArrayModifier arrayMod;
|
||||
if (!(isStatic || isRestrict || isConst || isVolatile || isVarSized))
|
||||
arrayMod = nodeFactory.newArrayModifier(null);
|
||||
else {
|
||||
ICASTArrayModifier temp = nodeFactory.newModifiedArrayModifier(null);
|
||||
temp.setStatic(isStatic);
|
||||
temp.setConst(isConst);
|
||||
temp.setVolatile(isVolatile);
|
||||
temp.setRestrict(isRestrict);
|
||||
temp.setVariableSized(isVarSized);
|
||||
arrayMod = temp;
|
||||
}
|
||||
ICASTArrayModifier arrayMod = nodeFactory.newArrayModifier(exp);
|
||||
arrayMod.setStatic(isStatic);
|
||||
arrayMod.setConst(isConst);
|
||||
arrayMod.setVolatile(isVolatile);
|
||||
arrayMod.setRestrict(isRestrict);
|
||||
arrayMod.setVariableSized(isVarSized);
|
||||
((ASTNode) arrayMod).setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
if (exp != null) {
|
||||
arrayMod.setConstantExpression(exp);
|
||||
}
|
||||
arrayMods.add(arrayMod);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
|
|||
boolean isVarSized, boolean hasTypeQualifierList, boolean hasAssignmentExpr) {
|
||||
assert isStatic || isVarSized || hasTypeQualifierList;
|
||||
|
||||
ICASTArrayModifier arrayModifier = nodeFactory.newModifiedArrayModifier(null);
|
||||
ICASTArrayModifier arrayModifier = nodeFactory.newArrayModifier(null);
|
||||
|
||||
// consume all the stuff between the square brackets into an array modifier
|
||||
arrayModifier.setStatic(isStatic);
|
||||
|
|
Loading…
Add table
Reference in a new issue