mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Import as member] Lower case initialisms
This commit is contained in:
@@ -262,6 +262,16 @@ namespace swift {
|
||||
StringRef toLowercaseInitialisms(StringRef string,
|
||||
StringScratchSpace &scratch);
|
||||
|
||||
/// Lowercase the first word within the given camelCase string.
|
||||
///
|
||||
/// \param string The string to lowercase.
|
||||
/// \param scratch Scratch buffer used to form the resulting string.
|
||||
///
|
||||
/// \returns the string with the first word lowercased, including
|
||||
/// initialisms.
|
||||
StringRef toLowercaseInitialisms(StringRef string,
|
||||
SmallVectorImpl<char> &scratch);
|
||||
|
||||
/// Sentence-case the given camelCase string by turning the first
|
||||
/// letter into an uppercase letter.
|
||||
///
|
||||
|
||||
@@ -833,6 +833,17 @@ static StringRef omitNeedlessWords(StringRef name,
|
||||
|
||||
StringRef camel_case::toLowercaseInitialisms(StringRef string,
|
||||
StringScratchSpace &scratch) {
|
||||
llvm::SmallString<32> scratchStr;
|
||||
StringRef result = toLowercaseInitialisms(string, scratchStr);
|
||||
if (string == result)
|
||||
return string;
|
||||
return scratch.copyString(result);
|
||||
}
|
||||
|
||||
StringRef
|
||||
camel_case::toLowercaseInitialisms(StringRef string,
|
||||
SmallVectorImpl<char> &scratch) {
|
||||
|
||||
if (string.empty())
|
||||
return string;
|
||||
|
||||
@@ -863,7 +874,8 @@ StringRef camel_case::toLowercaseInitialisms(StringRef string,
|
||||
scratchStr.push_back(clang::toLowercase(string[i]));
|
||||
}
|
||||
|
||||
return scratch.copyString(scratchStr);
|
||||
scratch = scratchStr;
|
||||
return scratchStr;
|
||||
}
|
||||
|
||||
/// Determine whether the given word occurring before the given
|
||||
|
||||
@@ -125,7 +125,7 @@ StringRef skipLeadingUnderscores(StringRef str) {
|
||||
// Form a humble camel name from a string. Skips leading underscores.
|
||||
static void formHumbleCamelName(StringRef str, NameBuffer &out) {
|
||||
str = skipLeadingUnderscores(str);
|
||||
auto newStr = camel_case::toLowercaseWord(str, out);
|
||||
auto newStr = camel_case::toLowercaseInitialisms(str, out);
|
||||
if (newStr == str)
|
||||
out = newStr;
|
||||
}
|
||||
@@ -336,7 +336,8 @@ private:
|
||||
Identifier getHumbleIdentifier(StringRef name) {
|
||||
// Lower-camel-case the incoming name
|
||||
NameBuffer buf;
|
||||
return {context.getIdentifier(camel_case::toLowercaseWord(name, buf))};
|
||||
formHumbleCamelName(name, buf);
|
||||
return {context.getIdentifier(buf)};
|
||||
}
|
||||
|
||||
DeclName formDeclName(StringRef baseName) {
|
||||
|
||||
@@ -18,7 +18,7 @@ extern void IAMStruct1InvertInPlace(struct IAMStruct1 *s);
|
||||
extern struct IAMStruct1 IAMStruct1Rotate(const struct IAMStruct1 *s,
|
||||
double radians);
|
||||
extern void IAMStruct1SelfComesLast(double x, struct IAMStruct1 s);
|
||||
extern void IAMStruct1SelfComesThird(int a, float b, struct IAMStruct1 s,
|
||||
extern void IAMStruct1SelfComesThird(double a, float b, struct IAMStruct1 s,
|
||||
double x);
|
||||
|
||||
/// Properties
|
||||
@@ -31,7 +31,7 @@ extern void IAMStruct1SetLength(double len, struct IAMStruct1 *s);
|
||||
extern double IAMStruct1GetLength(struct IAMStruct1 s);
|
||||
|
||||
|
||||
/// Various functions that can't quite be imported as properties.
|
||||
/// Various instance functions that can't quite be imported as properties.
|
||||
|
||||
// Too many parameters in the setter
|
||||
extern float IAMStruct1GetNonPropertyNumParams(struct IAMStruct1 s);
|
||||
@@ -49,11 +49,12 @@ extern void IAMStruct1SetNonPropertyNoSelf(double x, double y);
|
||||
// No set only properties
|
||||
extern void IAMStruct1SetNonPropertyNoGet(struct IAMStruct1 s, double x);
|
||||
|
||||
// Static versions
|
||||
// Too many parameters in the setter
|
||||
/// Various static functions that can't quite be imported as properties.
|
||||
// Too many parameters
|
||||
extern float IAMStruct1StaticGetNonPropertyNumParams();
|
||||
extern void IAMStruct1StaticSetNonPropertyNumParams(float a,
|
||||
float b);
|
||||
extern void IAMStruct1StaticGetNonPropertyNumParamsGetter(double d);
|
||||
|
||||
// Set type doesn't match get type
|
||||
extern float IAMStruct1StaticGetNonPropertyType();
|
||||
@@ -66,23 +67,29 @@ extern void IAMStruct1StaticSetNonPropertyNoSelf(double x, double y);
|
||||
// No set only properties
|
||||
extern void IAMStruct1StaticSetNonPropertyNoGet(double x);
|
||||
|
||||
|
||||
/// Static method
|
||||
extern int IAMStruct1StaticMethod();
|
||||
extern double IAMStruct1StaticMethod();
|
||||
extern double IAMStruct1TLAThreeLetterAcronym();
|
||||
|
||||
/// Static computed properties
|
||||
extern int IAMStruct1StaticGetProperty();
|
||||
extern int IAMStruct1StaticSetProperty(int i);
|
||||
extern int IAMStruct1StaticGetOnlyProperty();
|
||||
extern double IAMStruct1StaticGetProperty();
|
||||
extern double IAMStruct1StaticSetProperty(double);
|
||||
extern double IAMStruct1StaticGetOnlyProperty();
|
||||
|
||||
// FIXME: when no parameters, make a () and attach a parameter name
|
||||
/// Fuzzy
|
||||
extern struct IAMStruct1 IAMFuzzyStruct1Create();
|
||||
extern struct IAMStruct1 IAMFuzzyStruct1CreateWithFuzzyName();
|
||||
extern struct IAMStruct1 IAMFuzzyStruct1CreateFuzzyName();
|
||||
|
||||
// typedef __attribute__((objc_bridge(id))) void *IAMClassRef;
|
||||
struct IAMClass {
|
||||
int x, y, z;
|
||||
float x, y, z;
|
||||
};
|
||||
typedef struct IAMClass *IAMClassRef;
|
||||
|
||||
extern unsigned IAMClassGetTypeID();
|
||||
|
||||
extern IAMClassRef IAMClassCreate(int i);
|
||||
extern IAMClassRef IAMClassCreate(double i);
|
||||
|
||||
#endif // INFER_IMPORT_AS_MEMBER_H
|
||||
|
||||
@@ -28,7 +28,7 @@ import InferImportAsMember
|
||||
// PRINT-NEXT: mutating func invertInPlace()
|
||||
// PRINT-NEXT: func rotate(radians radians: Double) -> IAMStruct1
|
||||
// PRINT-NEXT: func selfComesLast(x x: Double)
|
||||
// PRINT-NEXT: func selfComesThird(a a: Int32, b b: Float, x x: Double)
|
||||
// PRINT-NEXT: func selfComesThird(a a: Double, b b: Float, x x: Double)
|
||||
//
|
||||
// PRINT-LABEL: /// Properties
|
||||
// PRINT-NEXT: var radius: Double { get nonmutating set }
|
||||
@@ -36,7 +36,7 @@ import InferImportAsMember
|
||||
// PRINT-NEXT: var magnitude: Double { get }
|
||||
// PRINT-NEXT: var length: Double
|
||||
//
|
||||
// PRINT-LABEL: /// Various functions that can't quite be imported as properties.
|
||||
// PRINT-LABEL: /// Various instance functions that can't quite be imported as properties.
|
||||
// PRINT-NEXT: func getNonPropertyNumParams() -> Float
|
||||
// PRINT-NEXT: func setNonPropertyNumParams(a a: Float, b b: Float)
|
||||
// PRINT-NEXT: func getNonPropertyType() -> Float
|
||||
@@ -44,6 +44,8 @@ import InferImportAsMember
|
||||
// PRINT-NEXT: func getNonPropertyNoSelf() -> Float
|
||||
// PRINT-NEXT: static func setNonPropertyNoSelf(x x: Double, y y: Double)
|
||||
// PRINT-NEXT: func setNonPropertyNoGet(x x: Double)
|
||||
//
|
||||
// PRINT-LABEL: /// Various static functions that can't quite be imported as properties.
|
||||
// PRINT-NEXT: static func staticGetNonPropertyNumParams() -> Float
|
||||
// PRINT-NEXT: static func staticSetNonPropertyNumParams(a a: Float, b b: Float)
|
||||
// PRINT-NEXT: static func staticGetNonPropertyType() -> Float
|
||||
@@ -51,14 +53,21 @@ import InferImportAsMember
|
||||
// PRINT-NEXT: static func staticGetNonPropertyNoSelf() -> Float
|
||||
// PRINT-NEXT: static func staticSetNonPropertyNoSelf(x x: Double, y y: Double)
|
||||
// PRINT-NEXT: static func staticSetNonPropertyNoGet(x x: Double)
|
||||
//
|
||||
|
||||
|
||||
|
||||
// PRINT-LABEL: /// Static method
|
||||
// PRINT-NEXT: static func staticMethod() -> Int32
|
||||
// PRINT-NEXT: static func staticMethod() -> Double
|
||||
// PRINT-NEXT: static func tlaThreeLetterAcronym() -> Double
|
||||
//
|
||||
// PRINT-LABEL: /// Static computed properties
|
||||
// PRINT-NEXT: static var staticProperty: Int32
|
||||
// PRINT-NEXT: static var staticOnlyProperty: Int32 { get }
|
||||
// PRINT-NEXT: }
|
||||
// PRINT-NEXT: static var staticProperty: Double
|
||||
// PRINT-NEXT: static var staticOnlyProperty: Double { get }
|
||||
|
||||
// PRINT-LABEL: /// Fuzzy
|
||||
// FIXME: fuzzies
|
||||
|
||||
// PRINT: }
|
||||
|
||||
// FIXME: get the class working
|
||||
|
||||
|
||||
Reference in New Issue
Block a user