1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 505832 - Add ICPPVariable.isConstexpr() method

Change-Id: I0f889347807d2e23be00ae68786a08e58a5ae8c4
This commit is contained in:
Sergey Prigogin 2016-10-11 20:29:23 -07:00
parent 33d12e75c9
commit c5afeb8d85
44 changed files with 724 additions and 567 deletions

View file

@ -263,7 +263,7 @@ public class IndexUpdateTests extends IndexTestBase {
updateFile();
checkCppVariable("globalVar", SHORT, new String[]{});
updateFile();
checkCppVariable("globalVar", INT, new String[]{REGISTER});
checkCppVariable("globalVar", INT, new String[]{});
}
private void checkCppVariable(String name, String type, String[] modifiers) throws Exception {

View file

@ -12,8 +12,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -33,6 +31,8 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import junit.framework.Test;
/**
* Tests for verifying whether the PDOM correctly stores information about
* C++ non-member functions.
@ -116,7 +116,6 @@ public class CPPFunctionTests extends PDOMTestBase {
ICPPFunction function = (ICPPFunction) bindings[0];
IParameter[] parameters = function.getParameters();
assertEquals(2, parameters.length);
assertEquals(true, parameters[0].isRegister());
}
public void testExternCPPFunction() throws Exception {

View file

@ -12,8 +12,6 @@
package org.eclipse.cdt.internal.pdom.tests;
import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.model.ICProject;
@ -22,6 +20,8 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
import junit.framework.Test;
/**
* Tests for verifying whether the PDOM correctly stores information about
* C++ variable declarations.
@ -69,7 +69,6 @@ public class CPPVariableTests extends PDOMTestBase {
IBinding[] bindings = findQualifiedName(pdom, "registerCPPVariable");
assertEquals(1, bindings.length);
ICPPVariable variable = (ICPPVariable) bindings[0];
assertTrue(variable.isRegister());
}
public void testCPPStaticVariable() throws Exception {

View file

@ -23,6 +23,12 @@ public interface ICPPVariable extends IVariable, ICPPBinding {
*/
public boolean isMutable();
/**
* Checks whether this variable is declared as constexpr.
* @since 6.2
*/
public boolean isConstexpr();
/**
* Checks whether this variable is declared as extern "C".
*/

View file

@ -309,6 +309,10 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
return false;
}
public boolean isConstexpr() {
return false;
}
public boolean isExtern() {
return false;
}

View file

@ -100,6 +100,11 @@ public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public String[] getQualifiedName() {
return new String[0];

View file

@ -105,7 +105,12 @@ public class CPPLambdaExpressionParameter extends PlatformObject implements ICPP
return false;
}
@Override
@Override
public boolean isConstexpr() {
return false;
}
@Override
public boolean isAuto() {
return hasStorageClass(IASTDeclSpecifier.sc_auto);
}

View file

@ -194,7 +194,12 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
return false;
}
@Override
@Override
public boolean isConstexpr() {
return false;
}
@Override
public boolean isAuto() {
return hasStorageClass(IASTDeclSpecifier.sc_auto);
}

View file

