mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Bug 231859: Optimization for computing int type of enum.
This commit is contained in:
parent
e3f899b9fc
commit
15a9ac904e
12 changed files with 301 additions and 50 deletions
|
@ -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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Andrew Niefer (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
|
@ -21,4 +22,13 @@ public interface IEnumeration extends IBinding, IType {
|
|||
* @throws DOMException
|
||||
*/
|
||||
IEnumerator[] getEnumerators() throws DOMException;
|
||||
|
||||
/**
|
||||
* @since 5.2
|
||||
*/
|
||||
long getMinValue();
|
||||
/**
|
||||
* @since 5.2
|
||||
*/
|
||||
long getMaxValue();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2009, 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
|
||||
|
@ -10,13 +10,10 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
|
||||
/**
|
||||
|
@ -267,29 +264,8 @@ public abstract class ArithmeticConversion {
|
|||
}
|
||||
|
||||
public static int getEnumIntTypeModifiers(IEnumeration enumeration) {
|
||||
// mstodo cache min/max values of enumerations
|
||||
long minValue = 0;
|
||||
long maxValue = 0;
|
||||
try {
|
||||
IEnumerator[] enumerators = enumeration.getEnumerators();
|
||||
for (IEnumerator enumerator : enumerators) {
|
||||
IValue value = enumerator.getValue();
|
||||
if (value != null) {
|
||||
Long val = value.numericalValue();
|
||||
if (val != null) {
|
||||
long v = val.longValue();
|
||||
if (minValue > v) {
|
||||
minValue = v;
|
||||
}
|
||||
if (maxValue < v) {
|
||||
maxValue = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
return 0;
|
||||
}
|
||||
final long minValue = enumeration.getMinValue();
|
||||
final long maxValue = enumeration.getMaxValue();
|
||||
// TODO(sprigogin): Use values of __INT_MAX__ and __LONG_MAX__ macros
|
||||
if (minValue >= Integer.MIN_VALUE && maxValue <= Integer.MAX_VALUE) {
|
||||
return 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 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
|
||||
|
@ -25,6 +25,7 @@ public class DeclarationOptions {
|
|||
final public static int NO_ARRAYS= 0x80;
|
||||
final public static int NO_NESTED= 0x100;
|
||||
final public static int ALLOW_PARAMETER_PACKS= 0x200;
|
||||
final public static int REQUIRE_SIMPLE_NAME= 0x400;
|
||||
|
||||
public static final DeclarationOptions
|
||||
GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_CONSTRUCTOR_INITIALIZER),
|
||||
|
@ -32,7 +33,7 @@ public class DeclarationOptions {
|
|||
C_MEMBER= new DeclarationOptions(ALLOW_BITFIELD | ALLOW_ABSTRACT),
|
||||
CPP_MEMBER= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD),
|
||||
LOCAL= new DeclarationOptions(ALLOW_CONSTRUCTOR_INITIALIZER),
|
||||
PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS),
|
||||
PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME),
|
||||
TYPEID= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER),
|
||||
TYPEID_NEW= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED),
|
||||
TYPEID_CONVERSION= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED),
|
||||
|
@ -49,6 +50,7 @@ public class DeclarationOptions {
|
|||
final public boolean fAllowFunctions;
|
||||
final public boolean fAllowNested;
|
||||
final public boolean fAllowParameterPacks;
|
||||
final public boolean fRequireSimpleName;
|
||||
|
||||
public DeclarationOptions(int options) {
|
||||
fAllowEmptySpecifier= (options & ALLOW_EMPTY_SPECIFIER) != 0;
|
||||
|
@ -60,5 +62,6 @@ public class DeclarationOptions {
|
|||
fAllowFunctions= (options & NO_FUNCTIONS) == 0;
|
||||
fAllowNested= (options & NO_NESTED) == 0;
|
||||
fAllowParameterPacks= (options & ALLOW_PARAMETER_PACKS) != 0;
|
||||
fRequireSimpleName= (options & REQUIRE_SIMPLE_NAME) != 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
|
@ -39,6 +40,8 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
|
|||
|
||||
private IASTName[] declarations = null;
|
||||
private IASTName definition = null;
|
||||
private Long fMinValue;
|
||||
private Long fMaxValue;
|
||||
public CEnumeration(IASTName enumeration) {
|
||||
ASTNodeProperty prop = enumeration.getPropertyInParent();
|
||||
if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME)
|
||||
|
@ -186,4 +189,48 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
|
|||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
if (fMinValue != null)
|
||||
return fMinValue.longValue();
|
||||
|
||||
long minValue = Long.MAX_VALUE;
|
||||
IEnumerator[] enumerators = getEnumerators();
|
||||
for (IEnumerator enumerator : enumerators) {
|
||||
IValue value = enumerator.getValue();
|
||||
if (value != null) {
|
||||
Long val = value.numericalValue();
|
||||
if (val != null) {
|
||||
long v = val.longValue();
|
||||
if (v < minValue) {
|
||||
minValue = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fMinValue= minValue;
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
if (fMaxValue != null)
|
||||
return fMaxValue.longValue();
|
||||
|
||||
long maxValue = Long.MIN_VALUE;
|
||||
IEnumerator[] enumerators = getEnumerators();
|
||||
for (IEnumerator enumerator : enumerators) {
|
||||
IValue value = enumerator.getValue();
|
||||
if (value != null) {
|
||||
Long val = value.numericalValue();
|
||||
if (val != null) {
|
||||
long v = val.longValue();
|
||||
if (v > maxValue) {
|
||||
maxValue = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fMaxValue= maxValue;
|
||||
return maxValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
|
@ -34,6 +35,8 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
*/
|
||||
public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPPInternalBinding {
|
||||
private IASTName enumName;
|
||||
private Long fMaxValue;
|
||||
private Long fMinValue;
|
||||
|
||||
public CPPEnumeration(IASTName name) {
|
||||
this.enumName = name;
|
||||
|
@ -130,4 +133,48 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP
|
|||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
if (fMinValue != null)
|
||||
return fMinValue.longValue();
|
||||
|
||||
long minValue = Long.MAX_VALUE;
|
||||
IEnumerator[] enumerators = getEnumerators();
|
||||
for (IEnumerator enumerator : enumerators) {
|
||||
IValue value = enumerator.getValue();
|
||||
if (value != null) {
|
||||
Long val = value.numericalValue();
|
||||
if (val != null) {
|
||||
long v = val.longValue();
|
||||
if (v < minValue) {
|
||||
minValue = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fMinValue= minValue;
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
if (fMaxValue != null)
|
||||
return fMaxValue.longValue();
|
||||
|
||||
long maxValue = Long.MIN_VALUE;
|
||||
IEnumerator[] enumerators = getEnumerators();
|
||||
for (IEnumerator enumerator : enumerators) {
|
||||
IValue value = enumerator.getValue();
|
||||
if (value != null) {
|
||||
Long val = value.numericalValue();
|
||||
if (val != null) {
|
||||
long v = val.longValue();
|
||||
if (v > maxValue) {
|
||||
maxValue = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fMaxValue= maxValue;
|
||||
return maxValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 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
|
||||
|
@ -2950,7 +2950,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (option.fRequireAbstract)
|
||||
throwBacktrack(LA(1));
|
||||
|
||||
final IASTName declaratorName= qualifiedName(CastExprCtx.eNotBExpr);
|
||||
final IASTName declaratorName= !option.fRequireSimpleName ? qualifiedName(CastExprCtx.eNotBExpr) : identifier();
|
||||
endOffset= calculateEndOffset(declaratorName);
|
||||
return declarator(pointerOps, hasEllipsis, declaratorName, null, startingOffset, endOffset, strategy, option);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 Symbian Software Systems 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:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.composite.c;
|
||||
|
||||
|
@ -41,4 +42,12 @@ class CompositeCEnumeration extends CompositeCBinding implements IEnumeration, I
|
|||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
return ((IEnumeration)rbinding).getMinValue();
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
return ((IEnumeration)rbinding).getMaxValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 Symbian Software Systems 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:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||
|
||||
|
@ -41,4 +42,11 @@ class CompositeCPPEnumeration extends CompositeCPPBinding implements IEnumeratio
|
|||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
public long getMinValue() {
|
||||
return ((IEnumeration)rbinding).getMinValue();
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
return ((IEnumeration)rbinding).getMaxValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -270,6 +270,14 @@ public class PDOMASTAdapter {
|
|||
public IBinding getOwner() throws DOMException {
|
||||
return fDelegate.getOwner();
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
return fDelegate.getMinValue();
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
return fDelegate.getMaxValue();
|
||||
}
|
||||
}
|
||||
|
||||
private static class AnonymousCompositeType implements ICompositeType {
|
||||
|
@ -410,6 +418,14 @@ public class PDOMASTAdapter {
|
|||
public boolean isSameType(IType type) {
|
||||
return ((IEnumeration) fDelegate).isSameType(type);
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
return ((IEnumeration)fDelegate).getMinValue();
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
return ((IEnumeration)fDelegate).getMaxValue();
|
||||
}
|
||||
}
|
||||
|
||||
private static class AnonymousClassType extends AnonymousCPPBinding implements ICPPClassType {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2009 QNX Software Systems and others.
|
||||
* Copyright (c) 2006, 2010 QNX Software Systems 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:
|
||||
* QNX - Initial API and implementation
|
||||
* Doug Schaefer (QNX) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||
|
@ -16,12 +16,14 @@ import java.util.Collections;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
|
@ -30,23 +32,44 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
* Enumerations in the database.
|
||||
*/
|
||||
class PDOMCEnumeration extends PDOMBinding implements IEnumeration, IIndexType {
|
||||
|
||||
private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE + 0;
|
||||
private static final int OFFSET_MIN_VALUE= FIRST_ENUMERATOR + Database.PTR_SIZE;
|
||||
private static final int OFFSET_MAX_VALUE= OFFSET_MIN_VALUE + 8;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
|
||||
protected static final int RECORD_SIZE = OFFSET_MAX_VALUE + 8;
|
||||
|
||||
private Long fMinValue;
|
||||
private Long fMaxValue;
|
||||
|
||||
public PDOMCEnumeration(PDOMLinkage linkage, PDOMNode parent, IEnumeration enumeration)
|
||||
throws CoreException {
|
||||
super(linkage, parent, enumeration.getNameCharArray());
|
||||
storeValueBounds(enumeration);
|
||||
}
|
||||
|
||||
public PDOMCEnumeration(PDOMLinkage linkage, long record) {
|
||||
super(linkage, record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
|
||||
storeValueBounds((IEnumeration) newBinding);
|
||||
}
|
||||
|
||||
private void storeValueBounds(IEnumeration enumeration) throws CoreException {
|
||||
final Database db= getDB();
|
||||
final long minValue = enumeration.getMinValue();
|
||||
final long maxValue = enumeration.getMaxValue();
|
||||
db.putLong(record+ OFFSET_MIN_VALUE, minValue);
|
||||
db.putLong(record+ OFFSET_MAX_VALUE, maxValue);
|
||||
fMinValue= minValue;
|
||||
fMaxValue= maxValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRecordSize() {
|
||||
|
@ -86,7 +109,33 @@ class PDOMCEnumeration extends PDOMBinding implements IEnumeration, IIndexType {
|
|||
enumerator.setNextEnumerator(first);
|
||||
getDB().putRecPtr(record + FIRST_ENUMERATOR, enumerator.getRecord());
|
||||
}
|
||||
|
||||
|
||||
public long getMinValue() {
|
||||
if (fMinValue != null) {
|
||||
return fMinValue.longValue();
|
||||
}
|
||||
long minValue= 0;
|
||||
try {
|
||||
minValue= getDB().getLong(record + OFFSET_MIN_VALUE);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
fMinValue= minValue;
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
if (fMaxValue != null) {
|
||||
return fMaxValue.longValue();
|
||||
}
|
||||
long maxValue= 0;
|
||||
try {
|
||||
maxValue= getDB().getLong(record + OFFSET_MAX_VALUE);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
fMaxValue= maxValue;
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2009 QNX Software Systems and others.
|
||||
* Copyright (c) 2006, 2010 QNX Software Systems 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:
|
||||
* QNX - Initial API and implementation
|
||||
* Doug Schaefer (QNX) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
|
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
|
@ -32,24 +34,45 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
* Enumerations in the index.
|
||||
*/
|
||||
class PDOMCPPEnumeration extends PDOMCPPBinding implements IEnumeration, IIndexType {
|
||||
|
||||
private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE + 0;
|
||||
private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE;
|
||||
private static final int OFFSET_MIN_VALUE= FIRST_ENUMERATOR + Database.PTR_SIZE;
|
||||
private static final int OFFSET_MAX_VALUE= OFFSET_MIN_VALUE + 8;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
|
||||
protected static final int RECORD_SIZE = OFFSET_MAX_VALUE + 8;
|
||||
|
||||
private Long fMinValue;
|
||||
private Long fMaxValue;
|
||||
|
||||
public PDOMCPPEnumeration(PDOMLinkage linkage, PDOMNode parent, IEnumeration enumeration)
|
||||
throws CoreException {
|
||||
super(linkage, parent, enumeration.getNameCharArray());
|
||||
storeValueBounds(enumeration);
|
||||
}
|
||||
|
||||
public PDOMCPPEnumeration(PDOMLinkage linkage, long record) {
|
||||
super(linkage, record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
|
||||
storeValueBounds((IEnumeration) newBinding);
|
||||
}
|
||||
|
||||
private void storeValueBounds(IEnumeration enumeration) throws CoreException {
|
||||
final Database db= getDB();
|
||||
final long minValue = enumeration.getMinValue();
|
||||
final long maxValue = enumeration.getMaxValue();
|
||||
db.putLong(record+ OFFSET_MIN_VALUE, minValue);
|
||||
db.putLong(record+ OFFSET_MAX_VALUE, maxValue);
|
||||
fMinValue= minValue;
|
||||
fMaxValue= maxValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
|
@ -127,6 +150,32 @@ class PDOMCPPEnumeration extends PDOMCPPBinding implements IEnumeration, IIndexT
|
|||
return false;
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
if (fMinValue != null) {
|
||||
return fMinValue.longValue();
|
||||
}
|
||||
long minValue= 0;
|
||||
try {
|
||||
minValue= getDB().getLong(record + OFFSET_MIN_VALUE);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
fMinValue= minValue;
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
if (fMaxValue != null) {
|
||||
return fMaxValue.longValue();
|
||||
}
|
||||
long maxValue= 0;
|
||||
try {
|
||||
maxValue= getDB().getLong(record + OFFSET_MAX_VALUE);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
fMaxValue= maxValue;
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
throw new PDOMNotImplementedError();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 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
|
||||
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
@ -112,4 +113,40 @@ public class C99Enumeration extends PlatformObject implements IC99Binding, IEnum
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getMinValue() {
|
||||
long minValue = Long.MAX_VALUE;
|
||||
IEnumerator[] enumerators = getEnumerators();
|
||||
for (IEnumerator enumerator : enumerators) {
|
||||
IValue value = enumerator.getValue();
|
||||
if (value != null) {
|
||||
Long val = value.numericalValue();
|
||||
if (val != null) {
|
||||
long v = val.longValue();
|
||||
if (v < minValue) {
|
||||
minValue = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public long getMaxValue() {
|
||||
long maxValue = Long.MIN_VALUE;
|
||||
IEnumerator[] enumerators = getEnumerators();
|
||||
for (IEnumerator enumerator : enumerators) {
|
||||
IValue value = enumerator.getValue();
|
||||
if (value != null) {
|
||||
Long val = value.numericalValue();
|
||||
if (val != null) {
|
||||
long v = val.longValue();
|
||||
if (v > maxValue) {
|
||||
maxValue = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue