This file is indexed.

/usr/include/hphp/compiler/json.h is in hhvm-dev 3.11.1+dfsg-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
   +----------------------------------------------------------------------+
   | HipHop for PHP                                                       |
   +----------------------------------------------------------------------+
   | Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com)     |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
*/

#ifndef incl_HPHP_JSON_H_
#define incl_HPHP_JSON_H_

#include <cassert>
#include <map>
#include <memory>
#include <ostream>
#include <set>
#include <vector>

#include "hphp/util/hash-map-typedefs.h"

namespace HPHP {

struct AnalysisResult;

namespace JSON {
///////////////////////////////////////////////////////////////////////////////

template <typename T> class _OutputStream;
template <typename T> class _MapStream;
template <typename T> class _ListStream;
template <typename T> class _ISerializable;

#define DEFINE_JSON_OUTPUT_TYPE(type) \
  struct type { \
    typedef _OutputStream<type>  OutputStream; \
    typedef _MapStream<type>     MapStream; \
    typedef _ListStream<type>    ListStream; \
    typedef _ISerializable<type> ISerializable; \
  }

DEFINE_JSON_OUTPUT_TYPE(CodeError);
DEFINE_JSON_OUTPUT_TYPE(DocTarget);

std::string Escape(const char *s);

template <typename T>
class _ISerializable {
public:
  virtual ~_ISerializable() {}

  /**
   * Generate JSON output of this data structure.
   */
  virtual void serialize(_OutputStream<T> &out) const = 0;
};

class Name {
public:
  explicit Name(const char *name) {
    assert(name && *name);
    m_name = name;
  }
  explicit Name(const std::string &name) {
    assert(!name.empty());
    m_name = name;
  }
  const std::string &getName() const { return m_name; }
private:
  std::string m_name;
};

// struct _Null {};
// _Null Null;
enum class Null {};

template <typename Type>
class _OutputStream {
public:
  _OutputStream(std::ostream &out,
                std::shared_ptr<AnalysisResult> ar) : m_out(out), m_ar(ar) {}

  _OutputStream &operator<< (unsigned int v) { m_out << v; return *this; }

  _OutputStream &operator<< (int v) { m_out << v; return *this; }

  _OutputStream &operator<< (bool v) {
    m_out << (v ? "true" : "false");
    return *this;
  }

  _OutputStream &operator<< (const char *v) {
    m_out << "\"" << Escape(v) << "\"";
    return *this;
  }

  _OutputStream &operator<< (const std::string &v) {
    m_out << "\"" << Escape(v.c_str()) << "\"";
    return *this;
  }

  _OutputStream &operator<< (const Name &n) {
    m_out << "\"" << n.getName() << "\":";
    return *this;
  }

  _OutputStream &operator<< (const Null &n) {
    m_out << "null";
    return *this;
  }

  _OutputStream &operator<< (const _ISerializable<Type> &v) {
    v.serialize(*this);
    return *this;
  }

  template<typename T>
  _OutputStream &operator<< (const std::shared_ptr<T> &v) {
    if (v) {
      *this << *v;
    } else {
      *this << Null();
    }
    return *this;
  }

  template<typename T>
  _OutputStream &operator<< (const std::vector<T> &v) {
    m_out << "[";
    for (unsigned int i = 0; i < v.size(); i++) {
      if (i > 0) m_out << ',';
      *this << v[i];
    }
    m_out << "]";
    return *this;
  }

  template<typename T>
  _OutputStream &operator<< (const std::set<T> &v) {
    m_out << "[";
    bool first = true;
    for (T el: v) {
      if (first) {
        first = false;
      } else {
        m_out << ',';
      }
      *this << el;
    }
    m_out << "]";
    return *this;
  }

  // TODO: std::map and __gnu_cxx::hash_map should share
  // the same function...

  template<typename K, typename T, typename C>
  _OutputStream &operator<< (const std::map<K, T, C> &v) {
    m_out << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
      if (iter != v.begin()) m_out << ',';
      *this << Name(iter->first);
      *this << iter->second;
    }
    m_out << "}\n";
    return *this;
  }

  template<typename K, typename T, typename H, typename E>
  _OutputStream &operator<< (const hphp_hash_map<K, T, H, E> &v) {
    m_out << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
      if (iter != v.begin()) m_out << ',';
      *this << Name(iter->first);
      *this << iter->second;
    }
    m_out << "}\n";
    return *this;
  }

  std::shared_ptr<AnalysisResult> analysisResult() const { return m_ar; }

private:
  std::ostream      &m_out;
  std::shared_ptr<AnalysisResult>  m_ar;

  std::ostream &raw() { return m_out;}

  friend class _MapStream<Type>;
  friend class _ListStream<Type>;
};

template <typename Type>
class _MapStream {
public:
  explicit _MapStream(_OutputStream<Type> &jout)
    : m_out(jout.raw()), m_jout(jout), m_first(true) {}

  template<typename T>
  _MapStream &add(const std::string &n, T v) {
    init(n);
    m_jout << v;
    return *this;
  }

  _MapStream &add(const std::string &n) {
    init(n);
    return *this;
  }

  void done() {
    if (m_first) {
      m_out << "{";
    }
    m_out << "}\n";
  }

private:
  std::ostream        &m_out;
  _OutputStream<Type> &m_jout;
  bool                m_first;

  void init(const std::string &n) {
    if (m_first) {
      m_out << "{";
      m_first = false;
    } else {
      m_out << ",";
    }
    m_jout << Name(n);
  }
};

template <typename Type>
class _ListStream {
public:
  explicit _ListStream(_OutputStream<Type> &jout)
    : m_out(jout.raw()), m_jout(jout), m_first(true) {}

  void next() {
    if (m_first) {
      m_out << "[";
      m_first = false;
    } else {
      m_out << ",";
    }
  }

  template<typename T>
  _ListStream &operator<< (T &v) {
    next();
    m_jout << v;
    return *this;
  }

  void done() {
    if (m_first) {
      m_out << "[";
    }
    m_out << "]\n";
  }

private:
  std::ostream        &m_out;
  _OutputStream<Type> &m_jout;
  bool                m_first;
};

///////////////////////////////////////////////////////////////////////////////
}}

#endif // incl_HPHP_JSON_H_