@ -37,9 +37,6 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP
return (ICPPParameter) getSpecializedBinding();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
*/
@Override
public IType getType() {
return fType;
@ -50,46 +47,36 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP
return fType instanceof ICPPParameterPackType;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic()
*/
@Override
public boolean isStatic() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
@Override
public boolean isExtern() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
@Override
public boolean isAuto() {
return getParameter().isAuto();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
@Override
public boolean isRegister() {
return getParameter().isRegister();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
@Override
public boolean isMutable() {
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public boolean hasDefaultValue() {
return fDefaultValue != null;

View file

@ -153,4 +153,9 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter
public boolean isMutable() {
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
}

View file

@ -46,6 +46,11 @@ public class CPPTemplateNonTypeParameterSpecialization extends CPPTemplateParame
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public boolean isExternC() {
return false;

View file

@ -37,6 +37,11 @@ public class CPPUnknownField extends CPPUnknownMember implements ICPPField {
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public boolean isAuto() {
return false;

View file

@ -193,7 +193,12 @@ public class CPPVariable extends PlatformObject implements ICPPInternalVariable
return false;
}
@Override
@Override
public boolean isConstexpr() {
return VariableHelpers.isConstexpr(fDefinition);
}
@Override
public boolean isStatic() {
return hasStorageClass(IASTDeclSpecifier.sc_static);
}

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariableInstance;
/**
@ -68,6 +69,11 @@ public class CPPVariableInstance extends CPPSpecialization
return false;
}
@Override
public boolean isConstexpr() {
return ((ICPPVariable) getSpecializedBinding()).isConstexpr();
}
@Override
public boolean isExternC() {
return false;

View file

@ -18,7 +18,8 @@ public class CPPVariableSpecialization extends CPPSpecialization implements ICPP
private final IType type;
private final IValue value;
public CPPVariableSpecialization(IBinding orig, IBinding owner, ICPPTemplateParameterMap tpmap, IType type, IValue value) {
public CPPVariableSpecialization(IBinding orig, IBinding owner, ICPPTemplateParameterMap tpmap, IType type,
IValue value) {
super(orig, owner, tpmap);
this.type = type;
this.value = value;
@ -63,6 +64,11 @@ public class CPPVariableSpecialization extends CPPSpecialization implements ICPP
return getVariable().isMutable();
}
@Override
public boolean isConstexpr() {
return getVariable().isConstexpr();
}
@Override
public boolean isExternC() {
return false;

View file

@ -36,6 +36,11 @@ public class CPPVariableTemplate extends CPPTemplateDefinition
return false;
}
@Override
public boolean isConstexpr() {
return VariableHelpers.isConstexpr((IASTName) getDefinition());
}
@Override
public boolean isExternC() {
return CPPVisitor.isExternC(getDefinition(), getDeclarations());

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
@ -64,6 +65,24 @@ public class VariableHelpers {
return false;
}
public static boolean isConstexpr(IASTName definition) {
if (definition == null)
return false;
IASTNode parent = definition.getParent();
while (!(parent instanceof IASTDeclaration)) {
parent = parent.getParent();
}
if (parent instanceof IASTSimpleDeclaration) {
ICPPASTDeclSpecifier declSpec =
(ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier();
if (declSpec != null)
return declSpec.isConstexpr();
}
return false;
}
@SuppressWarnings("null")
public static IType createType(ICPPVariable variable, IASTName definition, IASTName[] declarations,
boolean allDeclarationsResolved) {

View file

@ -58,7 +58,12 @@ class CompositeCPPVariable extends CompositeCPPBinding implements ICPPVariable {
public boolean isStatic() {
return ((ICPPVariable) rbinding).isStatic();
}
@Override
public boolean isConstexpr() {
return ((ICPPVariable) rbinding).isConstexpr();
}
@Override
public IValue getInitialValue() {
return ((ICPPVariable) rbinding).getInitialValue();

View file

@ -16,6 +16,20 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IPDOMNode;
@ -86,20 +100,6 @@ import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
/**
* Database for storing semantic information for one project.
*/
@ -276,10 +276,11 @@ public class PDOM extends PlatformObject implements IPDOM {
* 202.0 - C++14 constexpr evaluation, bug 490475.
* 203.0 - Use 16 bits to store field position, bug 501616.
* 204.0 - Do not store return expression in index, follow-up to bug 490475.
* 205.0 - Reworked storage of annotations, bug 505832.
*/
private static final int MIN_SUPPORTED_VERSION= version(204, 0);
private static final int MAX_SUPPORTED_VERSION= version(204, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(204, 0);
private static final int MIN_SUPPORTED_VERSION= version(205, 0);
private static final int MAX_SUPPORTED_VERSION= version(205, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(205, 0);
private static int version(int major, int minor) {
return (major << 16) + minor;

View file

@ -1,84 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006, 2012 IBM Corporation.
* 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
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/**
* A utility class for packing various annotations into bit fields. This
* includes storage class specifiers (auto, register, etc.), and CV qualifiers
* (const, volatile).
*/
public class PDOMCAnnotation {
// Storage class specifiers and function annotations
public static final int AUTO_OFFSET = 0;
public static final int EXTERN_OFFSET = 1;
public static final int INLINE_OFFSET = 2;
public static final int REGISTER_OFFSET = 3;
public static final int STATIC_OFFSET = 4;
public static final int VARARGS_OFFSET = 5;
public static final int NO_RETURN = 6;
// CV qualifiers
public static final int CONST_OFFSET = 0;
public static final int VOLATILE_OFFSET = 1;
/**
* Encodes storage class specifiers and other annotation from an IBinding
* as a bit vector.
*
* @param binding the IBinding whose annotation will be encoded.
* @return a bit vector of the annotation.
*/
public static byte encodeAnnotation(IBinding binding) {
byte modifiers = 0;
if (binding instanceof IVariable) {
IVariable variable = (IVariable) binding;
modifiers |= (variable.isAuto() ? 1 : 0) << AUTO_OFFSET;
modifiers |= (variable.isExtern() ? 1 : 0) << EXTERN_OFFSET;
modifiers |= (variable.isRegister() ? 1 : 0) << REGISTER_OFFSET;
modifiers |= (variable.isStatic() ? 1 : 0) << STATIC_OFFSET;
}
if (binding instanceof IFunction) {
IFunction function = (IFunction) binding;
modifiers |= (function.isAuto() ? 1 : 0) << AUTO_OFFSET;
modifiers |= (function.isExtern() ? 1 : 0) << EXTERN_OFFSET;
modifiers |= (function.isRegister() ? 1 : 0) << REGISTER_OFFSET;
modifiers |= (ASTInternal.isStatic(function, false) ? 1 : 0) << STATIC_OFFSET;
modifiers |= (function.isInline() ? 1 : 0) << INLINE_OFFSET;
modifiers |= (function.takesVarArgs() ? 1 : 0) << VARARGS_OFFSET;
modifiers |= (function.isNoReturn() ? 1 : 0) << NO_RETURN;
}
return modifiers;
}
/**
* Encodes CV qualifiers from a method declarator as a bit vector.
* @param type the function type
* @return a bit vector of the CV qualifiers.
*/
/*
* aftodo - will we put CV information in C pdom bindings or should we
* move this to PDOMCPPAnnotation?
*/
public static byte encodeCVQualifiers(ICPPFunctionType type) {
byte modifiers = 0;
modifiers |= (type.isConst() ? 1 : 0) << CONST_OFFSET;
modifiers |= (type.isVolatile() ? 1 : 0) << VOLATILE_OFFSET;
return modifiers;
}
}

View file

@ -0,0 +1,127 @@
/*******************************************************************************
* Copyright (c) 2006, 2012 IBM Corporation.
* 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
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/**
* A utility class for packing various annotations into bit fields. This includes
* storage class specifiers (auto, register, etc.), and CV qualifiers (const, volatile).
*/
class PDOMCAnnotations {
// Storage class specifiers and function annotations.
private static final int EXTERN_OFFSET = 0;
private static final int INLINE_OFFSET = 1;
private static final int STATIC_OFFSET = 2;
private static final int VARARGS_OFFSET = 3;
private static final int NO_RETURN_OFFSET = 4;
private static final int REGISTER_OFFSET = 5;
private static final int AUTO_OFFSET = 6;
/**
* Encodes annotations applicable to functions.
*
* @param function the function whose annotations will be encoded
* @return a bit vector of the annotations
*/
public static byte encodeFunctionAnnotations(IFunction function) {
byte annotation = 0;
if (function.isExtern())
annotation |= 1 << EXTERN_OFFSET;
if (ASTInternal.isStatic(function, false))
annotation |= 1 << STATIC_OFFSET;
if (function.isInline())
annotation |= 1 << INLINE_OFFSET;
if (function.takesVarArgs())
annotation |= 1 << VARARGS_OFFSET;
if (function.isNoReturn())
annotation |= 1 << NO_RETURN_OFFSET;
if (function.isRegister())
annotation |= 1 << REGISTER_OFFSET;
if (function.isAuto())
annotation |= 1 << AUTO_OFFSET;
return annotation;
}
/**
* Encodes annotations applicable to variables.
*
* @param variable the IBinding whose annotation will be encoded.
* @return a bit vector of the annotation.
*/
public static byte encodeVariableAnnotations(IVariable variable) {
byte modifiers = 0;
if (variable.isExtern())
modifiers |= 1 << EXTERN_OFFSET;
if (variable.isStatic())
modifiers |= 1 << STATIC_OFFSET;
if (variable.isRegister())
modifiers |= 1 << REGISTER_OFFSET;
if (variable.isAuto())
modifiers |= 1 << AUTO_OFFSET;
return modifiers;
}
/**
* Checks if the "extern" annotation is set.
*/
public static boolean isExtern(short annotation) {
return (annotation & (1 << EXTERN_OFFSET)) != 0;
}
/**
* Checks if the "static" annotation is set.
*/
public static boolean isStatic(short annotation) {
return (annotation & (1 << STATIC_OFFSET)) != 0;
}
/**
* Checks if the "inline" annotation is set.
*/
public static boolean isInline(short annotation) {
return (annotation & (1 << INLINE_OFFSET)) != 0;
}
/**
* Checks if the "varargs" annotation is set.
*/
public static boolean isVarargsFunction(short annotation) {
return (annotation & (1 << VARARGS_OFFSET)) != 0;
}
/**
* Checks if the "no return" annotation is set.
*/
public static boolean isNoReturnFunction(short annotation) {
return (annotation & (1 << NO_RETURN_OFFSET)) != 0;
}
/**
* Checks if the "register" annotation is set.
*/
public static boolean isRegister(byte annotation) {
return (annotation & (1 << REGISTER_OFFSET)) != 0;
}
/**
* Checks if the "auto" annotation is set.
*/
public static boolean isAuto(byte annotation) {
return (annotation & (1 << AUTO_OFFSET)) != 0;
}
}

View file

@ -72,7 +72,7 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
setType(getLinkage(), type);
IParameter[] parameters = function.getParameters();
setParameters(parameters);
byte annotations = PDOMCAnnotation.encodeAnnotation(function);
byte annotations = PDOMCAnnotations.encodeFunctionAnnotations(function);
getDB().putByte(record + ANNOTATIONS, annotations);
}
@ -91,7 +91,7 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
if (oldParams != null) {
oldParams.delete(linkage);
}
byte newAnnotation = PDOMCAnnotation.encodeAnnotation(func);
byte newAnnotation = PDOMCAnnotations.encodeFunctionAnnotations(func);
getDB().putByte(record + ANNOTATIONS, newAnnotation);
}
@ -138,12 +138,12 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
@Override
public boolean isStatic() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
return PDOMCAnnotations.isStatic(getAnnotations());
}
@Override
public boolean isExtern() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
return PDOMCAnnotations.isExtern(getAnnotations());
}
@Override
@ -185,17 +185,21 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
@Override
public boolean isInline() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.INLINE_OFFSET);
return PDOMCAnnotations.isInline(getAnnotations());
}
private byte getAnnotations() {
return getByte(record + ANNOTATIONS);
}
@Override
public boolean takesVarArgs() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.VARARGS_OFFSET);
return PDOMCAnnotations.isVarargsFunction(getAnnotations());
}
@Override
public boolean isNoReturn() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.NO_RETURN);
return PDOMCAnnotations.isNoReturnFunction(getAnnotations());
}
@Override

View file

@ -54,7 +54,7 @@ final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBin
db.putRecPtr(record + NEXT_PARAM, 0);
db.putRecPtr(record + NEXT_PARAM, next == null ? 0 : next.getRecord());
db.putByte(record + FLAG_OFFSET, encodeFlags(param));
db.putByte(record + FLAG_OFFSET, PDOMCAnnotations.encodeVariableAnnotations(param));
}
@Override
@ -74,14 +74,12 @@ final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBin
@Override
public boolean isAuto() {
byte flag = 1 << PDOMCAnnotation.AUTO_OFFSET;
return hasFlag(flag, true);
return true;
}
@Override
public boolean isRegister() {
byte flag = 1 << PDOMCAnnotation.REGISTER_OFFSET;
return hasFlag(flag, false);
return PDOMCAnnotations.isRegister(getFlags());
}
@Override
@ -172,22 +170,13 @@ final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBin
return null;
}
protected byte encodeFlags(IParameter param) {
// C99 ISO/IEC 9899: 6.7.5.3.2
byte flags= 0;
flags |= (param.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
flags |= (param.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET;
return flags;
}
protected boolean hasFlag(byte flag, boolean defValue) {
private byte getFlags() {
try {
byte myflags= getDB().getByte(record + FLAG_OFFSET);
return (myflags & flag) == flag;
return getDB().getByte(record + FLAG_OFFSET);
} catch (CoreException e) {
CCorePlugin.log(e);
}
return defValue;
return 0;
}
@Override

View file

@ -60,20 +60,18 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
public PDOMCVariable(PDOMLinkage linkage, PDOMNode parent, IVariable variable) throws CoreException {
super(linkage, parent, variable.getNameCharArray());
final Database db = getDB();
linkage.storeType(record + TYPE_OFFSET, variable.getType());
linkage.storeValue(record + VALUE_OFFSET, variable.getInitialValue());
db.putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(variable));
getDB().putByte(record + ANNOTATIONS, PDOMCAnnotations.encodeVariableAnnotations(variable));
}
@Override
public void update(final PDOMLinkage linkage, IBinding newBinding, IASTNode point) throws CoreException {
if (newBinding instanceof IVariable) {
final Database db = getDB();
IVariable var= (IVariable) newBinding;
linkage.storeType(record + TYPE_OFFSET, var.getType());
linkage.storeValue(record + VALUE_OFFSET, var.getInitialValue());
db.putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(var));
getDB().putByte(record + ANNOTATIONS, PDOMCAnnotations.encodeVariableAnnotations(var));
}
}
@ -113,22 +111,26 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
@Override
public boolean isStatic() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
return PDOMCAnnotations.isStatic(getAnnotations());
}
@Override
public boolean isExtern() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
return PDOMCAnnotations.isExtern(getAnnotations());
}
@Override
public boolean isAuto() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.AUTO_OFFSET);
return PDOMCAnnotations.isAuto(getAnnotations());
}
@Override
public boolean isRegister() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.REGISTER_OFFSET);
return PDOMCAnnotations.isRegister(getAnnotations());
}
private byte getAnnotations() {
return getByte(record + ANNOTATIONS);
}
@Override

