mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 406462 - Allow designated initializers for C++
Change-Id: Iafadba03e6a54b679b4c10ea693a5f8a84ddf839
This commit is contained in:
parent
49a9b0c3f6
commit
f0bd13a754
26 changed files with 4574 additions and 3632 deletions
|
@ -24,7 +24,11 @@ import static org.eclipse.cdt.core.parser.ParserLanguage.CPP;
|
|||
import static org.eclipse.cdt.core.parser.tests.VisibilityAsserts.assertVisibility;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
|
@ -90,11 +94,14 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||
|
@ -133,6 +140,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.SemanticQueries;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
@ -151,11 +159,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|||
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class AST2CPPTests extends AST2TestBase {
|
||||
|
||||
|
@ -11625,4 +11629,40 @@ public class AST2CPPTests extends AST2TestBase {
|
|||
// this test will need to be updated.
|
||||
helper.assertVariableValue("generic_lambdas_supported", 0);
|
||||
}
|
||||
|
||||
|
||||
// struct S {
|
||||
// int x;
|
||||
// int y;
|
||||
// int z[10];
|
||||
// };
|
||||
// S a = { .x = 10, .y = 11 };
|
||||
// S b = { .z[4 ... 6] = 3 };
|
||||
// int c[6] = { [4] = 29, [2] = 15 };
|
||||
// int d[6] = { [2 ... 4] = 29 };
|
||||
public void testDesignatedInitializers() throws Exception {
|
||||
BindingAssertionHelper bh = getAssertionHelper();
|
||||
ICPPASTDesignatedInitializer d1 = bh.assertNode(".x = 10");
|
||||
assertEquals(1, d1.getDesignators().length);
|
||||
assertTrue(d1.getDesignators()[0] instanceof ICPPASTFieldDesignator);
|
||||
ICPPASTDesignatedInitializer d2 = bh.assertNode(".y = 11");
|
||||
assertEquals(1, d2.getDesignators().length);
|
||||
assertTrue(d2.getDesignators()[0] instanceof ICPPASTFieldDesignator);
|
||||
ICPPASTDesignatedInitializer d3 = bh.assertNode(".z[4 ... 6] = 3");
|
||||
assertEquals(2, d3.getDesignators().length);
|
||||
assertTrue(d3.getDesignators()[0] instanceof ICPPASTFieldDesignator);
|
||||
assertTrue(d3.getDesignators()[1] instanceof IGPPASTArrayRangeDesignator);
|
||||
ICPPASTDesignatedInitializer d4 = bh.assertNode("[4] = 29");
|
||||
assertEquals(1, d4.getDesignators().length);
|
||||
assertTrue(d4.getDesignators()[0] instanceof ICPPASTArrayDesignator);
|
||||
ICPPASTDesignatedInitializer d5 = bh.assertNode("[2] = 15");
|
||||
assertEquals(1, d5.getDesignators().length);
|
||||
assertTrue(d5.getDesignators()[0] instanceof ICPPASTArrayDesignator);
|
||||
ICPPASTDesignatedInitializer d6 = bh.assertNode("[2 ... 4] = 29");
|
||||
assertEquals(1, d6.getDesignators().length);
|
||||
assertTrue(d6.getDesignators()[0] instanceof IGPPASTArrayRangeDesignator);
|
||||
ICPPField x = bh.assertNonProblemOnFirstIdentifier(".x");
|
||||
ICPPField y = bh.assertNonProblemOnFirstIdentifier(".y");
|
||||
ICPPField a = bh.assertNonProblemOnFirstIdentifier(".z[4 ... 6]");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,14 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.index.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* For testing resolution of bindings in C++ code with GNU extensions.
|
||||
*/
|
||||
|
@ -82,6 +83,17 @@ public abstract class IndexGPPBindingResolutionTest extends IndexBindingResoluti
|
|||
suite.addTest(ProjectWithDepProj.suite());
|
||||
}
|
||||
|
||||
// struct B {
|
||||
// float f;
|
||||
// };
|
||||
|
||||
// struct B b = {
|
||||
// .f = 3.1
|
||||
// };
|
||||
public void testDesignatedInitializer() throws Exception {
|
||||
IField f= getBindingFromASTName("f", 0);
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// struct underlying_type {
|
||||
// typedef __underlying_type(T) type;
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDecltypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier;
|
||||
|
@ -378,7 +379,7 @@ public class ASTStringUtil {
|
|||
}
|
||||
trimRight(buffer);
|
||||
buffer.append(Keywords.cpRBRACE);
|
||||
} else if (initializer instanceof ICASTDesignatedInitializer) {
|
||||
} else if (initializer instanceof ICASTDesignatedInitializer || initializer instanceof ICPPASTDesignatedInitializer) {
|
||||
//TODO handle ICASTDesignatedInitializer?
|
||||
// final ICASTDesignatedInitializer designatedInitializer= (ICASTDesignatedInitializer) initializer;
|
||||
// final ICASTDesignator[] designator= designatedInitializer.getDesignators();
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDecltypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVirtSpecifier;
|
||||
|
@ -346,6 +347,13 @@ public abstract class ASTVisitor {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.12
|
||||
*/
|
||||
public int visit(ICPPASTDesignator designator) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.7
|
||||
*/
|
||||
|
@ -476,6 +484,13 @@ public abstract class ASTVisitor {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.12
|
||||
*/
|
||||
public int leave(ICPPASTDesignator designator) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.7
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
|
||||
/**
|
||||
* Array designator, e.g. [4] in int a[6] = { [4] = 29, [2] = 15 };
|
||||
* @since 5.12
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTArrayDesignator extends ICPPASTDesignator {
|
||||
/**
|
||||
* The relationship between the array designator and the subscript expression.
|
||||
*/
|
||||
public static final ASTNodeProperty SUBSCRIPT_EXPRESSION = new ASTNodeProperty(
|
||||
"ICPPASTArrayDesignator.SUBSCRIPT_EXPRESSION - expression inside square brackets"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Returns the subscript expression.
|
||||
*/
|
||||
public ICPPASTExpression getSubscriptExpression();
|
||||
|
||||
/**
|
||||
* Sets the subscript expression.
|
||||
*
|
||||
* @param expression the expression for the subscript
|
||||
*/
|
||||
public void setSubscriptExpression(ICPPASTExpression expression);
|
||||
|
||||
@Override
|
||||
public ICPPASTArrayDesignator copy();
|
||||
|
||||
@Override
|
||||
public ICPPASTArrayDesignator copy(CopyStyle style);
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
|
||||
/**
|
||||
* This interface represents a designated initializer,
|
||||
* e.g. in struct A y = { .z = 4, .t[1] = 3 };
|
||||
* @since 5.12
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTDesignatedInitializer extends IASTInitializer, ICPPASTInitializerClause {
|
||||
/** The part of the initializer before the equal sign. */
|
||||
public static final ASTNodeProperty DESIGNATOR = new ASTNodeProperty(
|
||||
"ICPPASTDesignatedInitializer.DESIGNATOR - [ICPPASTDesignator]"); //$NON-NLS-1$
|
||||
|
||||
/** The part of the initializer after the equal sign. */
|
||||
public static final ASTNodeProperty OPERAND = new ASTNodeProperty(
|
||||
"ICPPASTDesignatedInitializer.OPERAND - [ICPPASTInitializerClause]"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Adds a designator to this initializer.
|
||||
*/
|
||||
public void addDesignator(ICPPASTDesignator designator);
|
||||
|
||||
/**
|
||||
* Returns all of the designators.
|
||||
*/
|
||||
public ICPPASTDesignator[] getDesignators();
|
||||
|
||||
/**
|
||||
* Returns the operand of the initializer.
|
||||
*/
|
||||
public ICPPASTInitializerClause getOperand();
|
||||
|
||||
/**
|
||||
* Sets the initializer clause. Not allowed on a frozen AST.
|
||||
*/
|
||||
void setOperand(ICPPASTInitializerClause operand);
|
||||
|
||||
@Override
|
||||
public ICPPASTDesignatedInitializer copy();
|
||||
|
||||
@Override
|
||||
public ICPPASTDesignatedInitializer copy(CopyStyle style);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
||||
/**
|
||||
* Base interface for all C-style designators.
|
||||
* @since 5.12
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTDesignator extends IASTNode {
|
||||
public static final ICPPASTDesignator[] EMPTY_ARRAY = {};
|
||||
|
||||
@Override
|
||||
public ICPPASTDesignator copy();
|
||||
|
||||
@Override
|
||||
public ICPPASTDesignator copy(CopyStyle style);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
||||
/**
|
||||
* Specific designator that represents a field reference.
|
||||
* @since 5.12
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTFieldDesignator extends ICPPASTDesignator {
|
||||
/** The name of the field being initialized. */
|
||||
public static final ASTNodeProperty FIELD_NAME = new ASTNodeProperty(
|
||||
"ICPPASTFieldDesignator.FIELD_NAME - field name"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Returns the field name.
|
||||
*/
|
||||
public IASTName getName();
|
||||
|
||||
/**
|
||||
* Sets the field name.
|
||||
*/
|
||||
public void setName(IASTName name);
|
||||
|
||||
@Override
|
||||
public ICPPASTFieldDesignator copy();
|
||||
|
||||
@Override
|
||||
public ICPPASTFieldDesignator copy(CopyStyle style);
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
* Mike Kucera (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Thomas Corbat (IFS)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -30,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation.Operator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
|
||||
|
@ -41,12 +43,27 @@ import org.eclipse.cdt.core.parser.IScanner;
|
|||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPNodeFactory extends INodeFactory {
|
||||
/**
|
||||
* @since 5.5
|
||||
*/
|
||||
public ICPPASTAliasDeclaration newAliasDeclaration(IASTName aliasName, ICPPASTTypeId aliasedType);
|
||||
|
||||
/**
|
||||
* @since 5.2
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name);
|
||||
|
||||
/**
|
||||
* @since 5.12
|
||||
*/
|
||||
public ICPPASTArrayDesignator newArrayDesignator(ICPPASTExpression exp);
|
||||
|
||||
/**
|
||||
* @since 5.12
|
||||
*/
|
||||
public IGPPASTArrayRangeDesignator newArrayRangeDesignatorGPP(ICPPASTExpression floor, ICPPASTExpression ceiling);
|
||||
|
||||
@Override
|
||||
public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript);
|
||||
|
||||
|
@ -141,6 +158,11 @@ public interface ICPPNodeFactory extends INodeFactory {
|
|||
|
||||
public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand);
|
||||
|
||||
/**
|
||||
* @since 5.12
|
||||
*/
|
||||
public ICPPASTDesignatedInitializer newDesignatedInitializer(ICPPASTInitializerClause initializer);
|
||||
|
||||
@Override
|
||||
public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
|
||||
|
||||
|
@ -166,6 +188,11 @@ public interface ICPPNodeFactory extends INodeFactory {
|
|||
@Override
|
||||
public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
|
||||
|
||||
/**
|
||||
* @since 5.12
|
||||
*/
|
||||
public ICPPASTFieldDesignator newFieldDesignator(IASTName name);
|
||||
|
||||
@Override
|
||||
public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
|
||||
|
||||
|
@ -429,9 +456,4 @@ public interface ICPPNodeFactory extends INodeFactory {
|
|||
|
||||
@Override
|
||||
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
|
||||
|
||||
/**
|
||||
* @since 5.5
|
||||
*/
|
||||
public ICPPASTAliasDeclaration newAliasDeclaration(IASTName aliasName, ICPPASTTypeId aliasedType);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.gnu.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression;
|
||||
|
||||
/**
|
||||
* GCC-specific designator that allows for shorthand array range to be specified
|
||||
* in a designated initializer, e.g. in int a[6] = { [2 ... 4] = 29 }; or
|
||||
* struct ABC { int def[10]; } abc = { .def[4 ... 6] = 3 };
|
||||
* @since 5.12
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface IGPPASTArrayRangeDesignator extends ICPPASTDesignator {
|
||||
/** The start of the index range. */
|
||||
public static final ASTNodeProperty SUBSCRIPT_FLOOR_EXPRESSION = new ASTNodeProperty(
|
||||
"IGPPASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION - start of index range"); //$NON-NLS-1$
|
||||
|
||||
/** The end of the index range. */
|
||||
public static final ASTNodeProperty SUBSCRIPT_CEILING_EXPRESSION = new ASTNodeProperty(
|
||||
"IGPPASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION - end of index range"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Returns the start expression of the index range.
|
||||
*/
|
||||
public ICPPASTExpression getRangeFloor();
|
||||
|
||||
/**
|
||||
* Sets the start expression of the index range.
|
||||
*
|
||||
* @param expression the expression for the start of the range
|
||||
*/
|
||||
public void setRangeFloor(ICPPASTExpression expression);
|
||||
|
||||
/**
|
||||
* Returns the end expression of the index range.
|
||||
*/
|
||||
public ICPPASTExpression getRangeCeiling();
|
||||
|
||||
/**
|
||||
* Sets the end expression of the index range.
|
||||
*
|
||||
* @param expression the expression for the end of the range
|
||||
*/
|
||||
public void setRangeCeiling(ICPPASTExpression expression);
|
||||
|
||||
@Override
|
||||
public IGPPASTArrayRangeDesignator copy();
|
||||
|
||||
@Override
|
||||
public IGPPASTArrayRangeDesignator copy(CopyStyle style);
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Richard Eames
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.parser.cpp;
|
||||
|
||||
|
@ -61,6 +62,14 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.12
|
||||
*/
|
||||
@Override
|
||||
public boolean supportGCCStyleDesignators() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportKnRC() {
|
||||
return false;
|
||||
|
@ -92,7 +101,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
|
@ -101,7 +109,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
|
@ -110,7 +117,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
|
@ -119,7 +125,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 5.11
|
||||
*/
|
||||
@Override
|
||||
|
@ -127,9 +132,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#getBuiltinBindingsProvider()
|
||||
*/
|
||||
@Override
|
||||
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
||||
return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, supportGCCOtherBuiltinSymbols());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2010 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2015 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
|
||||
|
@ -9,6 +9,7 @@
|
|||
* IBM Rational Software - Initial API and implementation
|
||||
* Ed Swartz (Nokia)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.parser.cpp;
|
||||
|
||||
|
@ -17,8 +18,8 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
|
||||
import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.IToken.ContextSensitiveTokenType;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider;
|
||||
|
||||
/**
|
||||
|
@ -33,105 +34,71 @@ public class GPPParserExtensionConfiguration extends AbstractCPPParserExtensionC
|
|||
return sInstance;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#allowRestrictPointerOperators()
|
||||
*/
|
||||
@Override
|
||||
public boolean allowRestrictPointerOperators() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportTypeofUnaryExpressions()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportTypeofUnaryExpressions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportAlignOfUnaryExpression()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportAlignOfUnaryExpression() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportExtendedTemplateSyntax()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportExtendedTemplateSyntax() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportMinAndMaxOperators()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportMinAndMaxOperators() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportStatementsInExpressions()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportStatementsInExpressions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportComplexNumbers()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportComplexNumbers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportRestrictKeyword()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportRestrictKeyword() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportLongLongs()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportLongLongs() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportKnRC()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportKnRC() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportAttributeSpecifiers()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportAttributeSpecifiers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportDeclspecSpecifiers()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportDeclspecSpecifiers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#getBuiltinBindingsProvider()
|
||||
*/
|
||||
@Override
|
||||
public boolean supportGCCStyleDesignators() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
||||
return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, true);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Ed Swartz (Nokia)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.parser.cpp;
|
||||
|
||||
|
@ -151,6 +152,15 @@ public interface ICPPParserExtensionConfiguration {
|
|||
*/
|
||||
public Map<String, ContextSensitiveTokenType> getAdditionalContextSensitiveKeywords();
|
||||
|
||||
/**
|
||||
* Support for GNU extension "Designated Initializers".
|
||||
*
|
||||
* @see "http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html"
|
||||
* @return {@code true} if support for the extension should be enabled
|
||||
* @since 5.12
|
||||
*/
|
||||
public boolean supportGCCStyleDesignators();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getBuiltinBindingsProvider()} instead.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* Implementation of array designator.
|
||||
*/
|
||||
public class CPPASTArrayDesignator extends ASTNode implements ICPPASTArrayDesignator, IASTAmbiguityParent {
|
||||
private ICPPASTExpression expression;
|
||||
|
||||
public CPPASTArrayDesignator() {
|
||||
}
|
||||
|
||||
public CPPASTArrayDesignator(ICPPASTExpression exp) {
|
||||
setSubscriptExpression(exp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTArrayDesignator copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTArrayDesignator copy(CopyStyle style) {
|
||||
CPPASTArrayDesignator copy = new CPPASTArrayDesignator(
|
||||
expression == null ? null : (ICPPASTExpression) expression.copy(style));
|
||||
return copy(copy, style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTExpression getSubscriptExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubscriptExpression(ICPPASTExpression value) {
|
||||
assertNotFrozen();
|
||||
expression = value;
|
||||
if (value != null) {
|
||||
value.setParent(this);
|
||||
value.setPropertyInParent(SUBSCRIPT_EXPRESSION);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitDesignators) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (expression != null && !expression.accept(action))
|
||||
return false;
|
||||
|
||||
if (action.shouldVisitDesignators && action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (child == expression) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
expression = (ICPPASTExpression) other;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* Implementation of array range designator.
|
||||
*/
|
||||
public class CPPASTArrayRangeDesignator extends ASTNode
|
||||
implements IGPPASTArrayRangeDesignator, IASTAmbiguityParent {
|
||||
private ICPPASTExpression floor;
|
||||
private ICPPASTExpression ceiling;
|
||||
|
||||
public CPPASTArrayRangeDesignator() {
|
||||
}
|
||||
|
||||
public CPPASTArrayRangeDesignator(ICPPASTExpression floor, ICPPASTExpression ceiling) {
|
||||
setRangeFloor(floor);
|
||||
setRangeCeiling(ceiling);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTArrayRangeDesignator copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTArrayRangeDesignator copy(CopyStyle style) {
|
||||
CPPASTArrayRangeDesignator copy = new CPPASTArrayRangeDesignator();
|
||||
copy.setRangeFloor(floor == null ? null : (ICPPASTExpression) floor.copy(style));
|
||||
copy.setRangeCeiling(ceiling == null ? null : (ICPPASTExpression) ceiling.copy(style));
|
||||
return copy(copy, style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTExpression getRangeFloor() {
|
||||
return this.floor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRangeFloor(ICPPASTExpression expression) {
|
||||
assertNotFrozen();
|
||||
floor = expression;
|
||||
if (expression != null) {
|
||||
expression.setParent(this);
|
||||
expression.setPropertyInParent(SUBSCRIPT_FLOOR_EXPRESSION);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTExpression getRangeCeiling() {
|
||||
return ceiling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRangeCeiling(ICPPASTExpression expression) {
|
||||
assertNotFrozen();
|
||||
ceiling = expression;
|
||||
if (expression != null) {
|
||||
expression.setParent(this);
|
||||
expression.setPropertyInParent(SUBSCRIPT_CEILING_EXPRESSION);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitDesignators) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (floor != null && !floor.accept(action))
|
||||
return false;
|
||||
if (ceiling != null && !ceiling.accept(action))
|
||||
return false;
|
||||
|
||||
if (action.shouldVisitDesignators && action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (child == floor) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
floor = (ICPPASTExpression) other;
|
||||
}
|
||||
if (child == ceiling) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
ceiling = (ICPPASTExpression) other;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -148,7 +148,7 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier
|
|||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||
List<IBinding> filtered = new ArrayList<>();
|
||||
|
||||
ICPPClassType classType = null;
|
||||
if (getParent() instanceof CPPASTCompositeTypeSpecifier) {
|
||||
|
@ -184,6 +184,11 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier
|
|||
return filtered.toArray(new IBinding[filtered.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPackExpansion() {
|
||||
return fIsPackExpansion;
|
||||
|
@ -194,9 +199,4 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier
|
|||
assertNotFrozen();
|
||||
fIsPackExpansion= val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* Implementation for designated initializers.
|
||||
*/
|
||||
public class CPPASTDesignatedInitializer extends ASTNode
|
||||
implements ICPPASTDesignatedInitializer, IASTAmbiguityParent {
|
||||
private ICPPASTInitializerClause rhs;
|
||||
private ICPPASTDesignator[] designators = ICPPASTDesignator.EMPTY_ARRAY;
|
||||
private int designatorsPos;
|
||||
|
||||
public CPPASTDesignatedInitializer() {
|
||||
}
|
||||
|
||||
public CPPASTDesignatedInitializer(ICPPASTInitializerClause init) {
|
||||
setOperand(init);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTDesignatedInitializer copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTDesignatedInitializer copy(CopyStyle style) {
|
||||
CPPASTDesignatedInitializer copy =
|
||||
new CPPASTDesignatedInitializer(rhs == null ? null : (ICPPASTInitializerClause) rhs.copy(style));
|
||||
for (ICPPASTDesignator designator : getDesignators()) {
|
||||
copy.addDesignator(designator == null ? null : designator.copy(style));
|
||||
}
|
||||
return copy(copy, style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDesignator(ICPPASTDesignator designator) {
|
||||
assertNotFrozen();
|
||||
if (designator != null) {
|
||||
designator.setParent(this);
|
||||
designator.setPropertyInParent(DESIGNATOR);
|
||||
designators = ArrayUtil.appendAt(designators, designatorsPos++, designator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTDesignator[] getDesignators() {
|
||||
designators = ArrayUtil.trim(designators, designatorsPos);
|
||||
return designators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTInitializerClause getOperand() {
|
||||
return rhs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOperand(ICPPASTInitializerClause operand) {
|
||||
assertNotFrozen();
|
||||
this.rhs = operand;
|
||||
if (rhs != null) {
|
||||
rhs.setParent(this);
|
||||
rhs.setPropertyInParent(OPERAND);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPEvaluation getEvaluation() {
|
||||
return rhs.getEvaluation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitInitializers) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
ICPPASTDesignator[] ds = getDesignators();
|
||||
for (int i = 0; i < ds.length; i++) {
|
||||
if (!ds[i].accept(action))
|
||||
return false;
|
||||
}
|
||||
if (rhs != null && !rhs.accept(action)) return false;
|
||||
|
||||
if (action.shouldVisitInitializers) {
|
||||
switch (action.leave(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (child == rhs) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
rhs = (ICPPASTInitializerClause) other;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDesignator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
|
||||
/**
|
||||
* Implementation of field designator.
|
||||
*/
|
||||
public class CPPASTFieldDesignator extends ASTNode
|
||||
implements ICPPASTFieldDesignator, ICPPASTCompletionContext {
|
||||
private IASTName name;
|
||||
|
||||
public CPPASTFieldDesignator() {
|
||||
}
|
||||
|
||||
public CPPASTFieldDesignator(IASTName name) {
|
||||
setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTFieldDesignator copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTFieldDesignator copy(CopyStyle style) {
|
||||
CPPASTFieldDesignator copy = new CPPASTFieldDesignator(name == null ? null : name.copy(style));
|
||||
return copy(copy, style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(IASTName name) {
|
||||
assertNotFrozen();
|
||||
this.name = name;
|
||||
if (name != null) {
|
||||
name.setParent(this);
|
||||
name.setPropertyInParent(FIELD_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept( ASTVisitor action) {
|
||||
if (action.shouldVisitDesignators) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (name != null && !name.accept(action))
|
||||
return false;
|
||||
if (action.shouldVisitDesignators && action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
return CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Thomas Corbat (IFS)
|
||||
* Anders Dahlberg (Ericsson) - bug 84144
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -55,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAttribute;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
|
@ -71,12 +73,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDecltypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression;
|
||||
|
@ -84,6 +88,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
|
@ -126,6 +131,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTToken;
|
||||
|
@ -144,6 +150,11 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTAliasDeclaration newAliasDeclaration(IASTName aliasName, ICPPASTTypeId mappingTypeId) {
|
||||
return new CPPASTAliasDeclaration(aliasName, mappingTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTAlignmentSpecifier newAlignmentSpecifier(IASTExpression expression) {
|
||||
return new CPPASTAlignmentSpecifier(expression);
|
||||
|
@ -159,6 +170,16 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
return new CPPASTArrayDeclarator(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTArrayDesignator newArrayDesignator(ICPPASTExpression exp) {
|
||||
return new CPPASTArrayDesignator(exp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGPPASTArrayRangeDesignator newArrayRangeDesignatorGPP(ICPPASTExpression floor, ICPPASTExpression ceiling) {
|
||||
return new CPPASTArrayRangeDesignator(floor, ceiling);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTArrayModifier newArrayModifier(IASTExpression expr) {
|
||||
return new CPPASTArrayModifier(expr);
|
||||
|
@ -329,6 +350,11 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
return new CPPASTDeleteExpression(operand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTDesignatedInitializer newDesignatedInitializer(ICPPASTInitializerClause initializer) {
|
||||
return new CPPASTDesignatedInitializer(initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
|
||||
return new CPPASTDoStatement(body, condition);
|
||||
|
@ -386,6 +412,11 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
return new CPPASTFieldDeclarator(name, bitFieldSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTFieldDesignator newFieldDesignator(IASTName name) {
|
||||
return new CPPASTFieldDesignator(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
|
||||
return new CPPASTFieldReference(name, owner);
|
||||
|
@ -846,9 +877,4 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
|
||||
return new CPPASTWhileStatement(condition, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTAliasDeclaration newAliasDeclaration(IASTName aliasName, ICPPASTTypeId mappingTypeId) {
|
||||
return new CPPASTAliasDeclaration(aliasName, mappingTypeId);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2015 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Patrick Hofer - [Bug 328528]
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||
|
||||
|
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
|
@ -54,6 +56,9 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags {
|
|||
if (parent instanceof ICPPASTConstructorInitializer) {
|
||||
return rwInCtorInitializer(node, indirection, (ICPPASTConstructorInitializer) parent);
|
||||
}
|
||||
if (parent instanceof ICPPASTFieldDesignator) {
|
||||
return WRITE; // Field is initialized via a designated initializer.
|
||||
}
|
||||
return super.rwAnyNode(node, indirection);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier;
|
||||
|
@ -322,6 +323,8 @@ public class CPPVisitor extends ASTQueries {
|
|||
return createBinding((IASTLabelStatement) parent);
|
||||
} else if (parent instanceof ICPPASTTemplateParameter) {
|
||||
return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent);
|
||||
} else if (parent instanceof ICPPASTFieldDesignator) {
|
||||
binding = resolveBinding(parent);
|
||||
}
|
||||
|
||||
if (name.getLookupKey().length > 0)
|
||||
|
@ -1310,6 +1313,17 @@ public class CPPVisitor extends ASTQueries {
|
|||
} else {
|
||||
return new CPPScope.CPPScopeProblem(name, ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
|
||||
}
|
||||
} else if (parent instanceof ICPPASTFieldDesignator) {
|
||||
ICPPASTDeclarator declarator = findAncestorWithType(parent, ICPPASTDeclarator.class);
|
||||
if (declarator != null) {
|
||||
IType type = createType(declarator);
|
||||
type= getNestedType(type, TDEF | CVTYPE);
|
||||
if (type instanceof ICPPClassType) {
|
||||
type= SemanticUtil.mapToAST(type, name);
|
||||
return ((ICPPClassType) type).getCompositeScope();
|
||||
}
|
||||
}
|
||||
return new CPPScope.CPPScopeProblem(name, ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
|
||||
} else if (parent instanceof IASTGotoStatement || parent instanceof IASTLabelStatement) {
|
||||
while (!(parent instanceof IASTFunctionDefinition)) {
|
||||
parent = parent.getParent();
|
||||
|
@ -1398,6 +1412,9 @@ public class CPPVisitor extends ASTQueries {
|
|||
} else if (node instanceof ICPPASTFieldReference) {
|
||||
name = ((ICPPASTFieldReference) node).getFieldName();
|
||||
break;
|
||||
} else if (node instanceof ICPPASTFieldDesignator) {
|
||||
name = ((ICPPASTFieldDesignator) node).getName();
|
||||
break;
|
||||
} else if (node instanceof IASTFunctionCallExpression) {
|
||||
node = ((IASTFunctionCallExpression) node).getFunctionNameExpression();
|
||||
} else if (node instanceof IASTUnaryExpression) {
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
|
||||
|
@ -245,6 +246,7 @@ public class LookupData extends ScopeLookupData {
|
|||
if (nameProp == IASTIdExpression.ID_NAME ||
|
||||
nameProp == IASTFieldReference.FIELD_NAME ||
|
||||
nameProp == ICASTFieldDesignator.FIELD_NAME ||
|
||||
nameProp == ICPPASTFieldDesignator.FIELD_NAME ||
|
||||
nameProp == ICPPASTUsingDirective.QUALIFIED_NAME ||
|
||||
nameProp == ICPPASTUsingDeclaration.NAME ||
|
||||
nameProp == IASTFunctionCallExpression.FUNCTION_NAME ||
|
||||
|
|
|
@ -20,9 +20,14 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
|
@ -48,6 +53,8 @@ public class InitializerWriter extends NodeWriter{
|
|||
writeConstructorInitializer((ICPPASTConstructorInitializer) initializer);
|
||||
} else if (initializer instanceof ICASTDesignatedInitializer) {
|
||||
writeDesignatedInitializer((ICASTDesignatedInitializer) initializer);
|
||||
} else if (initializer instanceof ICPPASTDesignatedInitializer) {
|
||||
writeDesignatedInitializer((ICPPASTDesignatedInitializer) initializer);
|
||||
} else if (initializer instanceof ICPPASTConstructorChainInitializer) {
|
||||
writeConstructorChainInitializer((ICPPASTConstructorChainInitializer) initializer);
|
||||
}
|
||||
|
@ -90,20 +97,52 @@ public class InitializerWriter extends NodeWriter{
|
|||
desigInit.getOperand().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeDesignatedInitializer(ICPPASTDesignatedInitializer desigInit) {
|
||||
ICPPASTDesignator[] designators = desigInit.getDesignators();
|
||||
for (ICPPASTDesignator designator : designators) {
|
||||
writeDesignator(designator);
|
||||
}
|
||||
scribe.print(EQUALS);
|
||||
desigInit.getOperand().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeDesignator(ICASTDesignator designator) {
|
||||
if (designator instanceof ICASTFieldDesignator) {
|
||||
ICASTFieldDesignator fieldDes = (ICASTFieldDesignator) designator;
|
||||
scribe.print('.');
|
||||
ICASTFieldDesignator fieldDes = (ICASTFieldDesignator) designator;
|
||||
fieldDes.getName().accept(visitor);
|
||||
} else if (designator instanceof ICASTArrayDesignator) {
|
||||
ICASTArrayDesignator arrDes = (ICASTArrayDesignator) designator;
|
||||
scribe.print('[');
|
||||
ICASTArrayDesignator arrDes = (ICASTArrayDesignator) designator;
|
||||
arrDes.getSubscriptExpression().accept(visitor);
|
||||
scribe.print(']');
|
||||
} else if (designator instanceof IGCCASTArrayRangeDesignator) {
|
||||
//IGCCASTArrayRangeDesignator new_name = (IGCCASTArrayRangeDesignator) designator;
|
||||
//TODO IGCCASTArrayRangeDesignator Bespiel zu parsen bringen
|
||||
throw new UnsupportedOperationException("Writing of GCC ArrayRangeDesignator is not yet implemented"); //$NON-NLS-1$
|
||||
scribe.print('[');
|
||||
IGCCASTArrayRangeDesignator arrDes = (IGCCASTArrayRangeDesignator) designator;
|
||||
arrDes.getRangeFloor().accept(visitor);
|
||||
scribe.print(" ... "); //$NON-NLS-1$
|
||||
arrDes.getRangeCeiling().accept(visitor);
|
||||
scribe.print(']');
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDesignator(ICPPASTDesignator designator) {
|
||||
if (designator instanceof ICPPASTFieldDesignator) {
|
||||
scribe.print('.');
|
||||
ICPPASTFieldDesignator fieldDes = (ICPPASTFieldDesignator) designator;
|
||||
fieldDes.getName().accept(visitor);
|
||||
} else if (designator instanceof ICPPASTArrayDesignator) {
|
||||
scribe.print('[');
|
||||
ICPPASTArrayDesignator arrDes = (ICPPASTArrayDesignator) designator;
|
||||
arrDes.getSubscriptExpression().accept(visitor);
|
||||
scribe.print(']');
|
||||
} else if (designator instanceof IGPPASTArrayRangeDesignator) {
|
||||
scribe.print('[');
|
||||
IGPPASTArrayRangeDesignator arrDes = (IGPPASTArrayRangeDesignator) designator;
|
||||
arrDes.getRangeFloor().accept(visitor);
|
||||
scribe.print(" ... "); //$NON-NLS-1$
|
||||
arrDes.getRangeCeiling().accept(visitor);
|
||||
scribe.print(']');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,6 +111,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDecltypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
||||
|
@ -749,6 +751,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
visit((IASTInitializerList) node);
|
||||
} else if (node instanceof ICASTDesignatedInitializer) {
|
||||
visit((ICASTDesignatedInitializer) node);
|
||||
} else if (node instanceof ICPPASTDesignatedInitializer) {
|
||||
visit((ICPPASTDesignatedInitializer) node);
|
||||
} else {
|
||||
formatRaw(node);
|
||||
}
|
||||
|
@ -2497,6 +2501,47 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
private int visit(ICPPASTDesignatedInitializer node) {
|
||||
scribe.printComment();
|
||||
ICPPASTDesignator[] designators = node.getDesignators();
|
||||
for (ICPPASTDesignator designator : designators) {
|
||||
designator.accept(this);
|
||||
if (scribe.printComment()) {
|
||||
scribe.space();
|
||||
}
|
||||
}
|
||||
|
||||
if (peekNextToken() == Token.tASSIGN) {
|
||||
scribe.printNextToken(Token.tASSIGN, preferences.insert_space_before_assignment_operator);
|
||||
if (preferences.insert_space_after_assignment_operator) {
|
||||
scribe.space();
|
||||
}
|
||||
}
|
||||
|
||||
Alignment expressionAlignment= scribe.createAlignment(
|
||||
Alignment.DESIGNATED_INITIALIZER,
|
||||
preferences.alignment_for_assignment,
|
||||
1,
|
||||
getCurrentPosition());
|
||||
|
||||
scribe.enterAlignment(expressionAlignment);
|
||||
boolean ok = false;
|
||||
do {
|
||||
try {
|
||||
scribe.alignFragment(expressionAlignment, 0);
|
||||
|
||||
IASTInitializerClause initializer = node.getOperand();
|
||||
initializer.accept(this);
|
||||
|
||||
ok = true;
|
||||
} catch (AlignmentException e) {
|
||||
scribe.redoAlignment(e);
|
||||
}
|
||||
} while (!ok);
|
||||
scribe.exitAlignment(expressionAlignment, true);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
private int visit(IASTInitializerList node) {
|
||||
scribe.printComment();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue