PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/runtime/eval/ast/class_statement.h

https://github.com/F4m3uS/hiphop-php
C Header | 172 lines | 133 code | 20 blank | 19 comment | 1 complexity | 939e38d9419480eefa424ee44e373f14 MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010 Facebook, Inc. (http://www.facebook.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef __EVAL_CLASS_STATEMENT_H__
  17. #define __EVAL_CLASS_STATEMENT_H__
  18. #include <runtime/eval/ast/statement.h>
  19. #include <runtime/base/class_info.h>
  20. #include <util/case_insensitive.h>
  21. namespace HPHP {
  22. namespace Eval {
  23. ///////////////////////////////////////////////////////////////////////////////
  24. DECLARE_AST_PTR(Expression);
  25. DECLARE_AST_PTR(ClassVariable);
  26. DECLARE_AST_PTR(ClassStatement);
  27. DECLARE_AST_PTR(MethodStatement);
  28. DECLARE_AST_PTR(ScalarExpression);
  29. DECLARE_AST_PTR(ClassStatementMarker);
  30. class EvalObjectData;
  31. class ClassInfoEvaled;
  32. class ClassEvalState;
  33. class ClassVariable : public Construct {
  34. public:
  35. ClassVariable(CONSTRUCT_ARGS, const std::string &name, int modifiers,
  36. ExpressionPtr value, const std::string &doc, ClassStatement *cls);
  37. void set(VariableEnvironment &env, EvalObjectData *self) const;
  38. void setStatic(VariableEnvironment &env, LVariableTable &statics) const;
  39. virtual void dump(std::ostream &out) const;
  40. const std::string &name() const { return m_name; }
  41. void getInfo(ClassInfo::PropertyInfo &info) const;
  42. int getModifiers() const { return m_modifiers; }
  43. void eval(VariableEnvironment &env, Variant &res) const;
  44. int64 getHash() const { return m_hash; }
  45. bool hasInitialValue() const { return m_value; }
  46. private:
  47. std::string m_name;
  48. int64 m_hash;
  49. int m_modifiers;
  50. ExpressionPtr m_value;
  51. std::string m_docComment;
  52. ClassStatement *m_cls;
  53. };
  54. class ClassStatement : public Statement {
  55. public:
  56. enum Modifier {
  57. Public = 1,
  58. Protected = 2,
  59. Private = 4,
  60. AccessMask = Public|Protected|Private,
  61. Static = 8,
  62. Abstract = 16,
  63. Final = 32,
  64. Interface = 64
  65. };
  66. ClassStatement(STATEMENT_ARGS, const std::string &name,
  67. const std::string &parent, const std::string &doc);
  68. void finish();
  69. const std::string &name() const { return m_name; }
  70. const std::string &lname() const { return m_lname; }
  71. const std::string &parent() const { return m_parent; }
  72. const ClassStatement *parentStatement() const;
  73. void loadInterfaceStatements() const;
  74. void setModifiers(int m) { m_modifiers = m; }
  75. int getModifiers() const { return m_modifiers; }
  76. void addBases(const std::vector<String> &bases);
  77. void addVariable(ClassVariablePtr v) {
  78. m_variables[v->name().c_str()] = v;
  79. m_variablesVec.push_back(v);
  80. }
  81. void addMethod(MethodStatementPtr m);
  82. void addConstant(const std::string &name, ExpressionPtr v);
  83. bool instanceOf(const char *c) const;
  84. bool subclassOf(const char *c) const;
  85. bool isBaseClass() const {
  86. return m_parent.empty() && m_bases.empty();
  87. }
  88. // Eval is called at declaration, not invocation
  89. virtual void eval(VariableEnvironment &env) const;
  90. void evalImpl(VariableEnvironment &env) const;
  91. // Called by create_class
  92. Object create(ClassEvalState &ce, CArrRef params, bool init,
  93. ObjectData* root = NULL) const;
  94. void initializeObject(EvalObjectData *obj) const;
  95. void initializeStatics(LVariableTable &statics) const;
  96. const MethodStatement* findMethod(const char* name,
  97. bool recursive = false,
  98. bool interfaces = false) const;
  99. const ClassVariable* findVariable(const char* name,
  100. bool recursive = false) const;
  101. bool getConstant(Variant &res, const char *c,
  102. bool recursive = false) const;
  103. virtual void dump(std::ostream &out) const;
  104. static void dumpModifiers(std::ostream &out, int m, bool variable);
  105. void getPropertyInfo(ClassInfoEvaled &owner) const;
  106. void getInfo(ClassInfoEvaled &info) const;
  107. bool hasAccess(const char *context, Modifier level) const;
  108. bool attemptPropertyAccess(CStrRef prop, const char *context,
  109. int &mods, bool rec = false) const;
  110. void failPropertyAccess(CStrRef prop, const char *context,
  111. int mods) const;
  112. void toArray(Array &props, Array &vals) const;
  113. void loadMethodTable(ClassEvalState &ce) const;
  114. void semanticCheck(const ClassStatement *cls) const;
  115. ClassStatementMarkerPtr getMarker() const;
  116. void delayDeclaration() { m_delayDeclaration = true; }
  117. protected:
  118. std::string m_name;
  119. std::string m_lname;
  120. int m_modifiers;
  121. std::string m_parent;
  122. hphp_const_char_imap<bool> m_bases;
  123. std::vector<std::string> m_basesVec;
  124. hphp_const_char_imap<ClassVariablePtr> m_variables;
  125. std::vector<ClassVariablePtr> m_variablesVec;
  126. hphp_const_char_imap<MethodStatementPtr> m_methods;
  127. std::vector<MethodStatementPtr> m_methodsVec;
  128. std::map<std::string, ExpressionPtr> m_constants;
  129. std::string m_docComment;
  130. ClassStatementMarkerPtr m_marker;
  131. bool m_delayDeclaration;
  132. void loadProperties(ClassInfoEvaled &info) const;
  133. const MethodStatement* findParentMethod(const char* name,
  134. bool interface) const;
  135. const ClassInfo *getBuiltinParentInfo() const;
  136. void abstractMethodCheck(hphp_const_char_imap<const char*> &abstracts,
  137. bool ifaces) const;
  138. void recursiveParentCheck(std::set<const ClassStatement*> &seen) const;
  139. };
  140. class ClassStatementMarker : public Statement {
  141. public:
  142. ClassStatementMarker(STATEMENT_ARGS, ClassStatement *cls);
  143. virtual void eval(VariableEnvironment &env) const;
  144. virtual bool skipDump() const { return true;}
  145. virtual void dump(std::ostream &out) const;
  146. protected:
  147. ClassStatement *m_class;
  148. };
  149. ///////////////////////////////////////////////////////////////////////////////
  150. }
  151. }
  152. #endif /* __EVAL_CLASS_STATEMENT_H__ */