View file

@ -1,109 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006, 2013 IBM Corporation.
* 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
* Markus Schorn (Wind River Systems)
* Thomas Corbat (IFS)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
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;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
class PDOMCPPAnnotation {
// "Mutable" shares the same offset as "inline" because
// only fields can be mutable and only functions can be inline.
public static final int MUTABLE_OFFSET = PDOMCAnnotation.INLINE_OFFSET;
// extern C shares the same offset as visibility because
// only members have visibility and cannot be extern C.
public static final int EXTERN_C_OFFSET= 6;
public static final int VISIBILITY_OFFSET = 6;
private static final int VISIBILITY_MASK = 0x03;
// Extra C++-specific annotations that don't fit on the first
// byte of annotations.
public static final int VIRTUAL_OFFSET = 0;
public static final int DESTRUCTOR_OFFSET = 1;
public static final int IMPLICIT_METHOD_OFFSET = 2;
public static final int EXPLICIT_METHOD_OFFSET = 3;
public static final int PURE_VIRTUAL_OFFSET = 4;
public static final int OVERRIDE_OFFSET = 5;
public static final int FINAL_OFFSET = 6;
public static final int MAX_EXTRA_OFFSET= FINAL_OFFSET;
/**
* Encodes storage class specifiers and other annotation, including
* C++-specific annotation, from an IBinding as a bit vector.
*
* @param binding the IBinding whose annotation will be encoded.
* @return a bit vector of the annotation.
*/
public static byte encodeAnnotation(IBinding binding) {
byte modifiers = PDOMCAnnotation.encodeAnnotation(binding);
if (binding instanceof ICPPMember) {
ICPPMember member = (ICPPMember) binding;
int mask = ~(VISIBILITY_MASK << VISIBILITY_OFFSET);
modifiers &= mask;
modifiers |= (member.getVisibility() & VISIBILITY_MASK) << VISIBILITY_OFFSET;
if (binding instanceof ICPPField) {
ICPPField variable = (ICPPField) binding;
modifiers |= (variable.isMutable() ? 1 : 0) << MUTABLE_OFFSET;
}
} else {
if (binding instanceof ICPPFunction) {
if (((ICPPFunction) binding).isExternC()) {
modifiers |= 1 << EXTERN_C_OFFSET;
}
} else if (binding instanceof ICPPVariable) {
if (((ICPPVariable) binding).isExternC()) {
modifiers |= 1 << EXTERN_C_OFFSET;
}
}
}
return modifiers;
}
/**
* Encodes C++-specific annotation not already handled by
* encodeAnnotation() as a bit vector.
*
* @param binding the IBinding whose annotation will be encoded.
* @return a bit vector of the annotation.
* @throws DOMException
*/
public static byte encodeExtraAnnotation(IBinding binding) throws DOMException {
byte modifiers = 0;
if (binding instanceof ICPPMethod) {
ICPPMethod method = (ICPPMethod) binding;
modifiers |= (method.isVirtual() ? 1 : 0) << VIRTUAL_OFFSET;
modifiers |= (method.isDestructor() ? 1 : 0) << DESTRUCTOR_OFFSET;
modifiers |= (method.isImplicit() ? 1 : 0) << IMPLICIT_METHOD_OFFSET;
modifiers |= (method.isPureVirtual() ? 1 : 0) << PURE_VIRTUAL_OFFSET;
modifiers |= (method.isExplicit() ? 1 : 0) << EXPLICIT_METHOD_OFFSET;
modifiers |= (method.isOverride() ? 1 : 0) << OVERRIDE_OFFSET;
modifiers |= (method.isFinal() ? 1 : 0) << FINAL_OFFSET;
}
return modifiers;
}
/**
* Unpacks visibility information from a bit vector of annotation.
* @param annotation Annotation containing visibility information.
* @return The visibility component of the annotation.
*/
public static int getVisibility(int annotation) {
return (annotation >> VISIBILITY_OFFSET) & VISIBILITY_MASK;
}
}

View file

