forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.cpp
125 lines (113 loc) · 3.27 KB
/
Types.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//===--- Types.cpp - Driver input & temporary type information ------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/Driver/Types.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"
using namespace swift;
using namespace swift::driver;
using namespace swift::driver::types;
struct TypeInfo {
const char *Name;
const char *Flags;
const char *TempSuffix;
};
static const TypeInfo TypeInfos[] = {
#define TYPE(NAME, ID, TEMP_SUFFIX, FLAGS) \
{ NAME, FLAGS, TEMP_SUFFIX },
#include "swift/Driver/Types.def"
};
static const TypeInfo &getInfo(unsigned Id) {
assert(Id >= 0 && Id < TY_INVALID && "Invalid Type ID.");
return TypeInfos[Id];
}
StringRef types::getTypeName(ID Id) {
return getInfo(Id).Name;
}
StringRef types::getTypeTempSuffix(ID Id) {
return getInfo(Id).TempSuffix;
}
ID types::lookupTypeForExtension(StringRef Ext) {
if (Ext.empty())
return TY_INVALID;
assert(Ext.front() == '.' && "not a file extension");
return llvm::StringSwitch<types::ID>(Ext.drop_front())
#define TYPE(NAME, ID, SUFFIX, FLAGS) \
.Case(SUFFIX, TY_##ID)
#include "swift/Driver/Types.def"
.Default(TY_INVALID);
}
ID types::lookupTypeForName(StringRef Name) {
return llvm::StringSwitch<types::ID>(Name)
#define TYPE(NAME, ID, SUFFIX, FLAGS) \
.Case(NAME, TY_##ID)
#include "swift/Driver/Types.def"
.Default(TY_INVALID);
}
bool types::isTextual(ID Id) {
switch (Id) {
case types::TY_Swift:
case types::TY_SIL:
case types::TY_Dependencies:
case types::TY_Assembly:
case types::TY_RawSIL:
case types::TY_LLVM_IR:
case types::TY_ObjCHeader:
case types::TY_AutolinkFile:
return true;
case types::TY_Image:
case types::TY_Object:
case types::TY_dSYM:
case types::TY_SIB:
case types::TY_RawSIB:
case types::TY_SwiftModuleFile:
case types::TY_SwiftModuleDocFile:
case types::TY_LLVM_BC:
case types::TY_SerializedDiagnostics:
case types::TY_ClangModuleFile:
case types::TY_SwiftDeps:
case types::TY_Nothing:
case types::TY_Remapping:
return false;
case types::TY_INVALID:
llvm_unreachable("Invalid type ID.");
}
}
bool types::isAfterLLVM(ID Id) {
switch (Id) {
case types::TY_Assembly:
case types::TY_LLVM_IR:
case types::TY_LLVM_BC:
case types::TY_Object:
return true;
case types::TY_Swift:
case types::TY_SIL:
case types::TY_Dependencies:
case types::TY_RawSIL:
case types::TY_ObjCHeader:
case types::TY_AutolinkFile:
case types::TY_Image:
case types::TY_dSYM:
case types::TY_SIB:
case types::TY_RawSIB:
case types::TY_SwiftModuleFile:
case types::TY_SwiftModuleDocFile:
case types::TY_SerializedDiagnostics:
case types::TY_ClangModuleFile:
case types::TY_SwiftDeps:
case types::TY_Nothing:
case types::TY_Remapping:
return false;
case types::TY_INVALID:
llvm_unreachable("Invalid type ID.");
}
}