From b8e36d1cae5fed4644d3d98f90f8046a347297af Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 22 Nov 2006 12:45:10 +0000 Subject: [PATCH] DOM: Add method to get type from ICCompositeTypeScope --- .../core/dom/ast/c/ICCompositeTypeScope.java | 10 +++++++++- .../dom/parser/c/CCompositeTypeScope.java | 14 ++++++++++++- .../core/dom/parser/c/CStructure.java | 20 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java index dd8de4a1a17..5d5a4ef8f58 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICCompositeTypeScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -16,6 +17,7 @@ package org.eclipse.cdt.core.dom.ast.c; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; /** * @author aniefer @@ -30,4 +32,10 @@ public interface ICCompositeTypeScope extends ICScope { * @throws DOMException */ public IBinding getBinding(char[] name) throws DOMException; + + /** + * Get the type this scope is associated with + * @since 4.0 + */ + public ICompositeType getCompositeType(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java index df4e1193c99..17133dc9f43 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -17,6 +18,8 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -57,4 +60,13 @@ public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope return (IBinding[]) ArrayUtil.trim( IBinding.class, result ); } + + public ICompositeType getCompositeType() { + ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) getPhysicalNode(); + IBinding binding = compSpec.getName().resolveBinding(); + if (binding instanceof ICompositeType) + return (ICompositeType) binding; + + return new CStructure.CStructureProblem( compSpec.getName(), IProblemBinding.SEMANTIC_BAD_SCOPE, compSpec.getName().toCharArray() ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index 257cb7b02c0..2bc69c23d72 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.core.runtime.PlatformObject; /** @@ -42,6 +43,25 @@ import org.eclipse.core.runtime.PlatformObject; * @author aniefer */ public class CStructure extends PlatformObject implements ICompositeType, ICInternalBinding { + + public static class CStructureProblem extends ProblemBinding implements ICompositeType { + public CStructureProblem(IASTNode node, int id, char[] arg) { + super(node, id, arg); + } + public IField findField(String name) throws DOMException { + throw new DOMException( this ); + } + public IScope getCompositeScope() throws DOMException { + throw new DOMException( this ); + } + public IField[] getFields() throws DOMException { + throw new DOMException( this ); + } + public int getKey() throws DOMException { + throw new DOMException( this ); + } + } + private IASTName [] declarations = null; private IASTName definition;