Skip to content

Commit d433428

Browse files
committed
Define BUILTIN_TYPE_NAME_PREFIX constant in Strings.h
Delete redundant comment Use upper case for constant
1 parent 52b4ae4 commit d433428

File tree

6 files changed

+29
-34
lines changed

6 files changed

+29
-34
lines changed

include/swift/Strings.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,39 +45,41 @@ namespace swift {
4545
/// The name of the fake module used to hold synthesized ClangImporter things.
4646
static const char MANGLING_MODULE_CLANG_IMPORTER[] = "__C_Synthesized";
4747

48-
/// The name of the Builtin type name for Int
48+
/// The name of the Builtin type prefix
49+
static const char BUILTIN_TYPE_NAME_PREFIX[] = "Builtin.";
50+
/// The name of the Builtin type for Int
4951
static const char BUILTIN_TYPE_NAME_INT[] = "Builtin.Int";
50-
/// The name of the Builtin type name for Int8
52+
/// The name of the Builtin type for Int8
5153
static const char BUILTIN_TYPE_NAME_INT8[] = "Builtin.Int8";
52-
/// The name of the Builtin type name for Int16
54+
/// The name of the Builtin type for Int16
5355
static const char BUILTIN_TYPE_NAME_INT16[] = "Builtin.Int16";
54-
/// The name of the Builtin type name for Int32
56+
/// The name of the Builtin type for Int32
5557
static const char BUILTIN_TYPE_NAME_INT32[] = "Builtin.Int32";
56-
/// The name of the Builtin type name for Int64
58+
/// The name of the Builtin type for Int64
5759
static const char BUILTIN_TYPE_NAME_INT64[] = "Builtin.Int64";
58-
/// The name of the Builtin type name for Int128
60+
/// The name of the Builtin type for Int128
5961
static const char BUILTIN_TYPE_NAME_INT128[] = "Builtin.Int128";
60-
/// The name of the Builtin type name for Int256
62+
/// The name of the Builtin type for Int256
6163
static const char BUILTIN_TYPE_NAME_INT256[] = "Builtin.Int256";
62-
/// The name of the Builtin type name for Int512
64+
/// The name of the Builtin type for Int512
6365
static const char BUILTIN_TYPE_NAME_INT512[] = "Builtin.Int512";
64-
/// The name of the Builtin type name for Float
65-
static const char BUILTIN_TYPE_NAME_Float[] = "Builtin.Float";
66-
/// The name of the Builtin type name for NativeObject
66+
/// The name of the Builtin type for Float
67+
static const char BUILTIN_TYPE_NAME_FLOAT[] = "Builtin.Float";
68+
/// The name of the Builtin type for NativeObject
6769
static const char BUILTIN_TYPE_NAME_NATIVEOBJECT[] = "Builtin.NativeObject";
68-
/// The name of the Builtin type name for BridgeObject
70+
/// The name of the Builtin type for BridgeObject
6971
static const char BUILTIN_TYPE_NAME_BRIDGEOBJECT[] = "Builtin.BridgeObject";
70-
/// The name of the Builtin type name for RawPointer
72+
/// The name of the Builtin type for RawPointer
7173
static const char BUILTIN_TYPE_NAME_RAWPOINTER[] = "Builtin.RawPointer";
72-
/// The name of the Builtin type name for UnsafeValueBuffer
74+
/// The name of the Builtin type for UnsafeValueBuffer
7375
static const char BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER[] = "Builtin.UnsafeValueBuffer";
74-
/// The name of the Builtin type name for UnknownObject
76+
/// The name of the Builtin type for UnknownObject
7577
static const char BUILTIN_TYPE_NAME_UNKNOWNOBJECT[] = "Builtin.UnknownObject";
76-
/// The name of the Builtin type name for Vector
78+
/// The name of the Builtin type for Vector
7779
static const char BUILTIN_TYPE_NAME_VEC[] = "Builtin.Vec";
78-
/// The name of the Builtin type name for SILToken
80+
/// The name of the Builtin type for SILToken
7981
static const char BUILTIN_TYPE_NAME_SILTOKEN[] = "Builtin.SILToken";
80-
/// The name of the Builtin type name for Word
82+
/// The name of the Builtin type for Word
8183
static const char BUILTIN_TYPE_NAME_WORD[] = "Builtin.Word";
8284
} // end namespace swift
8385

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,9 +3228,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
32283228
llvm::raw_svector_ostream UnderlyingOS(UnderlyingStrVec);
32293229
T->getElementType().print(UnderlyingOS);
32303230
}
3231-
std::string builtin_name = BUILTIN_NAME;
3232-
std::string builtin_type_prefix = builtin_name + ".";
3233-
if (UnderlyingStrVec.startswith(builtin_type_prefix))
3231+
if (UnderlyingStrVec.startswith(BUILTIN_TYPE_NAME_PREFIX))
32343232
UnderlyingStr = UnderlyingStrVec.substr(8);
32353233
else
32363234
UnderlyingStr = UnderlyingStrVec;

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ NodePointer Demangler::demangleBuiltinType() {
934934
if (size <= 0)
935935
return nullptr;
936936
CharVector name;
937-
name.append(BUILTIN_TYPE_NAME_Float, *this);
937+
name.append(BUILTIN_TYPE_NAME_FLOAT, *this);
938938
name.append(size, *this);
939939
Ty = createNode(Node::Kind::BuiltinTypeName, name);
940940
break;
@@ -954,16 +954,14 @@ NodePointer Demangler::demangleBuiltinType() {
954954
if (elts <= 0)
955955
return nullptr;
956956
NodePointer EltType = popTypeAndGetChild();
957-
std::string builtin_name = BUILTIN_NAME;
958-
std::string builtin_type_prefix = builtin_name + ".";
959957
if (!EltType || EltType->getKind() != Node::Kind::BuiltinTypeName ||
960-
!EltType->getText().startswith(builtin_type_prefix))
958+
!EltType->getText().startswith(BUILTIN_TYPE_NAME_PREFIX))
961959
return nullptr;
962960
CharVector name;
963961
name.append(BUILTIN_TYPE_NAME_VEC, *this);
964962
name.append(elts, *this);
965963
name.push_back('x', *this);
966-
name.append(EltType->getText().substr(strlen(builtin_type_prefix.c_str())), *this);
964+
name.append(EltType->getText().substr(strlen(BUILTIN_TYPE_NAME_PREFIX)), *this);
967965
Ty = createNode(Node::Kind::BuiltinTypeName, name);
968966
break;
969967
}

