2008-02-14 10:14:34 +03:00
|
|
|
//===--- Attr.h - Classes for representing expressions ----------*- 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 Attr interface and subclasses.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-14 10:43:43 +03:00
|
|
|
#ifndef LLVM_CLANG_AST_ATTR_H
|
|
|
|
#define LLVM_CLANG_AST_ATTR_H
|
2008-02-14 10:14:34 +03:00
|
|
|
|
2008-02-16 03:24:09 +03:00
|
|
|
#include <cassert>
|
2008-02-21 22:30:49 +03:00
|
|
|
#include <string>
|
2008-07-22 01:53:04 +04:00
|
|
|
#include <algorithm>
|
2008-02-16 02:57:38 +03:00
|
|
|
|
2008-02-14 10:14:34 +03:00
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
/// Attr - This represents one attribute.
|
|
|
|
class Attr {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
2008-06-08 19:45:52 +04:00
|
|
|
Alias,
|
2008-02-14 10:14:34 +03:00
|
|
|
Aligned,
|
2008-02-21 22:30:49 +03:00
|
|
|
Packed,
|
2008-02-27 23:43:06 +03:00
|
|
|
Annotate,
|
2008-07-22 01:53:04 +04:00
|
|
|
NonNull,
|
2008-02-29 19:48:43 +03:00
|
|
|
NoReturn,
|
2008-03-03 06:28:21 +03:00
|
|
|
Deprecated,
|
|
|
|
Weak,
|
|
|
|
DLLImport,
|
|
|
|
DLLExport,
|
|
|
|
NoThrow,
|
|
|
|
Format,
|
2008-03-07 23:04:22 +03:00
|
|
|
Visibility,
|
|
|
|
FastCall,
|
2008-04-25 13:32:00 +04:00
|
|
|
StdCall,
|
2008-07-16 02:26:48 +04:00
|
|
|
TransparentUnion,
|
|
|
|
IBOutletKind // Clang-specific. Use "Kind" suffix to not conflict with
|
|
|
|
// the IBOutlet macro.
|
2008-02-14 10:14:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2008-02-14 10:43:43 +03:00
|
|
|
Attr *Next;
|
2008-02-14 10:14:34 +03:00
|
|
|
Kind AttrKind;
|
|
|
|
|
|
|
|
protected:
|
2008-02-15 10:04:12 +03:00
|
|
|
Attr(Kind AK) : Next(0), AttrKind(AK) {}
|
2008-02-16 02:30:50 +03:00
|
|
|
public:
|
2008-02-14 10:14:34 +03:00
|
|
|
virtual ~Attr() {
|
2008-02-14 10:43:43 +03:00
|
|
|
delete Next;
|
2008-02-14 10:14:34 +03:00
|
|
|
}
|
2008-02-16 02:30:50 +03:00
|
|
|
|
2008-02-14 10:14:34 +03:00
|
|
|
Kind getKind() const { return AttrKind; }
|
|
|
|
|
2008-02-14 10:43:43 +03:00
|
|
|
Attr *getNext() { return Next; }
|
|
|
|
const Attr *getNext() const { return Next; }
|
|
|
|
void setNext(Attr *next) { Next = next; }
|
2008-02-14 10:14:34 +03:00
|
|
|
|
|
|
|
void addAttr(Attr *attr) {
|
|
|
|
assert((attr != 0) && "addAttr(): attr is null");
|
2008-02-14 10:43:43 +03:00
|
|
|
|
|
|
|
// FIXME: This doesn't preserve the order in any way.
|
|
|
|
attr->Next = Next;
|
|
|
|
Next = attr;
|
2008-02-14 10:14:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
static bool classof(const Attr *) { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class PackedAttr : public Attr {
|
|
|
|
public:
|
|
|
|
PackedAttr() : Attr(Packed) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
static bool classof(const Attr *A) {
|
|
|
|
return A->getKind() == Packed;
|
|
|
|
}
|
|
|
|
static bool classof(const PackedAttr *A) { return true; }
|
|
|
|
};
|
2008-02-16 22:51:27 +03:00
|
|
|
|
|
|
|
class AlignedAttr : public Attr {
|
|
|
|
unsigned Alignment;
|
|
|
|
public:
|
|
|
|
AlignedAttr(unsigned alignment) : Attr(Aligned), Alignment(alignment) {}
|
|
|
|
|
|
|
|
unsigned getAlignment() const { return Alignment; }
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
static bool classof(const Attr *A) {
|
|
|
|
return A->getKind() == Aligned;
|
|
|
|
}
|
|
|
|
static bool classof(const AlignedAttr *A) { return true; }
|
|
|
|
};
|
2008-02-14 10:43:43 +03:00
|
|
|
|
2008-02-21 22:30:49 +03:00
|
|
|
class AnnotateAttr : public Attr {
|
|
|
|
std::string Annotation;
|
|
|
|
public:
|
|
|
|
AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {}
|
|
|
|
|
|
|
|
const std::string& getAnnotation() const { return Annotation; }
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
static bool classof(const Attr *A) {
|
|
|
|
return A->getKind() == Annotate;
|
|
|
|
}
|
|
|
|
static bool classof(const AnnotateAttr *A) { return true; }
|
|
|
|
};
|
2008-06-08 19:45:52 +04:00
|
|
|
|
|
|
|
class AliasAttr : public Attr {
|
|
|
|
std::string Aliasee;
|
|
|
|
public:
|
|
|
|
AliasAttr(const std::string &aliasee) : Attr(Alias), Aliasee(aliasee) {}
|
|
|
|
|
|
|
|
const std::string& getAliasee() const { return Aliasee; }
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == Alias; }
|
|
|
|
static bool classof(const AliasAttr *A) { return true; }
|
|
|
|
};
|
2008-07-16 02:26:48 +04:00
|
|
|
|
|
|
|
class IBOutletAttr : public Attr {
|
|
|
|
public:
|
|
|
|
IBOutletAttr() : Attr(IBOutletKind) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
static bool classof(const Attr *A) {
|
|
|
|
return A->getKind() == IBOutletKind;
|
|
|
|
}
|
|
|
|
static bool classof(const IBOutletAttr *A) { return true; }
|
|
|
|
};
|
2008-06-08 19:45:52 +04:00
|
|
|
|
2008-02-27 23:43:06 +03:00
|
|
|
class NoReturnAttr : public Attr {
|
|
|
|
public:
|
|
|
|
NoReturnAttr() : Attr(NoReturn) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == NoReturn; }
|
|
|
|
static bool classof(const NoReturnAttr *A) { return true; }
|
|
|
|
};
|
2008-02-21 22:30:49 +03:00
|
|
|
|
2008-02-29 19:48:43 +03:00
|
|
|
class DeprecatedAttr : public Attr {
|
|
|
|
public:
|
|
|
|
DeprecatedAttr() : Attr(Deprecated) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == Deprecated; }
|
|
|
|
static bool classof(const DeprecatedAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
2008-03-03 06:28:21 +03:00
|
|
|
class WeakAttr : public Attr {
|
|
|
|
public:
|
|
|
|
WeakAttr() : Attr(Weak) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == Weak; }
|
|
|
|
static bool classof(const WeakAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class NoThrowAttr : public Attr {
|
|
|
|
public:
|
|
|
|
NoThrowAttr() : Attr(NoThrow) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == NoThrow; }
|
|
|
|
static bool classof(const NoThrowAttr *A) { return true; }
|
|
|
|
};
|
2008-07-22 01:53:04 +04:00
|
|
|
|
|
|
|
class NonNullAttr : public Attr {
|
|
|
|
unsigned* ArgNums;
|
|
|
|
unsigned Size;
|
|
|
|
public:
|
|
|
|
NonNullAttr(unsigned* arg_nums = 0, unsigned size = 0) : Attr(NonNull) {
|
|
|
|
if (size) {
|
|
|
|
assert (arg_nums);
|
|
|
|
ArgNums = new unsigned[size];
|
|
|
|
Size = size;
|
|
|
|
memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ArgNums = 0;
|
|
|
|
Size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~NonNullAttr() {
|
|
|
|
delete [] ArgNums;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNonNull(unsigned arg) {
|
|
|
|
return ArgNums ? std::binary_search(ArgNums, ArgNums+Size, arg) : true;
|
|
|
|
}
|
|
|
|
};
|
2008-03-03 06:28:21 +03:00
|
|
|
|
|
|
|
class FormatAttr : public Attr {
|
|
|
|
std::string Type;
|
|
|
|
int formatIdx, firstArg;
|
|
|
|
public:
|
|
|
|
FormatAttr(const std::string &type, int idx, int first) : Attr(Format),
|
|
|
|
Type(type), formatIdx(idx), firstArg(first) {}
|
|
|
|
|
|
|
|
const std::string& getType() const { return Type; }
|
|
|
|
int getFormatIdx() const { return formatIdx; }
|
|
|
|
int getFirstArg() const { return firstArg; }
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == Format; }
|
|
|
|
static bool classof(const FormatAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class VisibilityAttr : public Attr {
|
|
|
|
public:
|
2008-05-22 04:50:06 +04:00
|
|
|
/// @brief An enumeration for the kinds of visibility of symbols.
|
|
|
|
enum VisibilityTypes {
|
|
|
|
DefaultVisibility = 0,
|
|
|
|
HiddenVisibility,
|
|
|
|
ProtectedVisibility
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
VisibilityTypes VisibilityType;
|
|
|
|
public:
|
|
|
|
VisibilityAttr(VisibilityTypes v) : Attr(Visibility),
|
2008-03-03 06:28:21 +03:00
|
|
|
VisibilityType(v) {}
|
|
|
|
|
2008-05-22 04:50:06 +04:00
|
|
|
VisibilityTypes getVisibility() const { return VisibilityType; }
|
2008-03-03 06:28:21 +03:00
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == Visibility; }
|
|
|
|
static bool classof(const VisibilityAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLLImportAttr : public Attr {
|
|
|
|
public:
|
|
|
|
DLLImportAttr() : Attr(DLLImport) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == DLLImport; }
|
|
|
|
static bool classof(const DLLImportAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLLExportAttr : public Attr {
|
|
|
|
public:
|
|
|
|
DLLExportAttr() : Attr(DLLExport) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == DLLExport; }
|
|
|
|
static bool classof(const DLLExportAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
2008-03-07 23:04:22 +03:00
|
|
|
class FastCallAttr : public Attr {
|
|
|
|
public:
|
|
|
|
FastCallAttr() : Attr(FastCall) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == FastCall; }
|
|
|
|
static bool classof(const FastCallAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class StdCallAttr : public Attr {
|
|
|
|
public:
|
|
|
|
StdCallAttr() : Attr(StdCall) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == StdCall; }
|
|
|
|
static bool classof(const StdCallAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
2008-04-25 13:32:00 +04:00
|
|
|
class TransparentUnionAttr : public Attr {
|
|
|
|
public:
|
|
|
|
TransparentUnionAttr() : Attr(TransparentUnion) {}
|
|
|
|
|
|
|
|
// Implement isa/cast/dyncast/etc.
|
|
|
|
|
|
|
|
static bool classof(const Attr *A) { return A->getKind() == TransparentUnion; }
|
|
|
|
static bool classof(const TransparentUnionAttr *A) { return true; }
|
|
|
|
};
|
|
|
|
|
2008-02-14 10:14:34 +03:00
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|