This file is indexed.

/usr/include/hphp/compiler/construct.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
   +----------------------------------------------------------------------+
   | 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_CONSTRUCT_H_
#define incl_HPHP_CONSTRUCT_H_

#include "hphp/parser/location.h"
#include "hphp/compiler/json.h"
#include <memory>
#include "hphp/compiler/code_generator.h"
#include "hphp/compiler/analysis/code_error.h"
#include "hphp/compiler/analysis/block_scope.h"

namespace HPHP {
///////////////////////////////////////////////////////////////////////////////

class Variant;
DECLARE_BOOST_TYPES(Expression);
DECLARE_BOOST_TYPES(StatementList);
DECLARE_BOOST_TYPES(IParseHandler);
DECLARE_BOOST_TYPES(AnalysisResult);
DECLARE_BOOST_TYPES(BlockScope);
DECLARE_BOOST_TYPES(ClassScope);
DECLARE_BOOST_TYPES(FunctionScope);
DECLARE_BOOST_TYPES(FileScope);

class AstWalkerStateVec;

class IParseHandler {
  /**
   * To avoid iteration of parse tree, we move any work that can be done
   * in parse phase into this function, so to speed up static analysis.
   */
public:
  virtual ~IParseHandler() {}

  /**
   * onParse is called by the parser when the construct has just been parsed
   * to allow it to do any necessary work
   */
  virtual void onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
    always_assert(0);
  }
  /**
   * onParseRecur is called by a parent construct (ultimately a class or
   * interface).
   * This is done because at the time that onParse would be called for
   * (eg) a method, the ClassScope doesnt exist. So we wait until onParse
   * is called for the class, and it calls onParseRecur for its children.
   */
  virtual void onParseRecur(AnalysisResultConstPtr ar, FileScopeRawPtr fs,
                            ClassScopePtr scope) {
    always_assert(0);
  }
};

#define DECLARE_STATEMENT_TYPES(x) \
  x(Statement)              \
  x(FunctionStatement)      \
  x(ClassStatement)         \
  x(InterfaceStatement)     \
  x(ClassVariable)          \
  x(ClassConstant)          \
  x(MethodStatement)        \
  x(StatementList)          \
  x(BlockStatement)         \
  x(IfBranchStatement)      \
  x(IfStatement)            \
  x(WhileStatement)         \
  x(DoStatement)            \
  x(ForStatement)           \
  x(SwitchStatement)        \
  x(CaseStatement)          \
  x(BreakStatement)         \
  x(ContinueStatement)      \
  x(ReturnStatement)        \
  x(GlobalStatement)        \
  x(StaticStatement)        \
  x(EchoStatement)          \
  x(UnsetStatement)         \
  x(ExpStatement)           \
  x(ForEachStatement)       \
  x(FinallyStatement)       \
  x(CatchStatement)         \
  x(TryStatement)           \
  x(ThrowStatement)         \
  x(GotoStatement)          \
  x(LabelStatement)         \
  x(UseTraitStatement)      \
  x(ClassRequireStatement)  \
  x(TraitPrecStatement)     \
  x(TraitAliasStatement)    \
  x(TypedefStatement)       \
  x(UseDeclarationStatementFragment) \
  x(DeclareStatement)

#define DECLARE_EXPRESSION_TYPES(x)     \
  x(Expression,                  None) \
  x(ExpressionList,              None) \
  x(AssignmentExpression,       Store) \
  x(SimpleVariable,              Load) \
  x(DynamicVariable,             Load) \
  x(StaticMemberExpression,      Load) \
  x(ArrayElementExpression,      Load) \
  x(DynamicFunctionCall,         Call) \
  x(SimpleFunctionCall,          Call) \
  x(ScalarExpression,            None) \
  x(ObjectPropertyExpression,    Load) \
  x(ObjectMethodExpression,      Call) \
  x(ListAssignment,             Store) \
  x(NewObjectExpression,         Call) \
  x(UnaryOpExpression,         Update) \
  x(IncludeExpression,           Call) \
  x(BinaryOpExpression,        Update) \
  x(QOpExpression,               None) \
  x(NullCoalesceExpression,      None) \
  x(ArrayPairExpression,         None) \
  x(ClassConstantExpression,    Const) \
  x(ParameterExpression,         None) \
  x(ModifierExpression,          None) \
  x(ConstantExpression,         Const) \
  x(EncapsListExpression,        None) \
  x(ClosureExpression,           None) \
  x(ClassExpression,             None) \
  x(YieldExpression,             None) \
  x(YieldFromExpression,         None) \
  x(AwaitExpression,             None) \
  x(UserAttribute,               None)

