//===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the DeclObjC interface and subclasses.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_DECLOBJC_H
#define LLVM_CLANG_AST_DECLOBJC_H
#include "clang/AST/Decl.h"
#include "clang/Basic/IdentifierTable.h"
namespace clang {
class Expr;
class Stmt;
class FunctionDecl;
class AttributeList;
class ObjCIvarDecl;
class ObjCMethodDecl;
class ObjCProtocolDecl;
class ObjCCategoryDecl;
class ObjCPropertyDecl;
class ObjCPropertyImplDecl;
/// ObjCMethodDecl - Represents an instance or class method declaration.
/// ObjC methods can be declared within 4 contexts: class interfaces,
/// categories, protocols, and class implementations. While C++ member
/// functions leverage C syntax, Objective-C method syntax is modeled after
/// Smalltalk (using colons to specify argument types/expressions).
/// Here are some brief examples:
///
/// Setter/getter instance methods:
/// - (void)setMenu:(NSMenu *)menu;
/// - (NSMenu *)menu;
///
/// Instance method that takes 2 NSView arguments:
/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
///
/// Getter class method:
/// + (NSMenu *)defaultMenu;
///
/// A selector represents a unique name for a method. The selector names for
/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
///
class ObjCMethodDecl : public Decl, public DeclContext {
public:
enum ImplementationControl { None, Required, Optional };
private:
/// Bitfields must be first fields in this class so they pack with those
/// declared in class Decl.
/// instance (true) or class (false) method.
bool IsInstance : 1;
bool IsVariadic : 1;
// Synthesized declaration method for a property setter/getter
bool IsSynthesized : 1;
// NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
/// @required/@optional
unsigned DeclImplementation : 2;
// NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
/// in, inout, etc.
unsigned objcDeclQualifier : 6;
// Context this method is declared in.
NamedDecl *MethodContext;
// A unigue name for this method.
Selector SelName;
// Type of this method.
QualType MethodDeclType;
/// ParamInfo - new[]'d array of pointers to VarDecls for the formal
/// parameters of this Method. This is null if there are no formals.
ParmVarDecl **ParamInfo;
unsigned NumMethodParams;
/// List of attributes for this method declaration.
AttributeList *MethodAttrs;
SourceLocation EndLoc; // the location of the ';' or '{'.
// The following are only used for method definitions, null otherwise.
// FIXME: space savings opportunity, consider a sub-class.
Stmt *Body;
ParmVarDecl *SelfDecl;
ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
Selector SelInfo, QualType T,
Decl *contextDecl,
AttributeList *M = 0, bool isInstance = true,
bool isVariadic = false,
bool isSynthesized = false,
ImplementationControl impControl = None)
: Decl(ObjCMethod, beginLoc),
DeclContext(ObjCMethod),
IsInstance(isInstance), IsVariadic(isVariadic),
IsSynthesized(isSynthesized),
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
MethodContext(static_cast<NamedDecl*>(contextDecl)),
SelName(SelInfo), MethodDeclType(T),
ParamInfo(0), NumMethodParams(0),
MethodAttrs(M), EndLoc(endLoc), Body(0), SelfDecl(0) {}
~ObjCMethodDecl();
public:
static ObjCMethodDecl *Create(ASTContext &C,
SourceLocation beginLoc,
SourceLocation endLoc, Selector SelInfo,
QualType T, Decl *contextDecl,
AttributeList *M = 0, bool isInstance = true,
bool isVariadic = <