//===- DiagnosticsSILAnalysis.def - Diagnostics Text ------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
//  This file defines diagnostics emitted during SIL (dataflow) analysis.
//  Each diagnostic is described using one of three kinds (error, warning, or 
//  note) along with a unique identifier, category, options, and text, and is
//  followed by a signature describing the diagnostic argument kinds.
//
//===----------------------------------------------------------------------===//

#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE)))
#  error Must define either DIAG or the set {ERROR,WARNING,NOTE}
#endif

#ifndef ERROR
#  define ERROR(ID,Category,Options,Text,Signature)   \
  DIAG(ERROR,ID,Category,Options,Text,Signature)
#endif

#ifndef WARNING
#  define WARNING(ID,Category,Options,Text,Signature) \
  DIAG(WARNING,ID,Category,Options,Text,Signature)
#endif

#ifndef NOTE
#  define NOTE(ID,Category,Options,Text,Signature) \
  DIAG(NOTE,ID,Category,Options,Text,Signature)
#endif


// SILGen issues.
ERROR(bridging_module_missing,sil_gen,none,
      "unable to find module '%0' for implicit conversion function '%0.%1'",
      (StringRef, StringRef))
ERROR(bridging_function_missing,sil_gen,none,
      "unable to find implicit conversion function '%0.%1'",
      (StringRef, StringRef))
ERROR(bridging_function_overloaded,sil_gen,none,
      "multiple definitions of implicit conversion function '%0.%1'",
      (StringRef, StringRef))
ERROR(bridging_function_not_function,sil_gen,none,
      "definition of implicit conversion function '%0.%1' is not a function",
      (StringRef, StringRef))
ERROR(bridging_function_not_correct_type,sil_gen,none,
      "definition of implicit conversion function '%0.%1' is not of the correct"
      " type",
      (StringRef, StringRef))
ERROR(invalid_sil_builtin,sil_gen,none,
      "INTERNAL ERROR: invalid use of builtin: %0",
      (StringRef))
ERROR(could_not_find_bridge_type,sil_gen,none,
      "could not find Objective-C bridge type for type %0; "
      "did you forget to import Foundation?", (Type))
ERROR(could_not_find_pointer_memory_property,sil_gen,none,
      "could not find 'memory' property of pointer type %0", (Type))

ERROR(writeback_overlap_property,sil_gen,none,
      "inout writeback to computed property %0 occurs in multiple arguments to"
      " call, introducing invalid aliasing", (Identifier))
ERROR(writeback_overlap_subscript,sil_gen,none,
      "inout writeback through subscript occurs in multiple arguments to call,"
      " introducing invalid aliasing",
      ())
NOTE(writebackoverlap_note,sil_gen,none,
      "concurrent writeback occurred here", ())

ERROR(inout_argument_alias,sil_gen,none,
      "inout arguments are not allowed to alias each other", ())
NOTE(previous_inout_alias,sil_gen,none,
      "previous aliasing argument", ())

ERROR(unsupported_recursive_type,sil_gen,none,
      "recursive value type %0 is not allowed", (Type))

ERROR(recursive_enum_not_indirect,sil_gen,none,
      "recursive enum %0 is not marked 'indirect'", (Type))

ERROR(unsupported_c_function_pointer_conversion,sil_gen,none,
      "C function pointer signature %0 is not compatible with expected type %1",
      (Type, Type))

// Definite initialization diagnostics.
NOTE(variable_defined_here,sil_analysis,none,
     "%select{variable|constant}0 defined here", (bool))
ERROR(variable_used_before_initialized,sil_analysis,none,
      "%select{variable|constant}1 '%0' used before being initialized",
      (StringRef, bool))
ERROR(variable_inout_before_initialized,sil_analysis,none,
      "%select{variable|constant}1 '%0' passed by reference before being"
      " initialized", (StringRef, bool))
ERROR(variable_escape_before_initialized,sil_analysis,none,
      "%select{variable|constant}1 '%0' captured by a closure before being"
      " initialized", (StringRef, bool))

ERROR(variable_addrtaken_before_initialized,sil_analysis,none,
      "address of %select{variable|constant}1 '%0' taken before it is"
      " initialized", (StringRef, bool))
ERROR(ivar_not_initialized_at_superinit,sil_analysis,none,
      "property '%0' not initialized at super.init call", (StringRef, bool))
ERROR(ivar_not_initialized_at_implicit_superinit,sil_analysis,none,
      "property '%0' not initialized at implicitly generated super.init call",
      (StringRef, bool))

ERROR(self_use_before_fully_init,sil_analysis,none,
      "use of 'self' in %select{method call|property access}1 %0 before "
      "%select{all stored properties are initialized|"
      "super.init initializes self|"
      "self.init initializes self}2", (Identifier, bool, unsigned))
ERROR(use_of_self_before_fully_init,sil_analysis,none,
      "'self' used before all stored properties are initialized", ())
ERROR(use_of_self_before_fully_init_protocol,sil_analysis,none,
      "'self' used before chaining to another self.init requirement", ())


NOTE(stored_property_not_initialized,sil_analysis,none,
     "'%0' not initialized", (StringRef))

ERROR(selfinit_multiple_times,sil_analysis,none,
      "%select{super|self}0.init called multiple times in initializer",
      (unsigned))
ERROR(superselfinit_not_called_before_return,sil_analysis,none,
      "%select{super|self}0.init isn't called on all paths before returning "
      "from initializer", (unsigned))
ERROR(self_before_superselfinit,sil_analysis,none,
      "'self' used before %select{super|self}0.init call",
      (unsigned))
ERROR(self_inside_catch_superselfinit,sil_analysis,none,
      "'self' used inside 'catch' block reachable from "
      "%select{super|self}0.init call",
      (unsigned))
