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