]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Builtins.h
Upgrade our copy of llvm/clang to r130700, from upstream's trunk.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / 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   class LangOptions;
34   
35   enum LanguageID {
36     C_LANG = 0x1,     // builtin for c only.
37     CXX_LANG = 0x2,   // builtin for cplusplus only.
38     OBJC_LANG = 0x4,  // builtin for objective-c and objective-c++
39     ALL_LANGUAGES = (C_LANG|CXX_LANG|OBJC_LANG) //builtin is for all languages.
40   };
41   
42 namespace Builtin {
43 enum ID {
44   NotBuiltin  = 0,      // This is not a builtin function.
45 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
46 #include "clang/Basic/Builtins.def"
47   FirstTSBuiltin
48 };
49
50 struct Info {
51   const char *Name, *Type, *Attributes, *HeaderName;
52   LanguageID builtin_lang;
53   bool Suppressed;
54
55   bool operator==(const Info &RHS) const {
56     return !strcmp(Name, RHS.Name) &&
57            !strcmp(Type, RHS.Type) &&
58            !strcmp(Attributes, RHS.Attributes);
59   }
60   bool operator!=(const Info &RHS) const { return !(*this == RHS); }
61 };
62
63 /// Builtin::Context - This holds information about target-independent and
64 /// target-specific builtins, allowing easy queries by clients.
65 class Context {
66   const Info *TSRecords;
67   unsigned NumTSRecords;
68 public:
69   Context(const TargetInfo &Target);
70
71   /// InitializeBuiltins - Mark the identifiers for all the builtins with their
72   /// appropriate builtin ID # and mark any non-portable builtin identifiers as
73   /// such.
74   void InitializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
75
76   /// \brief Popular the vector with the names of all of the builtins.
77   void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names,
78                        bool NoBuiltins);
79
80   /// Builtin::GetName - Return the identifier name for the specified builtin,
81   /// e.g. "__builtin_abs".
82   const char *GetName(unsigned ID) const {
83     return GetRecord(ID).Name;
84   }
85
86   /// GetTypeString - Get the type descriptor string for the specified builtin.
87   const char *GetTypeString(unsigned ID) const {
88     return GetRecord(ID).Type;
89   }
90
91   /// isConst - Return true if this function has no side effects and doesn't
92   /// read memory.
93   bool isConst(unsigned ID) const {
94     return strchr(GetRecord(ID).Attributes, 'c') != 0;
95   }
96
97   /// isNoThrow - Return true if we know this builtin never throws an exception.
98   bool isNoThrow(unsigned ID) const {
99     return strchr(GetRecord(ID).Attributes, 'n') != 0;
100   }
101
102   /// isNoReturn - Return true if we know this builtin never returns.
103   bool isNoReturn(unsigned ID) const {
104     return strchr(GetRecord(ID).Attributes, 'r') != 0;
105   }
106
107   /// isLibFunction - Return true if this is a builtin for a libc/libm function,
108   /// with a "__builtin_" prefix (e.g. __builtin_abs).
109   bool isLibFunction(unsigned ID) const {
110     return strchr(GetRecord(ID).Attributes, 'F') != 0;
111   }
112
113   /// \brief Determines whether this builtin is a predefined libc/libm
114   /// function, such as "malloc", where we know the signature a
115   /// priori.
116   bool isPredefinedLibFunction(unsigned ID) const {
117     return strchr(GetRecord(ID).Attributes, 'f') != 0;
118   }
119
120   /// \brief Determines whether this builtin has custom typechecking.
121   bool hasCustomTypechecking(unsigned ID) const {
122     return strchr(GetRecord(ID).Attributes, 't') != 0;
123   }
124
125   /// \brief Completely forget that the given ID was ever considered a builtin,
126   /// e.g., because the user provided a conflicting signature.
127   void ForgetBuiltin(unsigned ID, IdentifierTable &Table);
128   
129   /// \brief If this is a library function that comes from a specific
130   /// header, retrieve that header name.
131   const char *getHeaderName(unsigned ID) const {
132     return GetRecord(ID).HeaderName;
133   }
134
135   /// \brief Determine whether this builtin is like printf in its
136   /// formatting rules and, if so, set the index to the format string
137   /// argument and whether this function as a va_list argument.
138   bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
139
140   /// \brief Determine whether this builtin is like scanf in its
141   /// formatting rules and, if so, set the index to the format string
142   /// argument and whether this function as a va_list argument.
143   bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
144
145   /// isConstWithoutErrno - Return true if this function has no side
146   /// effects and doesn't read memory, except for possibly errno. Such
147   /// functions can be const when the MathErrno lang option is
148   /// disabled.
149   bool isConstWithoutErrno(unsigned ID) const {
150     return strchr(GetRecord(ID).Attributes, 'e') != 0;
151   }
152
153 private:
154   const Info &GetRecord(unsigned ID) const;
155 };
156
157 }
158 } // end namespace clang
159 #endif