@ -0,0 +1,281 @@
/*******************************************************************************
* Copyright (c) 2006, 2013 IBM Corporation.
* 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
* Markus Schorn (Wind River Systems)
* Thomas Corbat (IFS)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
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;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
class PDOMCPPAnnotations {
private static final int VISIBILITY_OFFSET = 0;
private static final int VISIBILITY_MASK = 0x03;
private static final int EXTERN_OFFSET = 2;
private static final int MUTABLE_OFFSET = 3;
private static final int STATIC_OFFSET = 4;
private static final int CONSTEXPR_OFFSET = 5;
// "Inline" shares the same offset as "mutable" because
// only fields can be mutable and only functions can be inline.
private static final int INLINE_OFFSET = MUTABLE_OFFSET;
// "extern C" shares the same offset as visibility because
// only members have visibility and they cannot be extern C.
private static final int EXTERN_C_OFFSET = VISIBILITY_OFFSET;
// Function annotations start here.
private static final int VARARGS_OFFSET = 6;
private static final int PARAMETER_PACK_OFFSET = 7;
private static final int DELETED_OFFSET = 8;
private static final int NO_RETURN_OFFSET = 9;
// Method annotations that don't fit on the first 16 bits of annotations.
private static final int VIRTUAL_OFFSET = 0;
private static final int DESTRUCTOR_OFFSET = 1;
private static final int IMPLICIT_OFFSET = 2;
private static final int EXPLICIT_OFFSET = 3;
private static final int PURE_VIRTUAL_OFFSET = 4;
private static final int OVERRIDE_OFFSET = 5;
private static final int FINAL_OFFSET = 6;
/**
* Encodes annotations applicable to C++ functions.
*
* @param function the function whose annotations will be encoded
* @return a bit vector of the annotations
*/
public static short encodeFunctionAnnotations(ICPPFunction function) {
short annotation = encodeVisibility(function);
if (function.isExtern())
annotation |= 1 << EXTERN_OFFSET;
if (ASTInternal.isStatic(function, false))
annotation |= 1 << STATIC_OFFSET;
if (function.isInline())
annotation |= 1 << INLINE_OFFSET;
if (function.takesVarArgs())
annotation |= 1 << VARARGS_OFFSET;
if (function.isNoReturn())
annotation |= 1 << NO_RETURN_OFFSET;
if (function.isExternC())
annotation |= 1 << EXTERN_C_OFFSET;
if (function.isConstexpr())
annotation |= 1 << CONSTEXPR_OFFSET;
if (function.hasParameterPack())
annotation |= 1 << PARAMETER_PACK_OFFSET;
if (function.isDeleted())
annotation |= 1 << DELETED_OFFSET;
return annotation;
}
/**
* Encodes annotations applicable to C++ variables.
*
* @param variable the IBinding whose annotations will be encoded
* @return a bit vector of the annotations
*/
public static byte encodeVariableAnnotations(ICPPVariable variable) {
byte annotation = encodeVisibility(variable);
if (variable.isExtern())
annotation |= 1 << EXTERN_OFFSET;
if (variable.isStatic())
annotation |= 1 << STATIC_OFFSET;
if (variable.isExternC())
annotation |= 1 << EXTERN_C_OFFSET;
if (variable.isConstexpr())
annotation |= 1 << CONSTEXPR_OFFSET;
if (variable instanceof ICPPField && ((ICPPField) variable).isMutable())
annotation |= 1 << MUTABLE_OFFSET;
return annotation;
}
private static byte encodeVisibility(ICPPBinding binding) {
byte annotation = 0;
if (binding instanceof ICPPMember) {
ICPPMember member = (ICPPMember) binding;
annotation = (byte) ((member.getVisibility() & VISIBILITY_MASK) << VISIBILITY_OFFSET);
}
return annotation;
}
/**
* Encodes extra annotations applicable to C++ methods.
*
* @param binding the IBinding whose annotations will be encoded
* @return a bit vector of the annotation
*/
public static byte encodeExtraMethodAnnotations(IBinding binding) {
byte annotation = 0;
if (binding instanceof ICPPMethod) {
ICPPMethod method = (ICPPMethod) binding;
if (method.isVirtual())
annotation |= 1 << VIRTUAL_OFFSET;
if (method.isDestructor())
annotation |= 1 << DESTRUCTOR_OFFSET;
if (method.isImplicit())
annotation |= 1 << IMPLICIT_OFFSET;
if (method.isPureVirtual())
annotation |= 1 << PURE_VIRTUAL_OFFSET;
if (method.isExplicit())
annotation |= 1 << EXPLICIT_OFFSET;
if (method.isOverride())
annotation |= 1 << OVERRIDE_OFFSET;
if (method.isFinal())
annotation |= 1 << FINAL_OFFSET;
}
return annotation;
}
/**
* Unpacks visibility information from a bit vector of annotation.
*
* @param annotation the annotation containing visibility information.
* @return the visibility component of the annotation.
*/
public static int getVisibility(short annotation) {
return (annotation >> VISIBILITY_OFFSET) & VISIBILITY_MASK;
}
/**
* Checks if the "extern" annotation is set.
*/
public static boolean isExtern(short annotation) {
return (annotation & (1 << EXTERN_OFFSET)) != 0;
}
/**
* Checks if the "mutable" annotation is set.
*/
public static boolean isMutable(short annotation) {
return (annotation & (1 << MUTABLE_OFFSET)) != 0;
}
/**
* Checks if the "static" annotation is set.
*/
public static boolean isStatic(short annotation) {
return (annotation & (1 << STATIC_OFFSET)) != 0;
}
/**
* Checks if the "constexpr" annotation is set.
*/
public static boolean isConstexpr(short annotation) {
return (annotation & (1 << CONSTEXPR_OFFSET)) != 0;
}
/**
* Checks if the "inline" annotation is set.
*/
public static boolean isInline(short annotation) {
return (annotation & (1 << INLINE_OFFSET)) != 0;
}
/**
* Checks if the "extern C" annotation is set.
*/
public static boolean isExternC(short annotation) {
return (annotation & (1 << EXTERN_C_OFFSET)) != 0;
}
/**
* Checks if the "varargs" annotation is set.
*/
public static boolean isVarargsFunction(short annotation) {
return (annotation & (1 << VARARGS_OFFSET)) != 0;
}
/**
* Checks if the "has parameter pack" annotation is set.
*/
public static boolean hasParameterPack(short annotation) {
return (annotation & (1 << PARAMETER_PACK_OFFSET)) != 0;
}
/**
* Checks if the "deleted" annotation is set.
*/
public static boolean isDeletedFunction(short annotation) {
return (annotation & (1 << DELETED_OFFSET)) != 0;
}
/**
* Checks if the "no return" annotation is set.
*/
public static boolean isNoReturnFunction(short annotation) {
return (annotation & (1 << NO_RETURN_OFFSET)) != 0;
}
/**
* Checks if the "virtual" annotation is set.
*/
public static boolean isVirtualMethod(byte annotation) {
return (annotation & (1 << VIRTUAL_OFFSET)) != 0;
}
/**
* Checks if the "destructor" annotation is set.
*/
public static boolean isDestructor(byte annotation) {
return (annotation & (1 << DESTRUCTOR_OFFSET)) != 0;
}
/**
* Checks if the "implicit" annotation is set.
*/
public static boolean isImplicitMethod(byte annotation) {
return (annotation & (1 << IMPLICIT_OFFSET)) != 0;
}
/**
* Checks if the "explicit" annotation is set.
*/
public static boolean isExplicitMethod(byte annotation) {
return (annotation & (1 << EXPLICIT_OFFSET)) != 0;
}
/**
* Checks if the "pure virtual " annotation is set.
*/
public static boolean isPureVirtualMethod(byte annotation) {
return (annotation & (1 << PURE_VIRTUAL_OFFSET)) != 0;
}
/**
* Checks if the "override" annotation is set.
*/
public static boolean isOverrideMethod(byte annotation) {
return (annotation & (1 << OVERRIDE_OFFSET)) != 0;
}
/**
* Checks if the "final" annotation is set.
*/
public static boolean isFinalMethod(byte annotation) {
return (annotation & (1 << FINAL_OFFSET)) != 0;
}
/**
* Checks if the "explicit" annotation is set.
*/
public static byte clearImplicitMethodFlag(byte annotation) {
return (byte) (annotation & ~(1 << IMPLICIT_OFFSET));
}
}

View file

