Read/write from/to PCH the diagnostic mappings that the user set so that e.g. #pragma...
[clang.git] / lib / Driver / Types.cpp
blob3c07cf2898af7e5a1295d2a42135a078507046c0
1 //===--- Types.cpp - Driver input & temporary type information ----------*-===//
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 //===----------------------------------------------------------------------===//
10 #include "clang/Driver/Types.h"
12 #include "llvm/ADT/StringSwitch.h"
13 #include <string.h>
14 #include <cassert>
16 using namespace clang::driver;
17 using namespace clang::driver::types;
19 struct TypeInfo {
20 const char *Name;
21 const char *Flags;
22 const char *TempSuffix;
23 ID PreprocessedType;
26 static const TypeInfo TypeInfos[] = {
27 #define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \
28 { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, },
29 #include "clang/Driver/Types.def"
30 #undef TYPE
32 static const unsigned numTypes = sizeof(TypeInfos) / sizeof(TypeInfos[0]);
34 static const TypeInfo &getInfo(unsigned id) {
35 assert(id > 0 && id - 1 < numTypes && "Invalid Type ID.");
36 return TypeInfos[id - 1];
39 const char *types::getTypeName(ID Id) {
40 return getInfo(Id).Name;
43 types::ID types::getPreprocessedType(ID Id) {
44 return getInfo(Id).PreprocessedType;
47 const char *types::getTypeTempSuffix(ID Id) {
48 return getInfo(Id).TempSuffix;
51 bool types::onlyAssembleType(ID Id) {
52 return strchr(getInfo(Id).Flags, 'a');
55 bool types::onlyPrecompileType(ID Id) {
56 return strchr(getInfo(Id).Flags, 'p');
59 bool types::canTypeBeUserSpecified(ID Id) {
60 return strchr(getInfo(Id).Flags, 'u');
63 bool types::appendSuffixForType(ID Id) {
64 return strchr(getInfo(Id).Flags, 'A');
67 bool types::canLipoType(ID Id) {
68 return (Id == TY_Nothing ||
69 Id == TY_Image ||
70 Id == TY_Object);
73 bool types::isAcceptedByClang(ID Id) {
74 switch (Id) {
75 default:
76 return false;
78 case TY_Asm:
79 case TY_C: case TY_PP_C:
80 case TY_CL:
81 case TY_ObjC: case TY_PP_ObjC:
82 case TY_CXX: case TY_PP_CXX:
83 case TY_ObjCXX: case TY_PP_ObjCXX:
84 case TY_CHeader: case TY_PP_CHeader:
85 case TY_ObjCHeader: case TY_PP_ObjCHeader:
86 case TY_CXXHeader: case TY_PP_CXXHeader:
87 case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
88 case TY_AST:
89 case TY_LLVM_IR: case TY_LLVM_BC:
90 return true;
94 bool types::isOnlyAcceptedByClang(ID Id) {
95 switch (Id) {
96 default:
97 return false;
99 case TY_AST:
100 case TY_LLVM_IR:
101 case TY_LLVM_BC:
102 case TY_RewrittenObjC:
103 return true;
107 bool types::isObjC(ID Id) {
108 switch (Id) {
109 default:
110 return false;
112 case TY_ObjC: case TY_PP_ObjC:
113 case TY_ObjCXX: case TY_PP_ObjCXX:
114 case TY_ObjCHeader: case TY_PP_ObjCHeader:
115 case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
116 return true;
120 bool types::isCXX(ID Id) {
121 switch (Id) {
122 default:
123 return false;
125 case TY_CXX: case TY_PP_CXX:
126 case TY_ObjCXX: case TY_PP_ObjCXX:
127 case TY_CXXHeader: case TY_PP_CXXHeader:
128 case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
129 return true;
133 types::ID types::lookupTypeForExtension(const char *Ext) {
134 return llvm::StringSwitch<types::ID>(Ext)
135 .Case("c", TY_C)
136 .Case("i", TY_PP_C)
137 .Case("m", TY_ObjC)
138 .Case("M", TY_ObjCXX)
139 .Case("h", TY_CHeader)
140 .Case("C", TY_CXX)
141 .Case("H", TY_CXXHeader)
142 .Case("f", TY_PP_Fortran)
143 .Case("F", TY_Fortran)
144 .Case("s", TY_PP_Asm)
145 .Case("S", TY_Asm)
146 .Case("ii", TY_PP_CXX)
147 .Case("mi", TY_PP_ObjC)
148 .Case("mm", TY_ObjCXX)
149 .Case("bc", TY_LLVM_BC)
150 .Case("cc", TY_CXX)
151 .Case("CC", TY_CXX)
152 .Case("cl", TY_CL)
153 .Case("cp", TY_CXX)
154 .Case("hh", TY_CXXHeader)
155 .Case("ll", TY_LLVM_IR)
156 .Case("hpp", TY_CXXHeader)
157 .Case("ads", TY_Ada)
158 .Case("adb", TY_Ada)
159 .Case("ast", TY_AST)
160 .Case("c++", TY_CXX)
161 .Case("C++", TY_CXX)
162 .Case("cxx", TY_CXX)
163 .Case("cpp", TY_CXX)
164 .Case("CPP", TY_CXX)
165 .Case("CXX", TY_CXX)
166 .Case("for", TY_PP_Fortran)
167 .Case("FOR", TY_PP_Fortran)
168 .Case("fpp", TY_Fortran)
169 .Case("FPP", TY_Fortran)
170 .Case("f90", TY_PP_Fortran)
171 .Case("f95", TY_PP_Fortran)
172 .Case("F90", TY_Fortran)
173 .Case("F95", TY_Fortran)
174 .Case("mii", TY_PP_ObjCXX)
175 .Default(TY_INVALID);
178 types::ID types::lookupTypeForTypeSpecifier(const char *Name) {
179 unsigned N = strlen(Name);
181 for (unsigned i=0; i<numTypes; ++i) {
182 types::ID Id = (types::ID) (i + 1);
183 if (canTypeBeUserSpecified(Id) &&
184 memcmp(Name, getInfo(Id).Name, N + 1) == 0)
185 return Id;
188 return TY_INVALID;
191 // FIXME: Why don't we just put this list in the defs file, eh.
193 unsigned types::getNumCompilationPhases(ID Id) {
194 if (Id == TY_Object)
195 return 1;
197 unsigned N = 0;
198 if (getPreprocessedType(Id) != TY_INVALID)
199 N += 1;
201 if (onlyAssembleType(Id))
202 return N + 2; // assemble, link
203 if (onlyPrecompileType(Id))
204 return N + 1; // precompile
206 return N + 3; // compile, assemble, link
209 phases::ID types::getCompilationPhase(ID Id, unsigned N) {
210 assert(N < getNumCompilationPhases(Id) && "Invalid index.");
212 if (Id == TY_Object)
213 return phases::Link;
215 if (getPreprocessedType(Id) != TY_INVALID) {
216 if (N == 0)
217 return phases::Preprocess;
218 --N;
221 if (onlyAssembleType(Id))
222 return N == 0 ? phases::Assemble : phases::Link;
224 if (onlyPrecompileType(Id))
225 return phases::Precompile;
227 if (N == 0)
228 return phases::Compile;
229 if (N == 1)
230 return phases::Assemble;
232 return phases::Link;
235 ID types::lookupCXXTypeForCType(ID Id) {
236 switch (Id) {
237 default:
238 return Id;
240 case types::TY_C:
241 return types::TY_CXX;
242 case types::TY_PP_C:
243 return types::TY_PP_CXX;
244 case types::TY_CHeader:
245 return types::TY_CXXHeader;
246 case types::TY_PP_CHeader:
247 return types::TY_PP_CXXHeader;