File: typo-correction-recursive.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (132 lines) | stat: -rw-r--r-- 2,651 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// RUN: %clang_cc1 -fsyntax-only -verify %s

// Check the following typo correction behavior:
// - multiple typos in a single member call chain are all diagnosed
// - no typos are diagnosed for multiple typos in an expression when not all
//   typos can be corrected

class DeepClass
{
public:
  void trigger() const;
};

class Y
{
public:
  const DeepClass& getX() const { return m_deepInstance; }
private:
  DeepClass m_deepInstance;
  int m_n;
};

class Z
{
public:
  const Y& getY0() const { return m_y0; }
  const Y& getActiveY() const { return m_y0; }

private:
  Y m_y0;
  Y m_y1;
};

Z z_obj;

void testMultipleCorrections()
{
  z_obj.getY2().  // expected-error {{no member named 'getY2' in 'Z'}}
      getM().
      triggee();
}

void testNoCorrections()
{
  z_obj.getY2().  // expected-error {{no member named 'getY2' in 'Z'}}
      getM().
      thisDoesntSeemToMakeSense();
}

struct C {};
struct D { int value; };
struct A {
  C get_me_a_C();
};
struct B {
  D get_me_a_D();
};
class Scope {
public:
  A make_an_A();
  B make_a_B();
};

Scope scope_obj;

int testDiscardedCorrections() {
  return scope_obj.make_an_E().  // expected-error {{no member named 'make_an_E' in 'Scope'}}
      get_me_a_Z().value;
}

class AmbiguousHelper {
public:
  int helpMe();
  int helpBe();
};
class Ambiguous {
public:
  int calculateA();
  int calculateB();

  AmbiguousHelper getHelp1();
  AmbiguousHelper getHelp2();
};

Ambiguous ambiguous_obj;

int testDirectAmbiguousCorrection() {
  return ambiguous_obj.calculateZ();  // expected-error {{no member named 'calculateZ' in 'Ambiguous'}}
}

int testRecursiveAmbiguousCorrection() {
  return ambiguous_obj.getHelp3().    // expected-error {{no member named 'getHelp3' in 'Ambiguous'}}
      helpCe();
}


class DeepAmbiguityHelper {
public:
  DeepAmbiguityHelper& help1();
  DeepAmbiguityHelper& help2();

  DeepAmbiguityHelper& methodA();
  DeepAmbiguityHelper& somethingMethodB();
  DeepAmbiguityHelper& functionC();
  DeepAmbiguityHelper& deepMethodD();
  DeepAmbiguityHelper& asDeepAsItGets();
};

DeepAmbiguityHelper deep_obj;

int testDeepAmbiguity() {
  deep_obj.
      methodB(). // expected-error {{no member named 'methodB' in 'DeepAmbiguityHelper'}}
      somethingMethodC().
      functionD().
      deepMethodD().
      help3().
      asDeepASItGet().
      functionE();
}

struct Dog {
  int age;
  int size;
};

int from_dog_years(int DogYears, int DogSize);
int get_dog_years() {
  struct Dog doggo;
  return from_dog_years(doggo.agee,   //expected-error{{no member named 'agee' in 'Dog'}}
                        doggo.sizee); //expected-error{{no member named 'sizee' in 'Dog'}}
}