@ -47,6 +47,7 @@ public class PDOMCPPConstructorInstance extends PDOMCPPMethodInstance
super(linkage, bindingRecord);
}
@Override
public void initData(ICPPExecution constructorChain) {
if (constructorChain == null)
return;

View file

@ -47,6 +47,7 @@ class PDOMCPPConstructorSpecialization extends PDOMCPPMethodSpecialization
super(linkage, bindingRecord);
}
@Override
public void initData(ICPPExecution constructorChain) {
if (constructorChain == null)
return;

View file

@ -45,6 +45,7 @@ class PDOMCPPConstructorTemplateSpecialization extends PDOMCPPMethodTemplateSpec
super(linkage, bindingRecord);
}
@Override
public void initData(ICPPExecution constructorChain) {
if (constructorChain == null)
return;

View file

@ -68,12 +68,12 @@ class PDOMCPPField extends PDOMCPPVariable implements ICPPField {
@Override
public int getVisibility() {
return PDOMCPPAnnotation.getVisibility(getByte(record + ANNOTATIONS));
return PDOMCPPAnnotations.getVisibility(getAnnotations());
}
@Override
public boolean isMutable() {
return getBit(getByte(record + ANNOTATIONS), PDOMCPPAnnotation.MUTABLE_OFFSET);
return PDOMCPPAnnotations.isMutable(getAnnotations());
}
@Override

View file

@ -40,7 +40,7 @@ public class PDOMCPPFieldInstance extends PDOMCPPVariableInstance implements ICP
@Override
public int getVisibility() {
return PDOMCPPAnnotation.getVisibility(getByte(record + PDOMCPPVariableInstance.ANNOTATIONS));
return PDOMCPPAnnotations.getVisibility(getAnnotations());
}
@Override

View file

@ -33,8 +33,7 @@ import org.eclipse.core.runtime.CoreException;
* Binding for a specialization of a field, used in the index.
*/
class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements ICPPField {
private static final int TYPE_OFFSET = PDOMCPPSpecialization.RECORD_SIZE + 0;
private static final int TYPE_OFFSET = PDOMCPPSpecialization.RECORD_SIZE;
private static final int VALUE_OFFSET = TYPE_OFFSET + Database.TYPE_SIZE;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = VALUE_OFFSET + Database.VALUE_SIZE;
@ -131,6 +130,11 @@ class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements ICPPFi
return getField().isMutable();
}
@Override
public boolean isConstexpr() {
return getField().isConstexpr();
}
@Override
public int getFieldPosition() {
return getField().getFieldPosition();

View file

@ -51,7 +51,7 @@ public class PDOMCPPFieldTemplate extends PDOMCPPVariableTemplate implements ICP
@Override
public int getVisibility() {
return PDOMCPPAnnotation.getVisibility(getByte(record + PDOMCPPVariableTemplate.ANNOTATIONS));
return PDOMCPPAnnotations.getVisibility(getAnnotations());
}
@Override

View file

@ -49,7 +49,7 @@ public class PDOMCPPFieldTemplatePartialSpecialization extends PDOMCPPVariableTe
@Override
public int getVisibility() {
return PDOMCPPAnnotation.getVisibility(getByte(record + PDOMCPPVariableTemplate.ANNOTATIONS));
return PDOMCPPAnnotations.getVisibility(getAnnotations());
}
@Override

View file

@ -35,17 +35,12 @@ import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
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;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
* Binding for c++ functions in the index.
*/
class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverloader, ICPPComputableFunction {
private static final short ANNOT_PARAMETER_PACK = 8;
private static final short ANNOT_IS_DELETED = 9;
private static final short ANNOT_IS_CONSTEXPR = 10;
/**
* Offset of total number of function parameters (relative to the beginning of the record).
*/
@ -89,7 +84,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = FUNCTION_BODY + Database.EXECUTION_SIZE;
private short fAnnotation = -1;
private short fAnnotations = -1;
private int fRequiredArgCount = -1;
private ICPPFunctionType fType; // No need for volatile, all fields of ICPPFunctionTypes are final.
@ -99,25 +94,15 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
Database db = getDB();
Integer sigHash = IndexCPPSignatureUtil.getSignatureHash(function);
getDB().putInt(record + SIGNATURE_HASH, sigHash != null ? sigHash.intValue() : 0);
db.putShort(record + ANNOTATION, getAnnotation(function));
db.putShort(record + ANNOTATION, getAnnotations(function));
db.putShort(record + REQUIRED_ARG_COUNT, (short) function.getRequiredArgumentCount());
if (setTypes) {
linkage.new ConfigureFunction(function, this, point);
}
}
private short getAnnotation(ICPPFunction function) {
int annot = PDOMCPPAnnotation.encodeAnnotation(function) & 0xff;
if (function.hasParameterPack()) {
annot |= (1 << ANNOT_PARAMETER_PACK);
}
if (function.isDeleted()) {
annot |= (1 << ANNOT_IS_DELETED);
}
if (function.isConstexpr()) {
annot |= (1 << ANNOT_IS_CONSTEXPR);
}
return (short) annot;
private short getAnnotations(ICPPFunction function) {
return PDOMCPPAnnotations.encodeFunctionAnnotations(function);
}
public void initData(ICPPFunctionType ftype, ICPPParameter[] params, IType[] exceptionSpec,
@ -144,7 +129,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
int newBindingRequiredArgCount;
newType = func.getType();
newParams = func.getParameters();
newAnnotation = getAnnotation(func);
newAnnotation = getAnnotations(func);
newBindingRequiredArgCount = func.getRequiredArgumentCount();
fType = null;
@ -177,7 +162,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
}
final Database db = getDB();
db.putShort(record + ANNOTATION, newAnnotation);
fAnnotation = newAnnotation;
fAnnotations = newAnnotation;
db.putShort(record + REQUIRED_ARG_COUNT, (short) requiredCount);
fRequiredArgCount = requiredCount;
@ -252,7 +237,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
@Override
public boolean isInline() {
return getBit(getAnnotation(), PDOMCAnnotation.INLINE_OFFSET);
return PDOMCPPAnnotations.isInline(getAnnotations());
}
@Override
@ -267,20 +252,20 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
return fRequiredArgCount;
}
final protected short getAnnotation() {
if (fAnnotation == -1) {
protected final short getAnnotations() {
if (fAnnotations == -1) {
try {
fAnnotation = getDB().getShort(record + ANNOTATION);
fAnnotations = getDB().getShort(record + ANNOTATION);
} catch (CoreException e) {
fAnnotation = 0;
fAnnotations = 0;
}
}
return fAnnotation;
return fAnnotations;
}
@Override
public boolean isExternC() {
return getBit(getAnnotation(), PDOMCPPAnnotation.EXTERN_C_OFFSET);
return PDOMCPPAnnotations.isExternC(getAnnotations());
}
@Override
@ -339,17 +324,17 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
@Override
public boolean isConstexpr() {
return getBit(getAnnotation(), ANNOT_IS_CONSTEXPR);
return PDOMCPPAnnotations.isConstexpr(getAnnotations());
}
@Override
public boolean isDeleted() {
return getBit(getAnnotation(), ANNOT_IS_DELETED);
return PDOMCPPAnnotations.isDeletedFunction(getAnnotations());
}
@Override
public boolean isExtern() {
return getBit(getAnnotation(), PDOMCAnnotation.EXTERN_OFFSET);
return PDOMCPPAnnotations.isExtern(getAnnotations());
}
@Override
@ -360,22 +345,22 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
@Override
public boolean isStatic() {
return getBit(getAnnotation(), PDOMCAnnotation.STATIC_OFFSET);
return PDOMCPPAnnotations.isStatic(getAnnotations());
}
@Override
public boolean takesVarArgs() {
return getBit(getAnnotation(), PDOMCAnnotation.VARARGS_OFFSET);
return PDOMCPPAnnotations.isVarargsFunction(getAnnotations());
}
@Override
public boolean isNoReturn() {
return getBit(getAnnotation(), PDOMCAnnotation.NO_RETURN);
return PDOMCPPAnnotations.isNoReturnFunction(getAnnotations());
}
@Override
public boolean hasParameterPack() {
return getBit(getAnnotation(), ANNOT_PARAMETER_PACK);
return PDOMCPPAnnotations.hasParameterPack(getAnnotations());
}
@Override

View file

@ -34,7 +34,6 @@ 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;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
@ -42,31 +41,20 @@ import org.eclipse.core.runtime.CoreException;
*/
class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
implements ICPPFunctionSpecialization, ICPPComputableFunction {
/**
* Offset of total number of function parameters (relative to the beginning of the record).
*/
/** Offset of total number of function parameters (relative to the beginning of the record). */
private static final int NUM_PARAMS = PDOMCPPSpecialization.RECORD_SIZE;
/**
* Offset of pointer to the first parameter of this function (relative to the beginning
* of the record).
*/
/** Offset of pointer to the first parameter of this function (relative to the beginning of the record). */
private static final int FIRST_PARAM = NUM_PARAMS + 4;
/**
* Offset for type of this function (relative to the beginning of the record).
*/
/** Offset for type of this function (relative to the beginning of the record). */
private static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE;
/**
* Offset of start of exception specification
*/
/** Offset of start of exception specification. */
protected static final int EXCEPTION_SPEC = FUNCTION_TYPE + Database.TYPE_SIZE; // int
/**
* Offset of annotation information (relative to the beginning of the record).
*/
protected static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // short
/** Offset of annotation information (relative to the beginning of the record). */
private static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // short
/** Offset of the number of the required arguments. */
private static final int REQUIRED_ARG_COUNT = ANNOTATION + 2; // short
@ -80,12 +68,8 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = FUNCTION_BODY + Database.EXECUTION_SIZE;
private static final short ANNOT_PARAMETER_PACK = 8;
private static final short ANNOT_IS_DELETED = 9;
private static final short ANNOT_IS_CONSTEXPR = 10;
private ICPPFunctionType fType; // No need for volatile, all fields of ICPPFunctionTypes are final.
private short fAnnotation= -1;
private short fAnnotations= -1;
private int fRequiredArgCount= -1;
public PDOMCPPFunctionSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPFunction astFunction,
@ -124,8 +108,8 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
}
db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord());
}
fAnnotation = getAnnotation(astFunction);
db.putShort(record + ANNOTATION, fAnnotation);
fAnnotations = PDOMCPPAnnotations.encodeFunctionAnnotations(astFunction);
db.putShort(record + ANNOTATION, fAnnotations);
db.putShort(record + REQUIRED_ARG_COUNT , (short) astFunction.getRequiredArgumentCount());
long typelist= 0;
if (astFunction instanceof ICPPMethod && ((ICPPMethod) astFunction).isImplicit()) {
@ -140,20 +124,6 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
}
}
private short getAnnotation(ICPPFunction astFunction) {
int annot= PDOMCPPAnnotation.encodeAnnotation(astFunction) & 0xff;
if (astFunction.hasParameterPack()) {
annot |= (1 << ANNOT_PARAMETER_PACK);
}
if (astFunction.isDeleted()) {
annot |= (1 << ANNOT_IS_DELETED);
}
if (astFunction.isConstexpr()) {
annot |= (1 << ANNOT_IS_CONSTEXPR);
}
return (short) annot;
}
public PDOMCPPFunctionSpecialization(PDOMLinkage linkage, long bindingRecord) {
super(linkage, bindingRecord);
}
@ -180,18 +150,19 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
@Override
public boolean isInline() {
return getBit(readAnnotation(), PDOMCAnnotation.INLINE_OFFSET);
return PDOMCPPAnnotations.isInline(getAnnotations());
}
private short readAnnotation() {
if (fAnnotation == -1) {
protected final short getAnnotations() {
if (fAnnotations == -1) {
try {
fAnnotation= getDB().getShort(record + ANNOTATION);
fAnnotations= getDB().getShort(record + ANNOTATION);
} catch (CoreException e) {
fAnnotation= 0;
CCorePlugin.log(e);
fAnnotations= 0;
}
}
return fAnnotation;
return fAnnotations;
}
@Override
@ -251,17 +222,17 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
@Override
public boolean isConstexpr() {
return getBit(readAnnotation(), ANNOT_IS_CONSTEXPR);
return PDOMCPPAnnotations.isConstexpr(getAnnotations());
}
@Override
public boolean isExtern() {
return getBit(readAnnotation(), PDOMCAnnotation.EXTERN_OFFSET);
return PDOMCPPAnnotations.isExtern(getAnnotations());
}
@Override
public boolean isExternC() {
return getBit(readAnnotation(), PDOMCPPAnnotation.EXTERN_C_OFFSET);
return PDOMCPPAnnotations.isExternC(getAnnotations());
}
@Override
@ -272,17 +243,17 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
@Override
public boolean isStatic() {
return getBit(readAnnotation(), PDOMCAnnotation.STATIC_OFFSET);
return PDOMCPPAnnotations.isStatic(getAnnotations());
}
@Override
public boolean takesVarArgs() {
return getBit(readAnnotation(), PDOMCAnnotation.VARARGS_OFFSET);
return PDOMCPPAnnotations.isVarargsFunction(getAnnotations());
}
@Override
public boolean isNoReturn() {
return getBit(readAnnotation(), PDOMCAnnotation.NO_RETURN);
return PDOMCPPAnnotations.isNoReturnFunction(getAnnotations());
}
@Override
@ -299,24 +270,12 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
@Override
public boolean hasParameterPack() {
return getBit(readAnnotation(), ANNOT_PARAMETER_PACK);
return PDOMCPPAnnotations.hasParameterPack(getAnnotations());
}
@Override
public boolean isDeleted() {
return getBit(readAnnotation(), ANNOT_IS_DELETED);
}
public boolean isConst() {
// ISO/IEC 14882:2003 9.3.1.3
// Only applicable to member functions
return false;
}
public boolean isVolatile() {
// ISO/IEC 14882:2003 9.3.1.3
// Only applicable to member functions
return false;
return PDOMCPPAnnotations.isDeletedFunction(getAnnotations());
}
@Override

View file

@ -30,51 +30,30 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
* Method.
*/
class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
/**
* Offset of remaining annotation information (relative to the beginning of
* the record).
*/
private static final int ANNOTATION1 = PDOMCPPFunction.RECORD_SIZE; // byte
/**
* The size in bytes of a PDOMCPPMethod record in the database.
*/
/** Offset of remaining annotation information (relative to the beginning of the record). */
private static final int METHOD_ANNOTATION = PDOMCPPFunction.RECORD_SIZE; // byte
/** The size in bytes of a PDOMCPPMethod record in the database. */
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunction.RECORD_SIZE + 1;
/**
* The bit offset of CV qualifier flags within ANNOTATION1.
*/
private static final int CV_OFFSET = PDOMCPPAnnotation.MAX_EXTRA_OFFSET + 1;
private byte annotation1= -1;
private byte methodAnnotation= -1;
public PDOMCPPMethod(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method, IASTNode point)
throws CoreException, DOMException {
super(linkage, parent, method, true, point);
Database db = getDB();
try {
annotation1= PDOMCPPAnnotation.encodeExtraAnnotation(method);
db.putByte(record + ANNOTATION1, annotation1);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
methodAnnotation= PDOMCPPAnnotations.encodeExtraMethodAnnotations(method);
getDB().putByte(record + METHOD_ANNOTATION, methodAnnotation);
}
public PDOMCPPMethod(PDOMLinkage linkage, long record) {
@ -86,19 +65,15 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
if (newBinding instanceof ICPPMethod) {
ICPPMethod method= (ICPPMethod) newBinding;
super.update(linkage, newBinding, point);
annotation1= -1;
try {
final byte annot = PDOMCPPAnnotation.encodeExtraAnnotation(method);
getDB().putByte(record + ANNOTATION1, annot);
annotation1= annot;
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
methodAnnotation= -1;
byte annot = PDOMCPPAnnotations.encodeExtraMethodAnnotations(method);
getDB().putByte(record + METHOD_ANNOTATION, annot);
methodAnnotation= annot;
} else if (newBinding == null && isImplicit()) {
// Clear the implicit flag, such that the binding will no longer be picked up.
byte annot= (byte) (getAnnotation1() ^ (1 << PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET));
getDB().putByte(record + ANNOTATION1, annot);
annotation1= annot;
byte annot= PDOMCPPAnnotations.clearImplicitMethodFlag(getMethodAnnotation());
getDB().putByte(record + METHOD_ANNOTATION, annot);
methodAnnotation= annot;
}
}
@ -114,23 +89,23 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
@Override
public boolean isVirtual() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.VIRTUAL_OFFSET);
return PDOMCPPAnnotations.isVirtualMethod(getMethodAnnotation());
}
protected byte getAnnotation1() {
if (annotation1 == -1)
annotation1= getByte(record + ANNOTATION1);
return annotation1;
private byte getMethodAnnotation() {
if (methodAnnotation == -1)
methodAnnotation= getByte(record + METHOD_ANNOTATION);
return methodAnnotation;
}
@Override
public boolean isPureVirtual() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.PURE_VIRTUAL_OFFSET);
return PDOMCPPAnnotations.isPureVirtualMethod(getMethodAnnotation());
}
@Override
public boolean isDestructor() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.DESTRUCTOR_OFFSET);
return PDOMCPPAnnotations.isDestructor(getMethodAnnotation());
}
@Override
@ -140,12 +115,12 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
@Override
public boolean isImplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
return PDOMCPPAnnotations.isImplicitMethod(getMethodAnnotation());
}
@Override
public boolean isExplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.EXPLICIT_METHOD_OFFSET);
return PDOMCPPAnnotations.isExplicitMethod(getMethodAnnotation());
}
@Override
@ -178,7 +153,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
@Override
public int getVisibility() {
return PDOMCPPAnnotation.getVisibility(getAnnotation());
return PDOMCPPAnnotations.getVisibility(getAnnotations());
}
@Override
@ -191,14 +166,6 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
throw new UnsupportedOperationException();
}
public boolean isConst() {
return getBit(getAnnotation1(), PDOMCAnnotation.CONST_OFFSET + CV_OFFSET);
}
public boolean isVolatile() {
return getBit(getAnnotation1(), PDOMCAnnotation.VOLATILE_OFFSET + CV_OFFSET);
}
@Override
public int getAdditionalNameFlags(int standardFlags, IASTName name) {
if ((standardFlags & PDOMName.IS_REFERENCE) == PDOMName.IS_REFERENCE) {
@ -261,11 +228,11 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
@Override
public boolean isOverride() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.OVERRIDE_OFFSET);
return PDOMCPPAnnotations.isOverrideMethod(getMethodAnnotation());
}
@Override
public boolean isFinal() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.FINAL_OFFSET);
return PDOMCPPAnnotations.isFinalMethod(getMethodAnnotation());
}
}

