1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

DOM: Add method to get type from ICCompositeTypeScope

This commit is contained in:
Markus Schorn 2006-11-22 12:45:10 +00:00
parent 399fa8e60a
commit b8e36d1cae
3 changed files with 42 additions and 2 deletions

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
/** /**
* @author aniefer * @author aniefer
@ -30,4 +32,10 @@ public interface ICCompositeTypeScope extends ICScope {
* @throws DOMException * @throws DOMException
*/ */
public IBinding getBinding(char[] name) throws DOMException; public IBinding getBinding(char[] name) throws DOMException;
/**
* Get the type this scope is associated with
* @since 4.0
*/
public ICompositeType getCompositeType();
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; 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 ); 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() );
}
} }

View file

@ -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.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage; 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.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -42,6 +43,25 @@ import org.eclipse.core.runtime.PlatformObject;
* @author aniefer * @author aniefer
*/ */
public class CStructure extends PlatformObject implements ICompositeType, ICInternalBinding { 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 [] declarations = null;
private IASTName definition; private IASTName definition;