Skip to content

Commit 5d7f771

Browse files
committed
C++: Split off stl.h from stl.cpp.
1 parent 7349333 commit 5d7f771

File tree

2 files changed

+241
-115
lines changed

2 files changed

+241
-115
lines changed

cpp/ql/test/library-tests/dataflow/taint-tests/stl.cpp

Lines changed: 115 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,103 @@
11

2-
typedef unsigned long size_t;
2+
#include "stl.h"
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+
3100

4-
namespace std
5-
{
6-
template<class charT> struct char_traits;
7-
8-
typedef size_t streamsize;
9-
10-
struct ptrdiff_t;
11-
12-
template <class iterator_category,
13-
class value_type,
14-
class difference_type = ptrdiff_t,
15-
class pointer_type = value_type*,
16-
class reference_type = value_type&>
17-
struct iterator {
18-
iterator &operator++();
19-
iterator operator++(int);
20-
bool operator==(iterator other) const;
21-
bool operator!=(iterator other) const;
22-
reference_type operator*() const;
23-
};
24-
25-
struct input_iterator_tag {};
26-
struct forward_iterator_tag : public input_iterator_tag {};
27-
struct bidirectional_iterator_tag : public forward_iterator_tag {};
28-
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
29-
30-
template <class T> class allocator {
31-
public:
32-
allocator() throw();
33-
typedef size_t size_type;
34-
};
35-
36-
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
37-
class basic_string {
38-
public:
39-
typedef typename Allocator::size_type size_type;
40-
41-
explicit basic_string(const Allocator& a = Allocator());
42-
basic_string(const charT* s, const Allocator& a = Allocator());
43-
44-
const charT* c_str() const;
45-
46-
typedef std::iterator<random_access_iterator_tag, charT> iterator;
47-
typedef std::iterator<random_access_iterator_tag, const charT> const_iterator;
48-
49-
iterator begin();
50-
iterator end();
51-
const_iterator begin() const;
52-
const_iterator end() const;
53-
const_iterator cbegin() const;
54-
const_iterator cend() const;
55-
56-
template<class T> basic_string& operator+=(const T& t);
57-
basic_string& operator+=(const charT* s);
58-
basic_string& append(const basic_string& str);
59-
basic_string& append(const charT* s);
60-
basic_string& append(size_type n, charT c);
61-
};
62-
63-
template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
64-
template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
65-
66-
typedef basic_string<char> string;
67-
68-
template <class charT, class traits = char_traits<charT> >
69-
class basic_istream /*: virtual public basic_ios<charT,traits> - not needed for this test */ {
70-
public:
71-
basic_istream<charT,traits>& operator>>(int& n);
72-
};
73-
74-
template <class charT, class traits = char_traits<charT> >
75-
class basic_ostream /*: virtual public basic_ios<charT,traits> - not needed for this test */ {
76-
public:
77-
typedef charT char_type;
78-
basic_ostream<charT,traits>& write(const char_type* s, streamsize n);
79-
80-
basic_ostream<charT, traits>& operator<<(int n);
81-
};
82-
83-
template<class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
84-
template<class charT, class traits, class Allocator> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
85-
86-
template<class charT, class traits = char_traits<charT>>
87-
class basic_iostream : public basic_istream<charT, traits>, public basic_ostream<charT, traits> {
88-
public:
89-
};
90-
91-
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
92-
class basic_stringstream : public basic_iostream<charT, traits> {
93-
public:
94-
explicit basic_stringstream(/*ios_base::openmode which = ios_base::out|ios_base::in - not needed for this test*/);
95-
96-
basic_string<charT, traits, Allocator> str() const;
97-
};
98-
99-
using stringstream = basic_stringstream<char>;
100-
}
101101