View file

@ -12,28 +12,23 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethodSpecialization;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
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;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
* Specialization of a method
*/
class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
implements ICPPMethodSpecialization {
class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization implements ICPPMethodSpecialization {
/**
* Offset of remaining annotation information (relative to the beginning of
* the record).
@ -46,25 +41,13 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunctionSpecialization.RECORD_SIZE + 1;
/**
* The bit offset of CV qualifier flags within ANNOTATION1.
*/
private static final int CV_OFFSET = PDOMCPPAnnotation.MAX_EXTRA_OFFSET + 1;
public PDOMCPPMethodSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method,
PDOMBinding specialized, IASTNode point) throws CoreException {
super(linkage, parent, method, specialized, point);
Database db = getDB();
try {
ICPPFunctionType type = method.getType();
byte annotation = 0;
annotation |= PDOMCAnnotation.encodeCVQualifiers(type) << CV_OFFSET;
annotation |= PDOMCPPAnnotation.encodeExtraAnnotation(method);
db.putByte(record + ANNOTATION1, annotation);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
byte annotation = PDOMCPPAnnotations.encodeExtraMethodAnnotations(method);
db.putByte(record + ANNOTATION1, annotation);
}
public PDOMCPPMethodSpecialization(PDOMLinkage linkage, long bindingRecord) {
@ -83,27 +66,27 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
@Override
public boolean isDestructor() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.DESTRUCTOR_OFFSET);
return PDOMCPPAnnotations.isDestructor(getByte(record + ANNOTATION1));
}
@Override
public boolean isImplicit() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
return PDOMCPPAnnotations.isImplicitMethod(getByte(record + ANNOTATION1));
}
@Override
public boolean isExplicit() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.EXPLICIT_METHOD_OFFSET);
return PDOMCPPAnnotations.isExplicitMethod(getByte(record + ANNOTATION1));
}
@Override
public boolean isVirtual() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET);
return PDOMCPPAnnotations.isVirtualMethod(getByte(record + ANNOTATION1));
}
@Override
public boolean isPureVirtual() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.PURE_VIRTUAL_OFFSET);
return PDOMCPPAnnotations.isPureVirtualMethod(getByte(record + ANNOTATION1));
}
@Override
@ -124,17 +107,7 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
@Override
public int getVisibility() {
return PDOMCPPAnnotation.getVisibility(getByte(record + ANNOTATION));
}
@Override
public boolean isConst() {
return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.CONST_OFFSET + CV_OFFSET);
}
@Override
public boolean isVolatile() {
return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.VOLATILE_OFFSET + CV_OFFSET);
return PDOMCPPAnnotations.getVisibility(getAnnotations());
}
@Override

