blob: d96d63e454529b6c87deac08dc398093b1d96bd1 [file] [log] [blame]
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTTemplate;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
/**
* @author jcamelon
*
*/
public class ASTFunction extends ASTDeclaration implements IASTFunction
{
/**
* @param scope
*/
public ASTFunction(IASTScope scope, String name, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception,
boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean hasFunctionTryBlock, boolean hasVarArgs )
{
super(ownerTemplate != null ? null : scope );
this.name = name;
this.parms = parameters;
this.returnType = returnType;
this.exceptionSpec = exception;
this.isInline = isInline;
this.isFriend = isFriend;
this.isStatic = isStatic;
this.ownerTemplateDeclaration = ownerTemplate;
if( ownerTemplate != null )
ownerTemplate.setOwnedDeclaration( this );
offsets.setStartingOffset( startOffset );
offsets.setNameOffset( nameOffset );
qualifiedName = new ASTQualifiedNamedElement( scope, name );
setNameEndOffset(nameEndOffset);
this.hasFunctionTryBlock = hasFunctionTryBlock;
this.varArgs = hasVarArgs;
}
private boolean previouslyDeclared;
private boolean hasFunctionBody = false;
private final IASTQualifiedNameElement qualifiedName;
private final IASTTemplate ownerTemplateDeclaration;
private NamedOffsets offsets = new NamedOffsets();
private List declarations = new ArrayList();
private final IASTExceptionSpecification exceptionSpec;
private final String name;
private final List parms;
private final IASTAbstractDeclaration returnType;
private final boolean isInline, isFriend, isStatic;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#isInline()
*/
public boolean isInline()
{
return isInline;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#isFriend()
*/
public boolean isFriend()
{
return isFriend;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#isStatic()
*/
public boolean isStatic()
{
return isStatic;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()
*/
public String getName()
{
return name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#getReturnType()
*/
public IASTAbstractDeclaration getReturnType()
{
return returnType;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#getParameters()
*/
public Iterator getParameters()
{
return parms.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#getExceptionSpec()
*/
public IASTExceptionSpecification getExceptionSpec()
{
return exceptionSpec;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset()
*/
public int getNameOffset()
{
return offsets.getNameOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int)
*/
public void setNameOffset(int o)
{
offsets.setNameOffset( o );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration()
*/
public IASTTemplate getOwnerTemplateDeclaration()
{
return ownerTemplateDeclaration;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int)
*/
public void setStartingOffset(int o)
{
offsets.setStartingOffset(o);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int)
*/
public void setEndingOffset(int o)
{
offsets.setEndingOffset(o);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset()
*/
public int getStartingOffset()
{
return offsets.getStartingOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset()
*/
public int getEndingOffset()
{
return offsets.getEndingOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations()
*/
public Iterator getDeclarations()
{
return declarations.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName()
*/
public String[] getFullyQualifiedName()
{
return qualifiedName.getFullyQualifiedName();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
try
{
requestor.acceptFunctionDeclaration(this);
}
catch (Exception e)
{
/* do nothing */
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
try
{
requestor.enterFunctionBody( this );
}
catch (Exception e)
{
/* do nothing */
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
try
{
requestor.exitFunctionBody( this );
}
catch (Exception e)
{
/* do nothing */
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionBody(boolean)
*/
public void setHasFunctionBody(boolean b) {
hasFunctionBody = true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionBody()
*/
public boolean hasFunctionBody() {
return hasFunctionBody;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getOwnerCodeScope()
*/
public IASTCodeScope getOwnerCodeScope()
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#previouslyDeclared()
*/
public boolean previouslyDeclared()
{
return previouslyDeclared;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset()
*/
public int getNameEndOffset()
{
return offsets.getNameEndOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int)
*/
public void setNameEndOffset(int o)
{
offsets.setNameEndOffset(o);
}
private boolean hasFunctionTryBlock = false;
private final boolean varArgs;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionTryBlock(boolean)
*/
public void setHasFunctionTryBlock(boolean b)
{
hasFunctionTryBlock = b;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionTryBlock()
*/
public boolean hasFunctionTryBlock()
{
return hasFunctionTryBlock;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#takesVarArgs()
*/
public boolean takesVarArgs() {
return varArgs;
}
}