]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/Basic/Builtins.h
Update clang to r86025.
[FreeBSD/FreeBSD.git] / include / clang / Basic / Builtins.h
1 //===--- Builtins.h - Builtin function header -------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines enum values for all the target-independent builtin
11 // functions.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_BASIC_BUILTINS_H
16 #define LLVM_CLANG_BASIC_BUILTINS_H
17
18 #include <cstring>
19
20 // VC++ defines 'alloca' as an object-like macro, which interferes with our
21 // builtins.
22 #undef alloca
23
24 namespace llvm {
25   template <typename T> class SmallVectorImpl;
26 }
27
28 namespace clang {
29   class TargetInfo;
30   class IdentifierTable;
31   class ASTContext;
32   class QualType;
33
34 namespace Builtin {
35 enum ID {
36   NotBuiltin  = 0,      // This is not a builtin function.
37 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
38 #include "clang/Basic/Builtins.def"
39   FirstTSBuiltin
40 };
41
42 struct Info {
43   const char *Name, *Type, *Attributes, *HeaderName;
44   bool Suppressed;
45
46   bool operator==(const Info &RHS) const {
47     return !strcmp(Name, RHS.Name) &&
48            !strcmp(Type, RHS.Type) &&
49            !strcmp(Attributes, RHS.Attributes);
50   }
51   bool operator!=(const Info &RHS) const { return !(*this == RHS); }
52 };
53
54 /// Builtin::Context - This holds information about target-independent and
55 /// target-specific builtins, allowing easy queries by clients.
56 class Context {
57   const Info *TSRecords;
58   unsigned NumTSRecords;
59 public:
60   Context(const TargetInfo &Target);
61
62   /// InitializeBuiltins - Mark the identifiers for all the builtins with their
63   /// appropriate builtin ID # and mark any non-portable builtin identifiers as
64   /// such.
65   void InitializeBuiltins(IdentifierTable &Table, bool NoBuiltins = false);
66
67   /// \brief Popular the vector with the names of all of the builtins.
68   void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names,
69                        bool NoBuiltins);
70
71   /// Builtin::GetName - Return the identifier name for the specified builtin,
72   /// e.g. "__builtin_abs".
73   const char *GetName(unsigned ID) const {
74     return GetRecord(ID).Name;
75   }
76
77   /// GetTypeString - Get the type descriptor string for the specified builtin.
78   const char *GetTypeString(unsigned ID) const {
79     return GetRecord(ID).Type;
80   }
81
82   /// isConst - Return true if this function has no side effects and doesn't
83   /// read memory.
84   bool isConst(unsigned ID) const {
85     return strchr(GetRecord(ID).Attributes, 'c') != 0;
86   }
87
88   /// isNoThrow - Return true if we know this builtin never throws an exception.
89   bool isNoThrow(unsigned ID) const {
90     return strchr(GetRecord(ID).Attributes, 'n') != 0;
91   }
92
93   /// isNoReturn - Return true if we know this builtin never returns.
94   bool isNoReturn(unsigned ID) const {
95     return strchr(GetRecord(ID).Attributes, 'r') != 0;
96   }
97
98   /// isLibFunction - Return true if this is a builtin for a libc/libm function,
99   /// with a "__builtin_" prefix (e.g. __builtin_abs).
100   bool isLibFunction(unsigned ID) const {
101     return strchr(GetRecord(ID).Attributes, 'F') != 0;
102   }
103
104   /// \brief Determines whether this builtin is a predefined libc/libm
105   /// function, such as "malloc", where we know the signature a
106   /// priori.
107   bool isPredefinedLibFunction(unsigned ID) const {
108     return strchr(GetRecord(ID).Attributes, 'f') != 0;
109   }
110
111   /// \brief If this is a library function that comes from a specific
112   /// header, retrieve that header name.
113   const char *getHeaderName(unsigned ID) const {
114     return GetRecord(ID).HeaderName;
115   }
116
117   /// \brief Determine whether this builtin is like printf in its
118   /// formatting rules and, if so, set the index to the format string
119   /// argument and whether this function as a va_list argument.
120   bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
121
122   /// hasVAListUse - Return true of the specified builtin uses __builtin_va_list
123   /// as an operand or return type.
124   bool hasVAListUse(unsigned ID) const {
125     return strpbrk(GetRecord(ID).Type, "Aa") != 0;
126   }
127
128   /// isConstWithoutErrno - Return true if this function has no side
129   /// effects and doesn't read memory, except for possibly errno. Such
130   /// functions can be const when the MathErrno lang option is
131   /// disabled.
132   bool isConstWithoutErrno(unsigned ID) const {
133     return strchr(GetRecord(ID).Attributes, 'e') != 0;
134   }
135
136 private:
137   const Info &GetRecord(unsigned ID) const;
138 };
139
140 }
141 } // end namespace clang
142 #endif