View file

@ -16,55 +16,29 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
* Template for a method.
*/
class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements ICPPMethod {
/**
* Offset of remaining annotation information (relative to the beginning of
* the record).
*/
private static final int ANNOTATION1 = PDOMCPPFunctionTemplate.RECORD_SIZE; // byte
/**
* The size in bytes of a PDOMCPPMethodTemplate record in the database.
*/
/** Offset of remaining annotation information (relative to the beginning of the record). */
private static final int METHOD_ANNOTATION = PDOMCPPFunctionTemplate.RECORD_SIZE; // byte
/** The size in bytes of a PDOMCPPMethodTemplate record in the database. */
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunctionTemplate.RECORD_SIZE + 1;
/**
* The bit offset of CV qualifier flags within ANNOTATION1.
*/
private static final int CV_OFFSET = PDOMCPPAnnotation.MAX_EXTRA_OFFSET + 1;
private byte annotation1= -1;
private byte methodAnnotation= -1;
public PDOMCPPMethodTemplate(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method, IASTNode point)
throws CoreException, DOMException {
super(linkage, parent, (ICPPFunctionTemplate) method, point);
Database db = getDB();
try {
ICPPFunctionType type = method.getType();
byte annotation = 0;
annotation |= PDOMCAnnotation.encodeCVQualifiers(type) << CV_OFFSET;
annotation |= PDOMCPPAnnotation.encodeExtraAnnotation(method);
db.putByte(record + ANNOTATION1, annotation);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
methodAnnotation = PDOMCPPAnnotations.encodeExtraMethodAnnotations(method);
getDB().putByte(record + METHOD_ANNOTATION, methodAnnotation);
}
public PDOMCPPMethodTemplate(PDOMLinkage linkage, long bindingRecord) {
@ -83,28 +57,28 @@ class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements ICPPMetho
@Override
public boolean isDestructor() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.DESTRUCTOR_OFFSET);
}
final protected byte getAnnotation1() {
if (annotation1 == -1)
annotation1= getByte(record + ANNOTATION1);
return annotation1;
return PDOMCPPAnnotations.isDestructor(getMethodAnnotation());
}
@Override
public boolean isImplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
return PDOMCPPAnnotations.isImplicitMethod(getMethodAnnotation());
}
@Override
public boolean isExplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.EXPLICIT_METHOD_OFFSET);
return PDOMCPPAnnotations.isExplicitMethod(getMethodAnnotation());
}
@Override
public boolean isVirtual() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.VIRTUAL_OFFSET);
return PDOMCPPAnnotations.isVirtualMethod(getMethodAnnotation());
}
private byte getMethodAnnotation() {
if (methodAnnotation == -1)
methodAnnotation= getByte(record + METHOD_ANNOTATION);
return methodAnnotation;
}
@Override
@ -114,17 +88,9 @@ class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements ICPPMetho
@Override
public int getVisibility() {
return PDOMCPPAnnotation.getVisibility(getAnnotation());
return PDOMCPPAnnotations.getVisibility(getAnnotations());
}
public boolean isConst() {
return getBit(getAnnotation1(), PDOMCAnnotation.CONST_OFFSET + CV_OFFSET);
}
public boolean isVolatile() {
return getBit(getAnnotation1(), PDOMCAnnotation.VOLATILE_OFFSET + CV_OFFSET);
}
@Override
public boolean isExtern() {
// ISO/IEC 14882:2003 9.2.6

View file

@ -30,7 +30,6 @@ import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
@ -68,7 +67,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
}
private void storeAnnotations(Database db, ICPPParameter param) throws CoreException {
byte annotations = PDOMCPPAnnotation.encodeAnnotation(param);
byte annotations = PDOMCPPAnnotations.encodeVariableAnnotations(param);
db.putByte(record + ANNOTATIONS, annotations);
}
@ -119,6 +118,11 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public IType getType() {
return fType;
@ -126,9 +130,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
@Override
public boolean isAuto() {
// ISO/IEC 14882:2003 7.1.1.2
byte flag = 1 << PDOMCAnnotation.AUTO_OFFSET;
return hasFlag(flag, true, ANNOTATIONS);
return true;
}
@Override
@ -144,9 +146,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
@Override
public boolean isRegister() {
// ISO/IEC 14882:2003 7.1.1.2
byte flag = 1 << PDOMCAnnotation.REGISTER_OFFSET;
return hasFlag(flag, true, ANNOTATIONS);
return false; // We don't care whether the parameter has register storage class specifier or not.
}
@Override
@ -203,16 +203,6 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
return getType() instanceof ICPPParameterPackType;
}
private boolean hasFlag(byte flag, boolean defValue, int offset) {
try {
byte myflags= getDB().getByte(record + offset);
return (myflags & flag) == flag;
} catch (CoreException e) {
CCorePlugin.log(e);
}
return defValue;
}
@Override
public IIndexFragment getFragment() {
return getPDOM();
@ -220,13 +210,13 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
@Override
public boolean hasDefinition() throws CoreException {
// parameter bindings do not span index fragments
// Parameter bindings do not span index fragments.
return true;
}
@Override
public boolean hasDeclaration() throws CoreException {
// parameter bindings do not span index fragments
// Parameter bindings do not span index fragments.
return true;
}

View file

@ -164,6 +164,11 @@ class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements IC
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public IValue getInitialValue() {
return null;

View file

@ -213,6 +213,11 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding
public boolean isMutable() {
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public Object clone() {

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
@ -27,7 +28,6 @@ import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
@ -36,17 +36,17 @@ import org.eclipse.core.runtime.CoreException;
class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
private static final int TYPE_OFFSET = PDOMCPPBinding.RECORD_SIZE;
private static final int VALUE_OFFSET = TYPE_OFFSET + Database.TYPE_SIZE;
protected static final int ANNOTATIONS = VALUE_OFFSET + Database.VALUE_SIZE; // byte
private static final int ANNOTATIONS = VALUE_OFFSET + Database.VALUE_SIZE; // byte
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = ANNOTATIONS + 1;
public PDOMCPPVariable(PDOMLinkage linkage, PDOMNode parent, IVariable variable, boolean setTypeAndValue)
public PDOMCPPVariable(PDOMLinkage linkage, PDOMNode parent, ICPPVariable variable, boolean setTypeAndValue)
throws CoreException {
super(linkage, parent, variable.getNameCharArray());
// Find the type record
Database db = getDB();
db.putByte(record + ANNOTATIONS, encodeFlags(variable));
db.putByte(record + ANNOTATIONS, PDOMCPPAnnotations.encodeVariableAnnotations(variable));
if (setTypeAndValue) {
setType(parent.getLinkage(), variable.getType());
setValue(variable.getInitialValue());
@ -61,11 +61,11 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
public void update(final PDOMLinkage linkage, IBinding newBinding, IASTNode point) throws CoreException {
if (newBinding instanceof IVariable) {
final Database db = getDB();
IVariable var= (IVariable) newBinding;
ICPPVariable var= (ICPPVariable) newBinding;
IType newType= var.getType();
setType(linkage, newType);
setValue(var.getInitialValue());
db.putByte(record + ANNOTATIONS, encodeFlags(var));
db.putByte(record + ANNOTATIONS, PDOMCPPAnnotations.encodeVariableAnnotations(var));
}
}
@ -73,10 +73,6 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
linkage.storeType(record + TYPE_OFFSET, newType);
}
protected byte encodeFlags(IVariable variable) {
return PDOMCPPAnnotation.encodeAnnotation(variable);
}
public PDOMCPPVariable(PDOMLinkage linkage, long record) {
super(linkage, record);
}
@ -119,27 +115,38 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
@Override
public boolean isAuto() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.AUTO_OFFSET);
byte annotation = getAnnotations();
return !PDOMCPPAnnotations.isExtern(annotation) && !PDOMCPPAnnotations.isStatic(annotation)
&& getOwner() instanceof ICPPFunction;
}
@Override
public boolean isExtern() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
return PDOMCPPAnnotations.isExtern(getAnnotations());
}
@Override
public boolean isExternC() {
return getBit(getByte(record + ANNOTATIONS), PDOMCPPAnnotation.EXTERN_C_OFFSET);
return PDOMCPPAnnotations.isExternC(getAnnotations());
}
@Override
public boolean isRegister() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.REGISTER_OFFSET);
return false; // We don't care whether the parameter has register storage class specifier or not.
}
@Override
public boolean isStatic() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
return PDOMCPPAnnotations.isStatic(getAnnotations());
}
@Override
public boolean isConstexpr() {
return PDOMCPPAnnotations.isConstexpr(getAnnotations());
}
protected final byte getAnnotations() {
return getByte(record + ANNOTATIONS);
}
@Override

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariableInstance;
@ -25,14 +26,13 @@ import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
public class PDOMCPPVariableInstance extends PDOMCPPSpecialization implements ICPPVariableInstance {
private static final int TEMPLATE_ARGUMENTS = PDOMCPPSpecialization.RECORD_SIZE + 0;
private static final int TYPE = TEMPLATE_ARGUMENTS + Database.PTR_SIZE;
private static final int VALUE = TYPE + Database.TYPE_SIZE;
protected static final int ANNOTATIONS = VALUE + Database.VALUE_SIZE;
private static final int ANNOTATIONS = VALUE + Database.VALUE_SIZE; // byte
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = ANNOTATIONS + 1;
@ -48,7 +48,7 @@ public class PDOMCPPVariableInstance extends PDOMCPPSpecialization implements IC
db.putRecPtr(record + TEMPLATE_ARGUMENTS, argListRec);
getLinkage().storeType(record + TYPE, specialization.getType());
getLinkage().storeValue(record + VALUE, specialization.getInitialValue());
db.putByte(record + ANNOTATIONS, PDOMCPPAnnotation.encodeAnnotation(specialization));
db.putByte(record + ANNOTATIONS, PDOMCPPAnnotations.encodeVariableAnnotations(specialization));
}
public PDOMCPPVariableInstance(PDOMLinkage linkage, long bindingRecord) {
@ -87,27 +87,38 @@ public class PDOMCPPVariableInstance extends PDOMCPPSpecialization implements IC
@Override
public boolean isAuto() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.AUTO_OFFSET);
byte annotation = getAnnotations();
return !PDOMCPPAnnotations.isExtern(annotation) && !PDOMCPPAnnotations.isStatic(annotation)
&& getOwner() instanceof ICPPFunction;
}
@Override
public boolean isExtern() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
return PDOMCPPAnnotations.isExtern(getAnnotations());
}
@Override
public boolean isExternC() {
return getBit(getByte(record + ANNOTATIONS), PDOMCPPAnnotation.EXTERN_C_OFFSET);
return PDOMCPPAnnotations.isExternC(getAnnotations());
}
@Override
public boolean isRegister() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.REGISTER_OFFSET);
return false; // We don't care whether the parameter has register storage class specifier or not.
}
@Override
public boolean isStatic() {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
return PDOMCPPAnnotations.isStatic(getAnnotations());
}
@Override
public boolean isConstexpr() {
return PDOMCPPAnnotations.isConstexpr(getAnnotations());
}
protected final byte getAnnotations() {
return getByte(record + ANNOTATIONS);
}
@Override