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
|
//===--- ManglingUtils.cpp - Utilities for Swift name mangling ------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/Demangling/ManglingUtils.h"
#include <optional>
using namespace swift;
using namespace Mangle;
bool Mangle::isNonAscii(StringRef str) {
for (unsigned char c : str) {
if (c >= 0x80)
return true;
}
return false;
}
bool Mangle::needsPunycodeEncoding(StringRef str) {
for (unsigned char c : str) {
if (!isValidSymbolChar(c))
return true;
}
return false;
}
/// Translate the given operator character into its mangled form.
///
/// Current operator characters: @/=-+*%<>!&|^~ and the special operator '..'
char Mangle::translateOperatorChar(char op) {
switch (op) {
case '&': return 'a'; // 'and'
case '@': return 'c'; // 'commercial at sign'
case '/': return 'd'; // 'divide'
case '=': return 'e'; // 'equal'
case '>': return 'g'; // 'greater'
case '<': return 'l'; // 'less'
case '*': return 'm'; // 'multiply'
case '!': return 'n'; // 'negate'
case '|': return 'o'; // 'or'
case '+': return 'p'; // 'plus'
case '?': return 'q'; // 'question'
case '%': return 'r'; // 'remainder'
case '-': return 's'; // 'subtract'
case '~': return 't'; // 'tilde'
case '^': return 'x'; // 'xor'
case '.': return 'z'; // 'zperiod' (the z is silent)
default:
return op;
}
}
std::string Mangle::translateOperator(StringRef Op) {
std::string Encoded;
for (char ch : Op) {
Encoded.push_back(translateOperatorChar(ch));
}
return Encoded;
}
std::optional<StringRef>
Mangle::getStandardTypeSubst(StringRef TypeName,
bool allowConcurrencyManglings) {
#define STANDARD_TYPE(KIND, MANGLING, TYPENAME) \
if (TypeName == #TYPENAME) { \
return StringRef(#MANGLING); \
}
#define STANDARD_TYPE_CONCURRENCY(KIND, MANGLING, TYPENAME) \
if (allowConcurrencyManglings && TypeName == #TYPENAME) { \
return StringRef("c" #MANGLING); \
}
#include "swift/Demangling/StandardTypesMangling.def"
return std::nullopt;
}
|