Arquivos
hhvm/hphp/compiler/expression/parameter_expression.h
T
drussi 6e8178da16 expose type annotation to reflection including generics, function types and tuples
This is intended so reflection can be used (via getTypehintText and getReturnTypehintText) to regenerate code the user annotated with types. Essentially using reflection to intrispect code in order to generate type safe
(hack safe) code. That is particularly important for the tools that do dependency injection. The runtime should be oblivious to the change as the rich type annotation is currently only stored for the sake of reflection. For
functions the values are in the shared portion which is cold and should also take care of traits.
2013-04-19 12:21:55 -07:00

74 linhas
2.9 KiB
C++

/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010- 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 __PARAMETER_EXPRESSION_H__
#define __PARAMETER_EXPRESSION_H__
#include <compiler/expression/expression.h>
#include <util/json.h>
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
DECLARE_BOOST_TYPES(Type);
DECLARE_BOOST_TYPES(AnalysisResult);
DECLARE_BOOST_TYPES(ParameterExpression);
DECLARE_BOOST_TYPES(TypeAnnotation);
class ParameterExpression : public Expression {
public:
ParameterExpression(EXPRESSION_CONSTRUCTOR_PARAMETERS,
TypeAnnotationPtr type, const std::string &name,
bool ref, ExpressionPtr defaultValue,
ExpressionPtr attributeList);
DECLARE_EXPRESSION_VIRTUAL_FUNCTIONS;
bool isRef() const { return m_ref;}
bool isOptional() const { return m_defaultValue;}
const std::string &getName() const { return m_name; }
int getLocalEffects() const { return NoEffect; }
void rename(const std::string &name) { m_name = name;}
ExpressionPtr defaultValue() { return m_defaultValue; }
ExpressionPtr userAttributeList() { return m_attributeList; }
TypePtr getTypeSpec(AnalysisResultPtr ar, bool forInference);
bool hasTypeHint() const { return !m_type.empty(); }
const std::string &getTypeHint() const {
assert(hasTypeHint());
return m_type;
}
bool hasUserType() const { return m_originalType != nullptr; }
const std::string getOriginalTypeHint() const;
const std::string getUserTypeHint() const;
void parseHandler(ClassScopePtr cls);
void compatibleDefault();
void fixupSelfAndParentTypehints(ClassScopePtr cls);
private:
TypePtr getTypeSpecForClass(AnalysisResultPtr ar, bool forInference);
std::string m_type;
TypeAnnotationPtr m_originalType;
std::string m_name;
bool m_ref;
ExpressionPtr m_defaultValue;
ExpressionPtr m_attributeList;
};
///////////////////////////////////////////////////////////////////////////////
}
#endif // __PARAMETER_EXPRESSION_H__