102102
char *source();
103103
void sink(const char *s) {};
@@ -273,27 +273,27 @@ void test_range_based_for_loop_string() {
273273

274274

275275

276-
namespace std {
277-
template <class T>
278-
class vector {
279-
private:
280-
void *data_;
281-
public:
282-
vector(int size);
283276

284-
T& operator[](int idx);
285-
const T& operator[](int idx) const;
286277

287-
typedef std::iterator<random_access_iterator_tag, T> iterator;
288-
typedef std::iterator<random_access_iterator_tag, const T> const_iterator;
289278

290-
iterator begin() noexcept;
291-
iterator end() noexcept;
292279

293-
const_iterator begin() const noexcept;
294-
const_iterator end() const noexcept;
295-
};
296-
}
280+
281+
282+
283+
284+
285+
286+
287+
288+
289+
290+
291+
292+
293+
294+
295+
296+
297297

298298
void sink(int);
299299

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
2+
typedef unsigned long size_t;
3+
4+
// --- string ---
5+
6+
namespace std
7+
{
8+
template<class charT> struct char_traits;
9+
10+
typedef size_t streamsize;
11+
12+
struct ptrdiff_t;
13+
14+
template <class iterator_category,
15+
class value_type,
16+
class difference_type = ptrdiff_t,
17+
class pointer_type = value_type*,
18+
class reference_type = value_type&>
19+
struct iterator {
20+
iterator &operator++();
21+
iterator operator++(int);
22+
bool operator==(iterator other) const;
23+
bool operator!=(iterator other) const;
24+
reference_type operator*() const;
25+
};
26+
27+
struct input_iterator_tag {};
28+
struct forward_iterator_tag : public input_iterator_tag {};
29+
struct bidirectional_iterator_tag : public forward_iterator_tag {};
30+
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
31+
32+
template <class T> class allocator {
33+
public:
34+
allocator() throw();
35+
typedef size_t size_type;
36+
};
37+
38+
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
39+
class basic_string {
40+
public:
41+
typedef typename Allocator::size_type size_type;
42+
43+
explicit basic_string(const Allocator& a = Allocator());
44+
basic_string(const charT* s, const Allocator& a = Allocator());
45+
46+
const charT* c_str() const;
47+
48+
typedef std::iterator<random_access_iterator_tag, charT> iterator;
49+
typedef std::iterator<random_access_iterator_tag, const charT> const_iterator;
50+
51+
iterator begin();
52+
iterator end();
53+
const_iterator begin() const;
54+
const_iterator end() const;
55+
const_iterator cbegin() const;
56+
const_iterator cend() const;
57+
58+
template<class T> basic_string& operator+=(const T& t);
59+
basic_string& operator+=(const charT* s);
60+
basic_string& append(const basic_string& str);
61+
basic_string& append(const charT* s);
62+
basic_string& append(size_type n, charT c);
63+
};
64+
65+
template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
66+
template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
67+
68+
typedef basic_string<char> string;
69+
70+
template <class charT, class traits = char_traits<charT> >
71+
class basic_istream /*: virtual public basic_ios<charT,traits> - not needed for this test */ {
72+
public:
73+
basic_istream<charT,traits>& operator>>(int& n);
74+
};
75+
76+
template <class charT, class traits = char_traits<charT> >
77+
class basic_ostream /*: virtual public basic_ios<charT,traits> - not needed for this test */ {
78+
public:
79+
typedef charT char_type;
80+
basic_ostream<charT,traits>& write(const char_type* s, streamsize n);
81+
82+
basic_ostream<charT, traits>& operator<<(int n);
83+
};
84+
85+
template<class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
86+
template<class charT, class traits, class Allocator> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
87+
88+
template<class charT, class traits = char_traits<charT>>
89+
class basic_iostream : public basic_istream<charT, traits>, public basic_ostream<charT, traits> {
90+
public:
91+
};
92+
93+
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
94+
class basic_stringstream : public basic_iostream<charT, traits> {
95+
public:
96+
explicit basic_stringstream(/*ios_base::openmode which = ios_base::out|ios_base::in - not needed for this test*/);
97+
98+
basic_string<charT, traits, Allocator> str() const;
99+
};
100+
101+
using stringstream = basic_stringstream<char>;
102+
}
103+
104+
// --- vector ---
105+
106+
namespace std {
107+
template <class T>
108+
class vector {
109+
private:
110+
void *data_;
111+
public:
112+
vector(int size);
113+
114+
T& operator[](int idx);
115+
const T& operator[](int idx) const;
116+
117+
typedef std::iterator<random_access_iterator_tag, T> iterator;
118+
typedef std::iterator<random_access_iterator_tag, const T> const_iterator;
119+
120+
iterator begin() noexcept;
121+
iterator end() noexcept;
122+
123+
const_iterator begin() const noexcept;
124+
const_iterator end() const noexcept;
125+
};
126+
}

0 commit comments

Comments
 (0)