/**
 * Base class of Expression and Statement.
 */
class Construct : public std::enable_shared_from_this<Construct>,
                  public JSON::CodeError::ISerializable {
public:
  virtual ~Construct() {}

#define DEC_STATEMENT_ENUM(x) KindOf##x,
#define DEC_EXPRESSION_ENUM(x,t) KindOf##x,
  enum KindOf {
    DECLARE_STATEMENT_TYPES(DEC_STATEMENT_ENUM)
    DECLARE_EXPRESSION_TYPES(DEC_EXPRESSION_ENUM)
  };
#undef DEC_EXPRESSION_ENUM
#undef DEC_STATEMENT_ENUM

protected:
  Construct(BlockScopePtr scope, const Location::Range& loc, KindOf);

public:
  /**
   * Type checking without RTTI.
   */
  bool is(KindOf type) const {
    assert(m_kindOf != KindOfStatement);
    assert(m_kindOf != KindOfExpression);
    return m_kindOf == type;
  }
  KindOf getKindOf() const {
    assert(m_kindOf != KindOfStatement);
    assert(m_kindOf != KindOfExpression);
    return m_kindOf;
  }

  bool isStatement() const {
    return !isExpression();
  }
  bool isExpression() const {
    return m_kindOf > KindOfExpression;
  }

  enum Effect {
    NoEffect = 0,
    IOEffect = 1,                // could have an observable effect (not
                                 // changing variable values)
    AssignEffect = 2,            // writes an object in a way understood by the
                                 // alias manager
    GlobalEffect = 4,            // could affect global variables
    LocalEffect = 8,             // could affect variables from the local scope
    ParamEffect = 0x10,          // a function could affect its parameters
    DeepParamEffect = 0x20,      // a function could affect the array elements
                                 // or object members referenced by its
                                 // parameters
    DynamicParamEffect = 0x40,   // a function creates dynamic exps based
                                 // on its parameters, which it could affect
    CanThrow = 0x80,             // can throw PHP exception
    AccessorEffect = 0x100,      // could contain a getter/setter
    CreateEffect = 0x200,        // could cause the creation of an array
                                 // element or an object property
    DiagnosticEffect = 0x400,    // can cause a diagnostic to be issued
    OtherEffect = 0x800,         // something else
    UnknownEffect = 0xfff        // any of the above
  };

  static bool SkipRecurse(ConstructPtr c) {
    return c && c->skipRecurse();
  }
  bool skipRecurse() const;
  void copyLocationTo(ConstructPtr other);
  const Location::Range& getRange() const { return m_r; }
  int line0() const { return m_r.line0; }
  int line1() const { return m_r.line1; }
  void setFirst(int line0, int char0) { m_r.line0 = line0; m_r.char0 = char0; }
  void setFileLevel() { m_flags.topLevel = m_flags.fileLevel = true;}
  void setTopLevel() { m_flags.topLevel = true;}
  bool isFileLevel() const { return m_flags.fileLevel;}
  bool isTopLevel() const { return m_flags.topLevel;}

  void setNeeded() { m_flags.needed = true; }
  void clearNeeded() { m_flags.needed = false; }
  bool isNeeded() const { return m_flags.needed; }

  void setIsUnpack() { m_flags.unpack = 1; }
  bool isUnpack() const { return m_flags.unpack; }
  void clearIsUnpack() { m_flags.unpack = 0; }

  BlockScopeRawPtr getScope() const { return m_blockScope; }
  void setBlockScope(BlockScopeRawPtr scope) { m_blockScope = scope; }
  FileScopeRawPtr getFileScope() const {
    return m_blockScope->getContainingFile();
  }
  FunctionScopeRawPtr getFunctionScope() const {
    return m_blockScope->getContainingFunction();
  }
  ClassScopeRawPtr getClassScope() const {
    return m_blockScope->getContainingClass();
  }
  void resetScope(BlockScopeRawPtr scope);
  void parseTimeFatal(FileScopeRawPtr fs, Compiler::ErrorType error,
    ATTRIBUTE_PRINTF_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(4,5);
  void analysisTimeFatal(Compiler::ErrorType error,
    ATTRIBUTE_PRINTF_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(3,4);
  virtual int getLocalEffects() const { return UnknownEffect;}
  int getChildrenEffects() const;
  int getContainedEffects() const;
  bool hasEffect() const { return getContainedEffects() != NoEffect;}
  virtual bool kidUnused(int i) const { return false; }

  template<typename T>
  static std::shared_ptr<T> Clone(std::shared_ptr<T> constr) {
    if (constr) {
      return dynamic_pointer_cast<T>(constr->clone());
    }
    return std::shared_ptr<T>();
  }

  template<typename T>
  std::shared_ptr<T> Clone(std::shared_ptr<T> constr,
                           BlockScopePtr scope) {
    if (constr) {
      constr = constr->clone();
      constr->resetScope(scope);
    }
    return constr;
  }

  /**
   * Called when we analyze a program, which file it includes, which function
   * and class it uses, etc.
   */
  virtual void analyzeProgram(AnalysisResultPtr ar) = 0;

  /**
   * return the nth child construct
   */
  virtual ConstructPtr getNthKid(int n) const { return ConstructPtr(); }

  /**
   * set the nth child construct
   */
  virtual void setNthKid(int n, ConstructPtr cp)  {}

  /**
   * get the kid count
   */
  virtual int getKidCount() const = 0;

  // helpers for GDB
  void dumpNode(int spc);
  void dumpNode(int spc) const;

  void dump(int spc, AnalysisResultConstPtr ar);
  void dumpNode(int spc, AnalysisResultConstPtr ar);

  /**
   * Called when generating code.
   */
  virtual void outputPHP(CodeGenerator &cg, AnalysisResultPtr ar) = 0;

  /**
   * Implements JSON::CodeError::ISerializable.
   */
  virtual void serialize(JSON::CodeError::OutputStream &out) const;

  /**
   * Get canonicalized PHP source code for this construct.
   */
  std::string getText(AnalysisResultPtr ar);
  std::string getText();

  void recomputeEffects();

  /**
   * Write where this construct was in PHP files.
   */
  void printSource(CodeGenerator &cg);
  ExpressionPtr makeConstant(AnalysisResultConstPtr ar,
                             const std::string &value) const;
  ExpressionPtr makeScalarExpression(AnalysisResultConstPtr ar,
                                     const Variant &value) const;
private:
  BlockScopeRawPtr m_blockScope;
  union {
    unsigned m_flagsVal;
    struct {
      unsigned fileLevel           : 1; // is it at top level of a file
      unsigned topLevel            : 1; // is it at top level of a scope
      unsigned needed              : 1;
      unsigned unpack              : 1; // is this an unpack (only on params)
    } m_flags;
  };
  Location::Range m_r;
protected:
  KindOf m_kindOf;
  mutable int m_containedEffects;
  mutable int m_effectsTag;
};

class LocalEffectsContainer {
public:
  int getLocalEffects() const { return m_localEffects; }
  virtual void effectsCallback() = 0;
protected:
  explicit LocalEffectsContainer(Construct::Effect localEffect) :
    m_localEffects(localEffect) {}
  LocalEffectsContainer() :
    m_localEffects(0) {}
  void setLocalEffect  (Construct::Effect effect);
  void clearLocalEffect(Construct::Effect effect);
  bool hasLocalEffect  (Construct::Effect effect) const;
protected:
  int m_localEffects;
};

#define DECL_AND_IMPL_LOCAL_EFFECTS_METHODS \
  int getLocalEffects() const override { \
    return LocalEffectsContainer::getLocalEffects(); \
  } \
  void effectsCallback() override { recomputeEffects(); }

///////////////////////////////////////////////////////////////////////////////
}
#endif // incl_HPHP_CONSTRUCT_H_