ERROR(return_from_init_without_initing_self,sil_analysis,none,
      "return from enum initializer method without storing to 'self'", ())
ERROR(return_from_protocol_init_without_initing_self,sil_analysis,none,
      "protocol extension initializer never chained to 'self.init'", ())
ERROR(return_from_init_without_initing_stored_properties,sil_analysis,none,
      "return from initializer without initializing all"
      " stored properties", ())

ERROR(global_variable_function_use_uninit,sil_analysis,none,
      "%select{variable|constant}1 '%0' used by function definition before"
      " being initialized",
      (StringRef, bool))
ERROR(struct_not_fully_initialized,sil_analysis,none,
      "struct '%0' must be completely initialized before a member is stored to",
      (StringRef, bool))
ERROR(immutable_property_already_initialized,sil_analysis,none,
      "immutable value '%0' may only be initialized once",
      (StringRef))
NOTE(initial_value_provided_in_let_decl,sil_analysis,none,
     "initial value already provided in 'let' declaration", ())
ERROR(mutating_method_called_on_immutable_value,sil_analysis,none,
      "mutating %select{method|property access|subscript|operator}1 %0 may not"
      " be used on immutable value '%2'",
      (Identifier, unsigned, StringRef))
ERROR(immutable_value_passed_inout,sil_analysis,none,
      "immutable value '%0' may not be passed inout",
      (StringRef))
ERROR(assignment_to_immutable_value,sil_analysis,none,
      "immutable value '%0' may not be assigned to",
      (StringRef))


// Control flow diagnostics.
ERROR(missing_return,sil_analysis,none,
      "missing return in a %select{function|closure}1 expected to return %0",
      (Type, unsigned))
ERROR(return_from_noreturn,sil_analysis,none, 
      "return from a 'noreturn' function", ())
ERROR(non_exhaustive_switch,sil_analysis,none, 
      "switch must be exhaustive, consider adding a default clause", ())
ERROR(guard_body_must_not_fallthrough,sil_analysis,none,
      "'guard' body may not fall through, consider using 'return' or 'break'"
      " to exit the scope", ())
WARNING(unreachable_code,sil_analysis,none, "will never be executed", ())
NOTE(unreachable_code_branch,sil_analysis,none,
     "condition always evaluates to %select{false|true}0", (bool))
NOTE(call_to_noreturn_note,sil_analysis,none,
     "a call to a noreturn function", ())
WARNING(unreachable_code_after_stmt,sil_analysis,none,
        "code after '%select{return|break|continue|throw}0' will never "
        "be executed", (unsigned))
WARNING(unreachable_case,sil_analysis,none,
        "%select{case|default}0 will never be executed", (bool))
WARNING(switch_on_a_constant,sil_analysis,none,
        "switch condition evaluates to a constant", ())
NOTE(unreachable_code_note,sil_analysis,none, "will never be executed", ())

// 'transparent' diagnostics
ERROR(circular_transparent,sil_analysis,none,
      "inlining 'transparent' functions forms circular loop", ())
NOTE(note_while_inlining,sil_analysis,none,
     "while inlining here", ())

// Arithmetic diagnostics.
ERROR(integer_conversion_overflow,sil_analysis,none,
      "integer overflows when converted from %0 to %1",
      (Type, Type))
ERROR(integer_conversion_overflow_builtin_types,sil_analysis,none,
      "integer overflows when converted from %select{unsigned|signed}0 "
      "%1 to %select{unsigned|signed}2 %3",
      (bool, Type, bool, Type))
WARNING(integer_conversion_overflow_warn,sil_analysis,none,
      "integer overflows when converted from %0 to %1",
      (Type, Type))
ERROR(integer_conversion_sign_error,sil_analysis,none,
      "negative integer cannot be converted to unsigned type %0",
      (Type))
ERROR(negative_integer_literal_overflow_unsigned,sil_analysis,none,
      "negative integer '%1' overflows when stored into unsigned type %0",
      (Type, StringRef))

ERROR(integer_literal_overflow,sil_analysis,none,
      "integer literal '%1' overflows when stored into %0",
      (Type, StringRef))
ERROR(integer_literal_overflow_builtin_types,sil_analysis,none,
      "integer literal '%2' overflows when stored into "
      "%select{unsigned|signed}0 %1", (bool, Type, StringRef))
WARNING(integer_literal_overflow_warn,sil_analysis,none,
      "integer literal overflows when stored into %0",
      (Type))
ERROR(arithmetic_operation_overflow,sil_analysis,none,
      "arithmetic operation '%0 %1 %2' (on type %3) results in an overflow",
      (StringRef, StringRef, StringRef, Type))
ERROR(arithmetic_operation_overflow_generic_type,sil_analysis,none,
      "arithmetic operation '%0 %1 %2' (on %select{unsigned|signed}3 "
      "%4-bit integer type) results in an overflow",
      (StringRef, StringRef, StringRef, bool, unsigned))
ERROR(division_overflow,sil_analysis,none,
      "division '%0 %1 %2' results in an overflow",
      (StringRef, StringRef, StringRef))
ERROR(division_by_zero,sil_analysis,none, "division by zero", ())
ERROR(wrong_non_negative_assumption,sil_analysis,none,
      "assumed non-negative value '%0' is negative", (StringRef))
ERROR(shifting_all_significant_bits,sil_analysis,none,
      "shift amount is greater than or equal to type size in bits", ())

// FIXME: We won't need this as it will be replaced with user-generated strings.
// staticReport diagnostics.
ERROR(static_report_error, sil_analysis, none,
      "static report error", ())


#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
#  undef DIAG
# endif
# undef NOTE
# undef WARNING
# undef ERROR
#endif
