mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When ClangImporter::Implementation::inferDefaultArgument processes func/method arguments as part of omitNeedlessWordsInFunctionName it processes information about how the typenames for the parameters related to the parameter names to form a parameter names list. The parameter names list is used to determine if the argument label for a function should be clipped based on the typename. So for example a type like NSOrderedCollectionDifferenceCalculationOptions would cause a label ending with "Options" to get clipped so that for instance "withOptions" becomes simply "with". Unfortunately in the context of C++-Interop, the typename for the parameter often resolves to what the type backing the typedef or enum is and not the actual name of the typedef (so `typedef NSUInteger NSOrderedCollectionDifferenceCalculationOptions` resolves to a name of NSUInteger rather than NSOrderedCollectionDifferenceCalculationOptions). This patch seeks to collect a bit more information when processing NS_OPTIONS typedefs and providing that to the calling omitNeedlessWordsInFunctionName to handle more inteligently. In practice this fixes anywhere in Foundatio where `withOptions: NSOrderedCollectionDifferenceCalculationOptions` is used.
95 lines
2.8 KiB
C++
95 lines
2.8 KiB
C++
//===--- DefaultArgumentKind.h - Default Argument Kind Enum -----*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines the DefaultArgumentKind enumeration.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_DEFAULTARGUMENTKIND_H
|
|
#define SWIFT_DEFAULTARGUMENTKIND_H
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace llvm {
|
|
class StringRef;
|
|
}
|
|
|
|
namespace swift {
|
|
|
|
class Expr;
|
|
|
|
/// Describes the kind of default argument a tuple pattern element has.
|
|
enum class DefaultArgumentKind : uint8_t {
|
|
/// No default argument.
|
|
None,
|
|
/// A normal default argument.
|
|
Normal,
|
|
/// The default argument is inherited from the corresponding argument of the
|
|
/// overridden declaration.
|
|
Inherited,
|
|
/// The "nil" literal.
|
|
NilLiteral,
|
|
/// An empty array literal.
|
|
EmptyArray,
|
|
/// An empty dictionary literal.
|
|
EmptyDictionary,
|
|
/// A reference to the stored property. This is a special default argument
|
|
/// kind for the synthesized memberwise constructor to emit a call to the
|
|
/// property's initializer.
|
|
StoredProperty,
|
|
// Magic identifier literals expanded at the call site:
|
|
#define MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) NAME,
|
|
#include "swift/AST/MagicIdentifierKinds.def"
|
|
};
|
|
enum { NumDefaultArgumentKindBits = 4 };
|
|
|
|
struct ArgumentAttrs {
|
|
DefaultArgumentKind argumentKind;
|
|
bool isUnavailableInSwift = false;
|
|
llvm::StringRef CXXOptionsEnumName = "";
|
|
|
|
ArgumentAttrs(DefaultArgumentKind argumentKind,
|
|
bool isUnavailableInSwift = false,
|
|
llvm::StringRef CXXOptionsEnumName = "")
|
|
: argumentKind(argumentKind), isUnavailableInSwift(isUnavailableInSwift),
|
|
CXXOptionsEnumName(CXXOptionsEnumName) {}
|
|
|
|
bool operator !=(const DefaultArgumentKind &rhs) const {
|
|
return argumentKind != rhs;
|
|
}
|
|
|
|
bool operator==(const DefaultArgumentKind &rhs) const {
|
|
return argumentKind == rhs;
|
|
}
|
|
|
|
bool hasDefaultArg() const {
|
|
return argumentKind != DefaultArgumentKind::None;
|
|
}
|
|
|
|
bool hasAlternateCXXOptionsEnumName() const {
|
|
return !CXXOptionsEnumName.empty() && isUnavailableInSwift;
|
|
}
|
|
|
|
llvm::StringRef getAlternateCXXOptionsEnumName() const {
|
|
assert(hasAlternateCXXOptionsEnumName() &&
|
|
"Expected a C++ Options type for C++-Interop but found none.");
|
|
return CXXOptionsEnumName;
|
|
}
|
|
};
|
|
|
|
} // end namespace swift
|
|
|
|
#endif // LLVM_SWIFT_DEFAULTARGUMENTKIND_H
|
|
|