lib/Demangling/Remangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ void Remangler::mangleBuiltinTypeName(Node *node) {
614614
Buffer << 'w';
615615
} else if (stripPrefix(text, BUILTIN_TYPE_NAME_INT)) {
616616
Buffer << 'i' << text << '_';
617-
} else if (stripPrefix(text, BUILTIN_TYPE_NAME_Float)) {
617+
} else if (stripPrefix(text, BUILTIN_TYPE_NAME_FLOAT)) {
618618
Buffer << 'f' << text << '_';
619619
} else if (stripPrefix(text, BUILTIN_TYPE_NAME_VEC)) {
620620
auto split = text.split('x');

lib/IDE/TypeReconstruction.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,10 @@ static void VisitNodeBuiltinTypeName(
798798
std::string builtin_name = cur_node->getText();
799799

800800
StringRef builtin_name_ref(builtin_name);
801-
std::string builtin_type_prefix = stringWithFormat("%s.", BUILTIN_NAME);
802801

803-
if (builtin_name_ref.startswith(builtin_type_prefix)) {
802+
if (builtin_name_ref.startswith(BUILTIN_TYPE_NAME_PREFIX)) {
804803
StringRef stripped_name_ref =
805-
builtin_name_ref.drop_front(strlen(builtin_type_prefix.c_str()));
804+
builtin_name_ref.drop_front(strlen(BUILTIN_TYPE_NAME_PREFIX));
806805
SmallVector<ValueDecl *, 1> builtin_decls;
807806

808807
result._module =
@@ -815,7 +814,7 @@ static void VisitNodeBuiltinTypeName(
815814
}
816815
} else {
817816
result._error = stringWithFormat(
818-
"BuiltinTypeName %s doesn't start with %s", builtin_name.c_str(), builtin_type_prefix.c_str());
817+
"BuiltinTypeName %s doesn't start with %s", builtin_name.c_str(), BUILTIN_TYPE_NAME_PREFIX);
819818
}
820819
}
821820

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,9 +3552,7 @@ static TypeAliasDecl *findTypeAliasForBuiltin(ASTContext &Ctx, Type T) {
35523552
llvm::SmallString<32> FullName;
35533553
llvm::raw_svector_ostream OS(FullName);
35543554
T->print(OS);
3555-
std::string builtin_name = BUILTIN_NAME;
3556-
std::string builtin_type_prefix = builtin_name + ".";
3557-
assert(FullName.startswith(builtin_type_prefix));
3555+
assert(FullName.startswith(BUILTIN_TYPE_NAME_PREFIX));
35583556
StringRef TypeName = FullName.substr(8);
35593557

35603558
SmallVector<ValueDecl*, 4> CurModuleResults;

0 commit comments

Comments
 (0)