/usr/include/hphp/parser/parser.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 | /*
+----------------------------------------------------------------------+
| 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_PARSER_PARSER_H_
#define incl_HPHP_PARSER_PARSER_H_
#include <map>
#include <set>
#include <vector>
#include <string>
#include <memory>
#include "hphp/parser/scanner.h"
#include "hphp/util/lock.h"
#include "hphp/util/functional.h"
#include "hphp/util/hash-map-typedefs.h"
#define IMPLEMENT_XHP_ATTRIBUTES \
Token m_xhpAttributes; \
Token *xhpGetAttributes() { \
if (m_xhpAttributes.num()) { \
return &m_xhpAttributes; \
} \
return nullptr; \
} \
void xhpSetAttributes(Token &t) { \
m_xhpAttributes = t; \
m_xhpAttributes = 1; \
} \
void xhpResetAttributes() { \
m_xhpAttributes.reset(); \
} \
#define NAMESPACE_SEP '\\'
namespace HPHP {
//////////////////////////////////////////////////////////////////////
/*
* HHVM supports multiple types of lambda expressions.
*/
enum class ClosureType {
/*
* Short = Lambda syntax. Automatically captures variables mentioned in the
* body.
*/
Short,
/*
* Long = Traditional closure syntax. Only captures variables that are
* explicitly specified in the "use" list.
*/
Long,
};
enum class PropAccessType {
Normal,
NullSafe,
};
enum ObjPropType {
ObjPropNormal,
ObjPropXhpAttr
};
//////////////////////////////////////////////////////////////////////
typedef void* TStatementPtr;
class ParserBase {
public:
enum NameKind {
StringName,
VarName,
ExprName,
StaticClassExprName,
StaticName
};
static bool IsClosureName (const std::string &name);
std::string newClosureName(
const std::string &namespaceName,
const std::string &className,
const std::string &funcName);
std::string newAnonClassName(
const std::string &prefix,
const std::string &namespaceName,
const std::string &className,
const std::string &funcName);
public:
ParserBase(Scanner &scanner, const char *fileName);
virtual ~ParserBase();
Scanner &scanner() { return m_scanner;}
/**
* Main function to call to start parsing the file. This function is already
* implemented in hphp.y. Therefore, a subclass only has to declare it.
*/
virtual bool parseImpl() = 0;
/**
* Raise a parser error.
*/
virtual void error(ATTRIBUTE_PRINTF_STRING const char* fmt, ...)
ATTRIBUTE_PRINTF(2,3) = 0;
/**
* Public accessors.
*/
const char *file() const { return m_fileName;}
std::string getMessage(bool filename = false,
bool rawPosWhenNoError = false) const;
std::string getMessage(const Location::Range& loc,
bool filename = false) const;
const Location::Range& getRange() const;
int line0() const { return m_loc.r.line0;}
int char0() const { return m_loc.r.char0;}
int line1() const { return m_loc.r.line1;}
int char1() const { return m_loc.r.char1;}
int cursor() const { return m_loc.cursor;}
// called by generated code
int scan(ScannerToken *token, Location *loc) {
return m_scanner.getNextToken(*token, *loc);
}
void setRuleLocation(Location *loc) {
m_loc = *loc;
}
virtual void fatal(const Location* loc, const char* msg) {}
virtual void parseFatal(const Location* loc, const char* msg) {}
void pushFuncLocation();
Location::Range popFuncLocation();
void pushClass(bool isXhpClass);
bool peekClass();
void popClass();
// for typevar checking
void pushTypeScope();
void popTypeScope();
void addTypeVar(const std::string &name);
bool isTypeVar(const std::string &name);
bool isTypeVarInImmediateScope(const std::string &name);
// for goto syntax checking
void pushLabelInfo();
void pushLabelScope();
void popLabelScope();
void addLabel(const std::string &label, const Location::Range& loc,
ScannerToken *stmt);
void addGoto(const std::string &label, const Location::Range& loc,
ScannerToken *stmt);
void popLabelInfo();
enum GotoError {
UndefLabel = 1,
InvalidBlock,
};
virtual void invalidateGoto(TStatementPtr expr, GotoError error) = 0;
virtual void invalidateLabel(TStatementPtr expr) = 0;
virtual TStatementPtr extractStatement(ScannerToken *stmt) = 0;
protected:
Scanner &m_scanner;
const char *m_fileName;
Location m_loc;
std::vector<Location::Range> m_funcLocs;
std::vector<bool> m_classes; // used to determine if we are currently
// inside a regular class or an XHP class
struct LabelStmtInfo {
int scopeId;
TStatementPtr stmt;
bool inTryCatchBlock;
Location::Range loc;
};
typedef std::map<std::string, LabelStmtInfo> LabelMap;
// name => LabelStmtInfo
typedef std::set<std::string> TypevarScope;
typedef std::vector<TypevarScope> TypevarScopeStack;
TypevarScope m_typeVars;
TypevarScopeStack m_typeScopes;
// for goto syntax checking
typedef std::vector<int> LabelScopes;
struct GotoInfo {
std::string label;
LabelScopes scopes;
Location::Range loc;
TStatementPtr stmt;
};
class LabelInfo {
public:
LabelInfo() : scopeId(0) {}
int scopeId;
LabelScopes scopes;
LabelMap labels;
std::vector<GotoInfo> gotos;
};
std::vector<LabelInfo> m_labelInfos; // stack by function
// for namespace support
enum NamespaceState {
SeenNothing,
SeenNonNamespaceStatement,
SeenNamespaceStatement,
InsideNamespace,
};
NamespaceState m_nsState;
bool m_nsFileScope;
std::string m_namespace; // current namespace
hphp_string_imap<std::string> m_aliases;
hphp_string_imap<int> m_seenAnonClasses;
};
///////////////////////////////////////////////////////////////////////////////
}
#endif // incl_HPHP_PARSER_PARSER_H_
|