File: NumericDiagnostics.swift.gyb

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (63 lines) | stat: -rw-r--r-- 2,868 bytes parent folder | download
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
// RUN: %empty-directory(%t)
// RUN: %gyb %s -o %t/main.swift
// RUN: %line-directive %t/main.swift -- %target-build-swift -typecheck -Xfrontend -verify %t/main.swift
// REQUIRES: executable_test
// FIXME(integers): this test needs serious refactoring as there is now a lot
// more variation in the diagnostics. <rdar://problem/31635173>
// XFAIL: *

% from SwiftIntTypes import all_numeric_type_names, numeric_type_names_macintosh_only, \
%   all_integer_type_names, all_integer_binary_operator_names, all_integer_or_real_binary_operator_names, \
%   all_integer_assignment_operator_names, \
%   all_integer_or_real_assignment_operator_names

% int_ops = all_integer_binary_operator_names() + all_integer_assignment_operator_names()
% arith_ops = all_integer_or_real_binary_operator_names() + \
%   all_integer_or_real_assignment_operator_names()

% count = 0
// TODO: Verify the type of the result

func testIteratedOperations() {
% for typesToTest, operatorsToTest in zip([all_integer_type_names(), all_numeric_type_names()],
%  [int_ops, arith_ops]):
  %# TODO: rm when rdar://18695154 is fixed.
// typesToTest: ${typesToTest}, operatorsToTest: ${operatorsToTest}
  % for T1 in typesToTest:
    % for T2 in typesToTest:
      ${ "\n\n#if arch(i386) || arch(x86_64)\n" if T1 in numeric_type_names_macintosh_only()
        or T2 in numeric_type_names_macintosh_only() else "" }
      % for op in operatorsToTest:
        % count += 1
        % theDiagnostic = ""
        % all_assignment_operators = (all_integer_assignment_operator_names() + all_integer_or_real_assignment_operator_names())
        % if T1 != T2:
        %   if op in [">>", "<<"]: # heterogeneous shifts are allowed
        %     theDiagnostic = ""
        %   elif op in [">>=", "<<="]:
        %     theDiagnostic = "// expected-note{{add an explicit type annotation}}  expected-warning{{inferred to have type}}"
        %   elif op not in ["&+", "&-", "&*"]:
        %     theDiagnostic = "// expected-error{{of type}} expected-note*{{expected an argument list of type}} expected-note*{{exist with these partially matching parameter lists}}"
        %   else:
        %     theDiagnostic = "// expected-error {{'Self' could not be inferred}}"
        %   end
        % else:
        %   if op in all_assignment_operators:
        %     theDiagnostic = "// expected-note{{add an explicit type annotation}}  expected-warning{{inferred to have type}}"
        %   else:
        %     pass
        %   end
        % end
    do { // ${count}
      var x1_${T1}: ${T1} = 0
      var x2_${T2}: ${T2} = 0
      var result = x1_${T1} ${op} x2_${T2}  ${theDiagnostic}
    }
      % end # for op
      ${ "\n#endif //arch(i386) || arch(x86_64)\n\n" if T1 in numeric_type_names_macintosh_only()
        or T2 in numeric_type_names_macintosh_only() else "" }
    %end # T2
  %end # T1
%end # typesToTest

}