Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

rdar://problem/26424095 Import as Member: QoI errors #15

Merged
merged 4 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ def StringCompare : DiagGroup<"string-compare">;
def StringPlusInt : DiagGroup<"string-plus-int">;
def StringPlusChar : DiagGroup<"string-plus-char">;
def StrncatSize : DiagGroup<"strncat-size">;

def SwiftNameAttribute : DiagGroup<"swift-name-attribute">;

def TautologicalOutOfRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;
def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
Expand Down
2 changes: 1 addition & 1 deletion include/clang/Basic/DiagnosticIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace clang {
DIAG_START_AST = DIAG_START_PARSE + 500,
DIAG_START_COMMENT = DIAG_START_AST + 110,
DIAG_START_SEMA = DIAG_START_COMMENT + 100,
DIAG_START_ANALYSIS = DIAG_START_SEMA + 3000,
DIAG_START_ANALYSIS = DIAG_START_SEMA + 4000,
DIAG_UPPER_LIMIT = DIAG_START_ANALYSIS + 100
};

Expand Down
56 changes: 49 additions & 7 deletions include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -3009,15 +3009,57 @@ def err_objc_attr_protocol_requires_definition : Error<
"attribute %0 can only be applied to @protocol definitions, not forward declarations">;

// Swift attributes
def err_attr_swift_name_decl_kind : Error<
"%0 attribute cannot be applied to this declaration">;
def err_attr_swift_name_identifier : Error<
"parameter of %0 attribute must be an ASCII identifier string">;
def err_attr_swift_name_function : Error<
"parameter of %0 attribute must be a Swift function name string">;
def warn_attr_swift_name_decl_kind : Warning<
"%0 attribute cannot be applied to this declaration">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_function : Warning<
"parameter of %0 attribute must be a Swift function name string">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_function_no_prototype : Warning<
"%0 attribute can only be applied to function declarations with prototypes">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_context_name_invalid_identifier : Warning<
"%0 attribute has invalid identifier for context name">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_basename_invalid_identifier : Warning<
"%0 attribute has invalid identifier for base name">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_parameter_invalid_identifier : Warning<
"%0 attribute has invalid identifier for parameter name">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_missing_parameters : Warning<
"%0 attribute is missing parameter label clause">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_subscript_not_accessor : Warning<
"%0 attribute for 'subscript' must be a getter or setter">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_subscript_no_parameter : Warning<
"%0 attribute for 'subscript' must take at least one parameter">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_subscript_getter_newValue : Warning<
"%0 attribute for 'subscript' getter cannot take a 'newValue:' parameter">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_subscript_setter_no_newValue : Warning<
"%0 attribute for 'subscript' setter must take a 'newValue:' parameter">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_subscript_setter_multiple_newValues : Warning<
"%0 attribute for 'subscript' setter cannot take multiple 'newValue:' parameters">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_getter_parameters : Warning<
"%0 attribute for getter must not take any parameters besides 'self:'">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_setter_parameters : Warning<
"%0 attribute for setter must take one parameter for new value">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_multiple_selfs : Warning<
"%0 attribute cannot specify more than one 'self:' parameter">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_static_subscript : Warning<
"%0 attribute for 'subscript' must take a 'self:' parameter">,
InGroup<SwiftNameAttribute>;
def warn_attr_swift_name_num_params : Warning<
"too %select{few|many}0 parameters in %1 attribute (expected %2; got %3)">,
InGroup<DiagGroup<"swift-name-attribute">>;
InGroup<SwiftNameAttribute>;
def err_attr_swift_error_no_error_parameter : Error<
"%0 attribute can only be applied to a %select{function|method}1 "
"with an error parameter">;
Expand Down
18 changes: 18 additions & 0 deletions include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,24 @@ class Sema {
}
};

/// Do a check to make sure \p Name looks like a legal swift_name
/// attribute for the decl \p D. Raise a diagnostic if the name is invalid
/// for the given declaration.
///
/// For a function, this will validate a compound Swift name,
/// e.g. <code>init(foo:bar:baz:)</code> or <code>controllerForName(_:)</code>,
/// and the function will output the number of parameter names, and whether
/// this is a single-arg initializer.
///
/// For a type, enum constant, property, or variable declaration, this will
/// validate either a simple identifier, or a qualified
/// <code>context.identifier</code> name.
///
/// \returns true if the name is a valid swift name for \p D, false otherwise.
bool DiagnoseSwiftName(Decl *D, StringRef Name,
SourceLocation ArgLoc,
IdentifierInfo *AttrName);

private:
bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
TypeDiagnoser *Diagnoser);
Expand Down
11 changes: 8 additions & 3 deletions lib/Sema/SemaAPINotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void ProcessAPINotes(Sema &S, Decl *D,

if (Info.UnavailableInSwift) {
D->addAttr(AvailabilityAttr::CreateImplicit(
S.Context,
S.Context,
&S.Context.Idents.get("swift"),
VersionTuple(),
VersionTuple(),
Expand All @@ -129,9 +129,14 @@ static void ProcessAPINotes(Sema &S, Decl *D,

// swift_name
if (!Info.SwiftName.empty() && !D->hasAttr<SwiftNameAttr>()) {
auto &APINoteName = S.getASTContext().Idents.get("SwiftName API Note");

if (!S.DiagnoseSwiftName(D, Info.SwiftName, D->getLocation(),
&APINoteName)) {
return;
}
D->addAttr(SwiftNameAttr::CreateImplicit(S.Context,
CopyString(S.Context,
Info.SwiftName)));
CopyString(S.Context, Info.SwiftName)));
}
}

Expand Down
Loading