Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2010-01-15 18:28:45 +0000
committerMarkus Schorn2010-01-15 18:28:45 +0000
commit5a1293b690c1ec4b51fca1715d546d9e03ba9891 (patch)
tree4ab776e3bb3a6a3ba1d725edd73d8d2f15214b3b /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom
parent64c58d177664a4482d96be96068d255af7ff96c5 (diff)
downloadorg.eclipse.cdt-5a1293b690c1ec4b51fca1715d546d9e03ba9891.tar.gz
org.eclipse.cdt-5a1293b690c1ec4b51fca1715d546d9e03ba9891.tar.xz
org.eclipse.cdt-5a1293b690c1ec4b51fca1715d546d9e03ba9891.zip
Bug 294730: Declared type of an expression.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java39
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCASTSimpleDeclSpecifier.java61
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java24
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java26
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java30
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java75
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java22
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java64
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java99
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java69
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java19
18 files changed, 304 insertions, 278 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index ba03031274d..70b0d5b8fe0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 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
@@ -2104,7 +2104,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
protected IASTStatement parseDefaultStatement() throws EndOfFileException, BacktrackException {
- int startOffset = consume().getOffset(); // t_default
+ int startOffset = consume(IToken.t_default).getOffset();
int lastOffset = consume(IToken.tCOLON).getEndOffset();
IASTDefaultStatement df = nodeFactory.newDefaultStatement();
@@ -2243,7 +2243,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return result1;
}
- IASTExpression result2= buildUnaryExpression(unaryExprKind, expr, offset, endOffset2);
+ IASTExpression result2= unaryExprKind == -1 ? expr : buildUnaryExpression(unaryExprKind, expr, offset, endOffset2);
if (ca != null)
result2= ca.updateExpression(result2);
@@ -2444,6 +2444,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
case IToken.t__Imaginary:
case IToken.t_signed:
case IToken.t_unsigned:
+ case IToken.t_decltype:
// class-specifier:
case IToken.t_class:
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
index 3e80a5e342f..88ac199cb3e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2010 Wind River Systems, Inc. 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
@@ -43,7 +43,6 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
-import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
/**
@@ -260,8 +259,7 @@ public abstract class VariableReadWriteFlags {
case IASTUnaryExpression.op_sizeof:
case IASTUnaryExpression.op_sizeofParameterPack:
- case IGNUASTUnaryExpression.op_alignOf:
- case IGNUASTUnaryExpression.op_typeof:
+ case IASTUnaryExpression.op_alignOf:
return 0;
}
return READ;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java
index 89bad1ab150..269b383f89d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 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
@@ -13,10 +13,14 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
-public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements ICASTSimpleDeclSpecifier {
+public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements ICASTSimpleDeclSpecifier,
+ IASTAmbiguityParent {
private int simpleType;
private boolean isSigned;
@@ -26,6 +30,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
private boolean longlong;
private boolean complex=false;
private boolean imaginary=false;
+ private IASTExpression fDeclTypeExpression;
public CASTSimpleDeclSpecifier copy() {
CASTSimpleDeclSpecifier copy = new CASTSimpleDeclSpecifier();
@@ -43,9 +48,10 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
copy.longlong = longlong;
copy.complex = complex;
copy.imaginary = imaginary;
+ if (fDeclTypeExpression != null)
+ copy.setDeclTypeExpression(fDeclTypeExpression.copy());
}
-
public int getType() {
return simpleType;
}
@@ -78,7 +84,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
private int getType(Kind kind) {
switch(kind) {
case eBoolean:
- return t_Bool;
+ return t_bool;
case eChar:
case eWChar:
return t_char;
@@ -134,6 +140,10 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
default : break;
}
}
+
+ if (fDeclTypeExpression != null && !fDeclTypeExpression.accept(action))
+ return false;
+
if( action.shouldVisitDeclSpecifiers ){
switch( action.leave( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
@@ -161,4 +171,25 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
assertNotFrozen();
this.imaginary = value;
}
+
+ public IASTExpression getDeclTypeExpression() {
+ return fDeclTypeExpression;
+ }
+
+ public void setDeclTypeExpression(IASTExpression expression) {
+ assertNotFrozen();
+ fDeclTypeExpression= expression;
+ if (expression != null) {
+ expression.setPropertyInParent(DECLTYPE_EXPRESSION);
+ expression.setParent(this);
+ }
+ }
+
+ public void replace(IASTNode child, IASTNode other) {
+ if (child == fDeclTypeExpression) {
+ other.setPropertyInParent(child.getPropertyInParent());
+ other.setParent(child.getParent());
+ fDeclTypeExpression= (IASTExpression) other;
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
index de7c37d7d38..6a952ec16cc 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 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
@@ -77,7 +77,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICNodeFactory;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
-import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.internal.core.dom.parser.NodeFactory;
@@ -349,7 +348,8 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
return new CASTArrayRangeDesignator(floor, ceiling);
}
- public IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) {
+ @Deprecated
+ public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) {
return new GCCASTSimpleDeclSpecifier(typeofExpression);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java
index b9bdc9d6b16..48cc051427d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 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
@@ -34,12 +34,12 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
-import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
@@ -50,7 +50,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
-import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileSet;
@@ -306,8 +305,8 @@ public class CScope implements ICScope, IASTInternalScope {
}
IASTNode parent= name.getParent();
while (parent != null) {
- if (parent instanceof IASTUnaryExpression) {
- if (((IASTUnaryExpression) parent).getOperator() == IGNUASTUnaryExpression.op_typeof)
+ if (parent instanceof IASTSimpleDeclSpecifier) {
+ if (((IASTSimpleDeclSpecifier) parent).getDeclTypeExpression() != null)
return false;
}
else if (parent instanceof IASTTypeIdExpression) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index bbbeaef1486..2e78f81f1e0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 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
@@ -83,7 +83,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
-import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
@@ -1332,13 +1331,12 @@ public class CVisitor extends ASTQueries {
* @return the base IType
*/
public static IType createBaseType(IASTDeclSpecifier declSpec) {
- if (declSpec instanceof IGCCASTSimpleDeclSpecifier) {
- IASTExpression exp = ((IGCCASTSimpleDeclSpecifier)declSpec).getTypeofExpression();
+ if (declSpec instanceof ICASTSimpleDeclSpecifier) {
+ final ICASTSimpleDeclSpecifier sds = (ICASTSimpleDeclSpecifier)declSpec;
+ IASTExpression exp = sds.getDeclTypeExpression();
if (exp != null)
return exp.getExpressionType();
- return new CBasicType((ICASTSimpleDeclSpecifier) declSpec);
- } else if (declSpec instanceof ICASTSimpleDeclSpecifier) {
- return new CBasicType((ICASTSimpleDeclSpecifier)declSpec);
+ return new CBasicType(sds);
}
IBinding binding = null;
IASTName name = null;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCASTSimpleDeclSpecifier.java
index f1977c8de6d..be7031e023e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCASTSimpleDeclSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCASTSimpleDeclSpecifier.java
@@ -1,33 +1,28 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 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 Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
* Emanuel Graf IFS - Bugfix for #198257
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
-import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
- * @author aniefer
- *
+ * @deprecated Replaced by {@link CASTSimpleDeclSpecifier}.
*/
-public class GCCASTSimpleDeclSpecifier extends CASTSimpleDeclSpecifier implements IGCCASTSimpleDeclSpecifier, IASTAmbiguityParent {
-
- private IASTExpression typeOfExpression;
+@Deprecated
+public class GCCASTSimpleDeclSpecifier extends CASTSimpleDeclSpecifier implements IGCCASTSimpleDeclSpecifier {
public GCCASTSimpleDeclSpecifier() {
}
-
+
public GCCASTSimpleDeclSpecifier(IASTExpression typeofExpression) {
setTypeofExpression(typeofExpression);
}
@@ -36,50 +31,14 @@ public class GCCASTSimpleDeclSpecifier extends CASTSimpleDeclSpecifier implement
public GCCASTSimpleDeclSpecifier copy() {
GCCASTSimpleDeclSpecifier copy = new GCCASTSimpleDeclSpecifier();
copySimpleDeclSpec(copy);
- copy.setTypeofExpression(typeOfExpression == null ? null : typeOfExpression.copy());
return copy;
}
-
- public void setTypeofExpression(IASTExpression typeofExpression) {
- this.typeOfExpression = typeofExpression;
- if (typeofExpression != null) {
- typeofExpression.setParent(this);
- typeofExpression.setPropertyInParent(TYPEOF_EXPRESSION);
- }
- }
- public IASTExpression getTypeofExpression() {
- return typeOfExpression;
+ public void setTypeofExpression(IASTExpression expr) {
+ setDeclTypeExpression(expr);
}
- @Override
- public boolean accept( ASTVisitor action ){
- if( action.shouldVisitDeclSpecifiers ){
- switch( action.visit( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- if( typeOfExpression != null )
- if( !typeOfExpression.accept( action ) ) return false;
-
- if( action.shouldVisitDeclSpecifiers ){
- switch( action.leave( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
-
- return true;
- }
-
- public void replace(IASTNode child, IASTNode other) {
- if (child == typeOfExpression) {
- other.setPropertyInParent(child.getPropertyInParent());
- other.setParent(child.getParent());
- typeOfExpression= (IASTExpression) other;
- }
+ public IASTExpression getTypeofExpression() {
+ return getDeclTypeExpression();
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index 7c2c647b234..8d19058bba6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 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
@@ -71,7 +71,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICNodeFactory;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
-import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
import org.eclipse.cdt.core.dom.parser.IExtensionToken;
@@ -589,9 +588,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
case IToken.t_sizeof:
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx);
- case IGCCToken.t_typeof:
- return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
- IASTTypeIdExpression.op_typeof, IASTUnaryExpression.op_typeof, ctx);
case IGCCToken.t___alignof__:
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx);
@@ -1004,7 +1000,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
case IToken.t__Bool:
if (encounteredTypename)
break declSpecifiers;
- simpleType = ICASTSimpleDeclSpecifier.t_Bool;
+ simpleType = IASTSimpleDeclSpecifier.t_bool;
encounteredRawType= true;
endOffset= consume().getEndOffset();
break;
@@ -1081,8 +1077,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (encounteredRawType || encounteredTypename)
throwBacktrack(LA(1));
- typeofExpression = parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
- IGNUASTTypeIdExpression.op_typeof, IGNUASTUnaryExpression.op_typeof, CastExprCtx.eNotBExpr);
+ simpleType= IASTSimpleDeclSpecifier.t_typeof;
+ consume(IGCCToken.t_typeof);
+ typeofExpression = parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(),
+ IGNUASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotBExpr);
encounteredTypename= true;
endOffset= calculateEndOffset(typeofExpression);
@@ -1155,11 +1153,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
private ICASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType,
int options, int isLong, IASTExpression typeofExpression, int offset, int endOffset) {
- ICASTSimpleDeclSpecifier declSpec;
- if (typeofExpression != null)
- declSpec = nodeFactory.newSimpleDeclSpecifierGCC(typeofExpression);
- else
- declSpec = nodeFactory.newSimpleDeclSpecifier();
+ ICASTSimpleDeclSpecifier declSpec= nodeFactory.newSimpleDeclSpecifier();
configureDeclSpec(declSpec, storageClass, options);
declSpec.setType(simpleType);
@@ -1171,6 +1165,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
declSpec.setShort((options & SHORT) != 0);
declSpec.setComplex((options & COMPLEX) != 0);
declSpec.setImaginary((options & IMAGINARY) != 0);
+ if (typeofExpression != null) {
+ declSpec.setDeclTypeExpression(typeofExpression);
+ typeofExpression.setParent(declSpec);
+ }
((ASTNode) declSpec).setOffsetAndLength(offset, endOffset - offset);
return declSpec;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java
index f1cbae94fe5..ed5d0f52881 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java
@@ -1,12 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 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 - Initial API and implementation
+ * John Camelon (IBM) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -15,14 +16,15 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/**
- * @author jcamelon
+ * Base for all c++ declaration specifiers
*/
public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPASTDeclSpecifier {
private boolean friend;
private boolean inline;
- private boolean volatil;
private boolean isConst;
+ private boolean isVolatile;
+ private boolean isRestrict;
private int sc;
private boolean virtual;
private boolean explicit;
@@ -50,12 +52,21 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
}
public boolean isVolatile() {
- return volatil;
+ return isVolatile;
}
public void setVolatile(boolean value) {
assertNotFrozen();
- volatil = value;
+ isVolatile = value;
+ }
+
+ public boolean isRestrict() {
+ return isRestrict;
+ }
+
+ public void setRestrict(boolean value) {
+ assertNotFrozen();
+ isRestrict = value;
}
public boolean isInline() {
@@ -93,8 +104,9 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
protected void copyBaseDeclSpec(CPPASTBaseDeclSpecifier other) {
other.friend = friend;
other.inline = inline;
- other.volatil = volatil;
other.isConst = isConst;
+ other.isVolatile = isVolatile;
+ other.isRestrict= isRestrict;
other.virtual = virtual;
other.explicit = explicit;
other.sc = sc;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java
index 12694d6c926..314236c2332 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 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
@@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
-import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
+import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*;
import java.util.ArrayList;
import java.util.List;
@@ -28,10 +28,12 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@@ -39,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReference, IASTAmbiguityParent,
@@ -190,7 +193,28 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen
IBinding binding = name.resolvePreBinding();
try {
if (binding instanceof IVariable) {
- return SemanticUtil.mapToAST(((IVariable) binding).getType(), this);
+ IType e2= ((IVariable) binding).getType();
+ if (binding instanceof ICPPField && !((ICPPField) binding).isStatic()) {
+ IType e1= getFieldOwner().getExpressionType();
+ if (isPointerDereference()) {
+ e1= SemanticUtil.getNestedType(e1, TDEF | REF | CVTYPE);
+ if (e1 instanceof IPointerType) {
+ e1= ((IPointerType) e1).getType();
+ }
+ }
+ CVQualifier cvq1 = SemanticUtil.getCVQualifier(e1);
+ if (((ICPPField) binding).isMutable()) {
+ // Remove const, add union of volatile.
+ CVQualifier cvq2 = SemanticUtil.getCVQualifier(e2);
+ if (cvq2.isConst()) {
+ e2= SemanticUtil.getNestedType(e2, ALLCVQ | TDEF | REF);
+ }
+ e2= SemanticUtil.addQualifiers(e2, false, cvq1.isVolatile() || cvq2.isVolatile());
+ } else {
+ e2= SemanticUtil.addQualifiers(e2, cvq1.isConst(), cvq1.isVolatile());
+ }
+ }
+ return SemanticUtil.mapToAST(e2, this);
} else if (binding instanceof IEnumerator) {
return ((IEnumerator) binding).getType();
} else if (binding instanceof IFunction) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java
index a12fe8b99c8..03dfd9886b2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 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
@@ -12,16 +12,23 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
-public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implements ICPPASTSimpleDeclSpecifier {
-
+public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implements ICPPASTSimpleDeclSpecifier,
+ IASTAmbiguityParent {
private int type;
private boolean isSigned;
private boolean isUnsigned;
private boolean isShort;
private boolean isLong;
+ private boolean isLonglong;
+ private boolean isComplex=false;
+ private boolean isImaginary=false;
+ private IASTExpression fDeclTypeExpression;
public CPPASTSimpleDeclSpecifier copy() {
CPPASTSimpleDeclSpecifier copy = new CPPASTSimpleDeclSpecifier();
@@ -36,6 +43,12 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implement
other.isUnsigned = isUnsigned;
other.isShort = isShort;
other.isLong = isLong;
+ other.isLonglong= isLonglong;
+ other.isComplex= isComplex;
+ other.isImaginary= isImaginary;
+ if (fDeclTypeExpression != null) {
+ other.setDeclTypeExpression(fDeclTypeExpression.copy());
+ }
}
/**
@@ -92,7 +105,23 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implement
return isLong;
}
- public void setSigned(boolean value) {
+ public boolean isLongLong() {
+ return isLonglong;
+ }
+
+ public boolean isComplex() {
+ return isComplex;
+ }
+
+ public boolean isImaginary() {
+ return isImaginary;
+ }
+
+ public IASTExpression getDeclTypeExpression() {
+ return fDeclTypeExpression;
+ }
+
+ public void setSigned(boolean value) {
assertNotFrozen();
isSigned = value;
}
@@ -112,7 +141,31 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implement
isShort = value;
}
- @Override
+ public void setLongLong(boolean value) {
+ assertNotFrozen();
+ isLonglong = value;
+ }
+
+ public void setComplex(boolean value) {
+ assertNotFrozen();
+ isComplex = value;
+ }
+
+ public void setImaginary(boolean value) {
+ assertNotFrozen();
+ isImaginary = value;
+ }
+
+ public void setDeclTypeExpression(IASTExpression expression) {
+ assertNotFrozen();
+ fDeclTypeExpression = expression;
+ if (expression != null) {
+ expression.setPropertyInParent(DECLTYPE_EXPRESSION);
+ expression.setParent(this);
+ }
+ }
+
+ @Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitDeclSpecifiers) {
switch (action.visit(this)) {
@@ -121,6 +174,10 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implement
default: break;
}
}
+
+ if (fDeclTypeExpression != null && !fDeclTypeExpression.accept(action))
+ return false;
+
if (action.shouldVisitDeclSpecifiers) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -130,4 +187,12 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implement
}
return true;
}
+
+ public void replace(IASTNode child, IASTNode other) {
+ if (child == fDeclTypeExpression) {
+ other.setPropertyInParent(child.getPropertyInParent());
+ other.setParent(child.getParent());
+ fDeclTypeExpression= (IASTExpression) other;
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java
index 040c3450fb7..017f52f453c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 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
@@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
-import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.core.runtime.CoreException;
@@ -58,19 +57,14 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
}
private static int getModifiers(ICPPASTSimpleDeclSpecifier sds) {
- int qualifiers=
+ return
( sds.isLong() ? IBasicType.IS_LONG : 0 ) |
( sds.isShort() ? IBasicType.IS_SHORT : 0 ) |
( sds.isSigned() ? IBasicType.IS_SIGNED: 0 ) |
- ( sds.isUnsigned()? IBasicType.IS_UNSIGNED : 0 );
- if (sds instanceof IGPPASTSimpleDeclSpecifier) {
- IGPPASTSimpleDeclSpecifier gsds= (IGPPASTSimpleDeclSpecifier) sds;
- qualifiers |=
- ( gsds.isLongLong()? IBasicType.IS_LONG_LONG : 0 ) |
- ( gsds.isComplex() ? IBasicType.IS_COMPLEX : 0 ) |
- ( gsds.isImaginary()?IBasicType.IS_IMAGINARY : 0 );
- }
- return qualifiers;
+ ( sds.isUnsigned()? IBasicType.IS_UNSIGNED : 0 ) |
+ ( sds.isLongLong()? IBasicType.IS_LONG_LONG : 0 ) |
+ ( sds.isComplex() ? IBasicType.IS_COMPLEX : 0 ) |
+ ( sds.isImaginary()?IBasicType.IS_IMAGINARY : 0 );
}
private static Kind getKind(ICPPASTSimpleDeclSpecifier sds) {
@@ -79,11 +73,11 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
static Kind getKind(final int simpleDeclSpecType) {
switch(simpleDeclSpecType) {
- case ICPPASTSimpleDeclSpecifier.t_bool:
+ case IASTSimpleDeclSpecifier.t_bool:
return Kind.eBoolean;
case IASTSimpleDeclSpecifier.t_char:
return Kind.eChar;
- case ICPPASTSimpleDeclSpecifier.t_wchar_t:
+ case IASTSimpleDeclSpecifier.t_wchar_t:
return Kind.eWChar;
case IASTSimpleDeclSpecifier.t_double:
return Kind.eDouble;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
index 1fe4146c505..67191d5cf51 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 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
@@ -107,7 +107,6 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
-import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.internal.core.dom.parser.NodeFactory;
@@ -356,10 +355,6 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTSimpleDeclSpecifier();
}
- public IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP() {
- return new GPPASTSimpleDeclSpecifier();
- }
-
public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CPPASTFunctionDeclarator(name);
}
@@ -529,4 +524,9 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern) {
return new CPPASTPackExpansionExpression(pattern);
}
+
+ @Deprecated
+ public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP() {
+ return new GPPASTSimpleDeclSpecifier();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index b2938d4127b..c89a43ed554 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -111,11 +111,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
-import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
-import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.parser.IExtensionToken;
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
@@ -152,7 +150,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private final boolean allowCPPRestrict;
private final boolean supportExtendedTemplateSyntax;
- private final boolean supportLongLong;
private final IIndex index;
protected ICPPASTTranslationUnit translationUnit;
@@ -181,7 +178,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
config.getBuiltinBindingsProvider());
allowCPPRestrict = config.allowRestrictPointerOperators();
supportExtendedTemplateSyntax = config.supportExtendedTemplateSyntax();
- supportLongLong = config.supportLongLongs();
supportParameterInfoBlock= config.supportParameterInfoBlock();
supportExtendedSizeofOperator= config.supportExtendedSizeofOperator();
supportFunctionStyleAsm= config.supportFunctionStyleAssembler();
@@ -414,7 +410,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
case IToken.t_new:
case IToken.t_delete:
case IToken.t_sizeof:
- case IGCCToken.t_typeof:
case IGCCToken.t___alignof__:
// postfix expression
case IToken.t_typename:
@@ -1087,9 +1082,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx);
- case IGCCToken.t_typeof:
- return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
- IASTTypeIdExpression.op_typeof, IASTUnaryExpression.op_typeof, ctx);
case IGCCToken.t___alignof__:
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx);
@@ -2442,13 +2434,28 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (encounteredRawType || encounteredTypename)
throwBacktrack(LA(1));
- typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
- IGNUASTTypeIdExpression.op_typeof, IGNUASTUnaryExpression.op_typeof, CastExprCtx.eNotBExpr);
+ simpleType= IASTSimpleDeclSpecifier.t_typeof;
+ consume(IGCCToken.t_typeof);
+ typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(),
+ IGNUASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotBExpr);
encounteredTypename= true;
endOffset= calculateEndOffset(typeofExpression);
break;
+ case IToken.t_decltype:
+ if (encounteredRawType || encounteredTypename)
+ throwBacktrack(LA(1));
+
+ simpleType= IASTSimpleDeclSpecifier.t_decltype;
+ consume(IToken.t_decltype);
+ consume(IToken.tLPAREN);
+ typeofExpression= unaryExpression(CastExprCtx.eNotBExpr);
+ endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset();
+
+ encounteredTypename= true;
+ break;
+
default:
if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) {
handleOtherDeclSpecModifier();
@@ -2510,31 +2517,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private ICPPASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType,
int options, int isLong, IASTExpression typeofExpression, int offset, int endOffset) {
-
- if (isLong > 1 && !supportLongLong)
- isLong= 1;
-
- ICPPASTSimpleDeclSpecifier declSpec= null;
- if (isLong > 1 || (options & (RESTRICT|COMPLEX|IMAGINARY)) != 0 || typeofExpression != null) {
- final IGPPASTSimpleDeclSpecifier gppDeclSpec= nodeFactory.newSimpleDeclSpecifierGPP();
- gppDeclSpec.setLongLong(isLong > 1);
- gppDeclSpec.setRestrict((options & RESTRICT) != 0);
- gppDeclSpec.setComplex((options & COMPLEX) != 0);
- gppDeclSpec.setImaginary((options & IMAGINARY) != 0);
- gppDeclSpec.setTypeofExpression(typeofExpression);
-
- declSpec= gppDeclSpec;
- } else {
- declSpec = nodeFactory.newSimpleDeclSpecifier();
- }
+ ICPPASTSimpleDeclSpecifier declSpec= nodeFactory.newSimpleDeclSpecifier();
configureDeclSpec(declSpec, storageClass, options);
declSpec.setType(simpleType);
declSpec.setLong(isLong == 1);
+ declSpec.setLongLong(isLong > 1);
declSpec.setShort((options & SHORT) != 0);
declSpec.setUnsigned((options & UNSIGNED) != 0);
declSpec.setSigned((options & SIGNED) != 0);
+ declSpec.setComplex((options & COMPLEX) != 0);
+ declSpec.setImaginary((options & IMAGINARY) != 0);
+ declSpec.setDeclTypeExpression(typeofExpression);
((ASTNode) declSpec).setOffsetAndLength(offset, endOffset-offset);
return declSpec;
@@ -2548,6 +2543,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declSpec.setFriend((options & FRIEND) != 0);
declSpec.setVirtual((options & VIRTUAL) != 0);
declSpec.setExplicit((options & EXPLICIT) != 0);
+ declSpec.setRestrict((options & RESTRICT) != 0);
}
/**
@@ -2717,18 +2713,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (declspec instanceof ICPPASTSimpleDeclSpecifier) {
ICPPASTSimpleDeclSpecifier sspec= (ICPPASTSimpleDeclSpecifier) declspec;
- switch(sspec.getType()) {
- case IASTSimpleDeclSpecifier.t_unspecified:
- if (sspec.isLong() || sspec.isShort() || sspec.isSigned() || sspec.isUnsigned())
- return true;
- if (sspec instanceof IGPPASTSimpleDeclSpecifier) {
- final IGPPASTSimpleDeclSpecifier gspec = (IGPPASTSimpleDeclSpecifier) sspec;
- if (gspec.isLongLong())
- return true;
- }
+ if (CPPVisitor.doesNotSpecifyType(declspec)) {
return false;
-
- case IASTSimpleDeclSpecifier.t_void:
+ }
+ if (sspec.getType() == IASTSimpleDeclSpecifier.t_void) {
return false;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java
index 49973a871d1..5e458cdfe8e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java
@@ -1,126 +1,47 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 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 - Initial API and implementation
+ * John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
-import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
- * @author jcamelon
+ * @deprecated Replaced by {@link CPPASTSimpleDeclSpecifier}
*/
-public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier
- implements IGPPASTSimpleDeclSpecifier, IASTAmbiguityParent {
+@Deprecated
+public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier implements
+ IGPPASTSimpleDeclSpecifier {
- private boolean longLong;
- private boolean restrict;
- private boolean complex=false;
- private boolean imaginary=false;
- private IASTExpression typeOfExpression;
-
-
-
public GPPASTSimpleDeclSpecifier() {
}
public GPPASTSimpleDeclSpecifier(IASTExpression typeofExpression) {
- setTypeofExpression(typeofExpression);
+ super();
+ setDeclTypeExpression(typeofExpression);
}
@Override
public GPPASTSimpleDeclSpecifier copy() {
GPPASTSimpleDeclSpecifier copy = new GPPASTSimpleDeclSpecifier();
copySimpleDeclSpec(copy);
- copy.setTypeofExpression(typeOfExpression == null ? null : typeOfExpression.copy());
- copy.longLong = longLong;
- copy.restrict = restrict;
- copy.complex = complex;
- copy.imaginary = imaginary;
return copy;
}
- public boolean isLongLong() {
- return longLong;
- }
-
- public void setLongLong(boolean value) {
- longLong = value;
- }
-
- public boolean isRestrict() {
- return restrict;
- }
-
- public void setRestrict(boolean value) {
- restrict = value;
- }
public void setTypeofExpression(IASTExpression typeofExpression) {
- typeOfExpression = typeofExpression;
- if (typeofExpression != null) {
- typeofExpression.setParent(this);
- typeofExpression.setPropertyInParent(TYPEOF_EXPRESSION);
- }
+ setDeclTypeExpression(typeofExpression);
}
public IASTExpression getTypeofExpression() {
- return typeOfExpression;
- }
-
- @Override
- public boolean accept( ASTVisitor action ){
- if( action.shouldVisitDeclSpecifiers ){
- switch( action.visit( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- if( typeOfExpression != null )
- if( !typeOfExpression.accept( action ) ) return false;
-
- if( action.shouldVisitDeclSpecifiers ){
- switch( action.leave( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- return true;
+ return getDeclTypeExpression();
}
-
- public boolean isComplex() {
- return complex;
- }
-
- public void setComplex(boolean value) {
- this.complex = value;
- }
-
- public boolean isImaginary() {
- return imaginary;
- }
-
- public void setImaginary(boolean value) {
- this.imaginary = value;
- }
-
- public void replace(IASTNode child, IASTNode other) {
- if (child == typeOfExpression) {
- other.setPropertyInParent(child.getPropertyInParent());
- other.setParent(child.getParent());
- typeOfExpression= (IASTExpression) other;
- }
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index 63bd3aaf8d8..35e9eb8beb7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 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
@@ -64,6 +64,7 @@ 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;
+import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IParameter;
@@ -129,7 +130,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
-import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@@ -1742,13 +1742,8 @@ public class CPPVisitor extends ASTQueries {
name = ((IASTEnumerationSpecifier)declSpec).getName();
} else if (declSpec instanceof ICPPASTSimpleDeclSpecifier) {
ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec;
- if (spec instanceof IGPPASTSimpleDeclSpecifier) {
- IGPPASTSimpleDeclSpecifier gspec = (IGPPASTSimpleDeclSpecifier) spec;
- final IASTExpression typeofExpression = gspec.getTypeofExpression();
- if (typeofExpression != null) {
- type = typeofExpression.getExpressionType();
- }
- }
+ // Check for decltype(expr)
+ type = getDeclType(spec);
if (type == null) {
type = new CPPBasicType(spec);
}
@@ -1782,6 +1777,55 @@ public class CPPVisitor extends ASTQueries {
return type;
}
+ /**
+ * Compute the type for decltype(expr) or typeof(expr)
+ */
+ private static IType getDeclType(ICPPASTSimpleDeclSpecifier spec) {
+ IASTExpression expr = spec.getDeclTypeExpression();
+ if (expr == null)
+ return null;
+
+ if (spec.getType() == IASTSimpleDeclSpecifier.t_decltype) {
+ IASTName namedEntity= null;
+ if (expr instanceof IASTIdExpression) {
+ namedEntity= ((IASTIdExpression) expr).getName();
+ } else if (expr instanceof IASTFieldReference) {
+ namedEntity= ((IASTFieldReference) expr).getFieldName();
+ }
+ if (namedEntity != null) {
+ IBinding b= namedEntity.resolvePreBinding();
+ if (b instanceof IType) {
+ return (IType) b;
+ }
+ try {
+ if (b instanceof IVariable) {
+ return ((IVariable) b).getType();
+ }
+ if (b instanceof IFunction) {
+ return ((IFunction) b).getType();
+ }
+ } catch (DOMException e) {
+ return e.getProblem();
+ }
+ }
+ }
+ IType type = expr.getExpressionType();
+ if (spec.getType() == IASTSimpleDeclSpecifier.t_decltype) {
+ while (expr instanceof IASTUnaryExpression
+ && ((IASTUnaryExpression) expr).getOperator() == IASTUnaryExpression.op_bracketedPrimary) {
+ expr = ((IASTUnaryExpression) expr).getOperand();
+ }
+ if (!(expr instanceof IASTFunctionCallExpression)) {
+ type= SemanticUtil.getNestedType(type, TDEF | REF);
+ if (expr.isLValue())
+ type= new CPPReferenceType(type, false);
+ }
+ } else {
+ type= SemanticUtil.getNestedType(type, TDEF | REF);
+ }
+ return type;
+ }
+
public static IType getThisType(IScope scope) {
try {
IASTNode node = null;
@@ -2182,12 +2226,7 @@ public class CPPVisitor extends ASTQueries {
if (declspec instanceof ICPPASTSimpleDeclSpecifier) {
ICPPASTSimpleDeclSpecifier ds= (ICPPASTSimpleDeclSpecifier) declspec;
if (ds.getType() == IASTSimpleDeclSpecifier.t_unspecified) {
- if (ds instanceof IGPPASTSimpleDeclSpecifier) {
- final IGPPASTSimpleDeclSpecifier gds = (IGPPASTSimpleDeclSpecifier) ds;
- if (gds.isLongLong() || gds.getTypeofExpression() != null)
- return false;
- }
- if (ds.isShort() || ds.isLong() || ds.isSigned() || ds.isUnsigned())
+ if (ds.isShort() || ds.isLong() || ds.isLongLong() || ds.isSigned() || ds.isUnsigned())
return false;
return true;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
index e6c3b0bd9d1..8e5e09ef739 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
@@ -171,7 +171,7 @@ public class SemanticUtil {
/**
* Returns 0 for no qualifier, 1 for const, 2 for volatile and 3 for const volatile.
*/
- static CVQualifier getCVQualifier(IType t) {
+ public static CVQualifier getCVQualifier(IType t) {
if (t instanceof IQualifierType) {
IQualifierType qt= (IQualifierType) t;
if (qt.isConst()) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
index 734ccd0dd5f..aaf65e1914c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -37,7 +37,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
-import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@@ -252,8 +251,8 @@ public class ExpressionWriter extends NodeWriter{
case IASTUnaryExpression.op_bracketedPrimary:
case ICPPASTUnaryExpression.op_throw:
case ICPPASTUnaryExpression.op_typeid:
- case IGNUASTUnaryExpression.op_alignOf:
- case IGNUASTUnaryExpression.op_typeof:
+ case IASTUnaryExpression.op_alignOf:
+ case IASTUnaryExpression.op_typeof:
return true;
default:
@@ -268,8 +267,8 @@ public class ExpressionWriter extends NodeWriter{
case IASTUnaryExpression.op_postFixIncr:
case IASTUnaryExpression.op_bracketedPrimary:
case ICPPASTUnaryExpression.op_typeid:
- case IGNUASTUnaryExpression.op_alignOf:
- case IGNUASTUnaryExpression.op_typeof:
+ case IASTUnaryExpression.op_alignOf:
+ case IASTUnaryExpression.op_typeof:
return true;
default:
@@ -306,9 +305,9 @@ public class ExpressionWriter extends NodeWriter{
return THROW;
case ICPPASTUnaryExpression.op_typeid:
return TYPEID_OP;
- case IGNUASTUnaryExpression.op_alignOf:
+ case IASTUnaryExpression.op_alignOf:
return ALIGNOF_OP;
- case IGNUASTUnaryExpression.op_typeof:
+ case IASTUnaryExpression.op_typeof:
return TYPEOF_OP;
default:
System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
@@ -326,8 +325,8 @@ public class ExpressionWriter extends NodeWriter{
case ICPPASTUnaryExpression.op_typeid:
return CLOSING_BRACKET_OP;
case IASTUnaryExpression.op_bracketedPrimary:
- case IGNUASTUnaryExpression.op_alignOf:
- case IGNUASTUnaryExpression.op_typeof:
+ case IASTUnaryExpression.op_alignOf:
+ case IASTUnaryExpression.op_typeof:
return CLOSING_BRACKET_OP;
default:
System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$

Back to the top