Add "native" functions for use in Systemlib
<?hh
class Foo {
<<__Native>>
public function bar(int $baz) : string;
<<__Native>>
public static function bling(mixed $blong) : double;
}
<<__Native>>
function blong(string $a, stdClass $b) : void;
<<__Native("ActRec")>>
function zorb(int $foo, string $bar): float;
Hooks internal functions:
String HHVM_METHOD(Foo, bar, int64_t bar) { ... }
double HHVM_STATIC_METHOD(Foo, bling, CVarRef blong) { ... }
void HHVM_FUNCTION(blong, CStrRef a, CObjRef b) { ... }
TypedValue* HHVM_FN(zorb)(ActRec* ar) { ... }
When registered during Extension::moduleLoad() with:
HHVM_ME(Foo, bar)
HHVM_STATIC_ME(Foo, bling)
HHVM_FE(blong)
HHVM_FE(zorb)
Differential Revision: D922477
Esse commit está contido em:
@@ -36,11 +36,11 @@ using namespace HPHP;
|
||||
FunctionStatement::FunctionStatement
|
||||
(STATEMENT_CONSTRUCTOR_PARAMETERS,
|
||||
ModifierExpressionPtr modifiers, bool ref, const std::string &name,
|
||||
ExpressionListPtr params, const std::string &retTypeConstraint,
|
||||
ExpressionListPtr params, TypeAnnotationPtr retTypeAnnotation,
|
||||
StatementListPtr stmt, int attr, const std::string &docComment,
|
||||
ExpressionListPtr attrList)
|
||||
: MethodStatement(STATEMENT_CONSTRUCTOR_PARAMETER_VALUES(FunctionStatement),
|
||||
modifiers, ref, name, params, retTypeConstraint, stmt,
|
||||
modifiers, ref, name, params, retTypeAnnotation, stmt,
|
||||
attr, docComment, attrList, false), m_ignored(false) {
|
||||
}
|
||||
|
||||
@@ -80,6 +80,33 @@ void FunctionStatement::onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
|
||||
if (Option::PersistenceHook) {
|
||||
fs->setPersistent(Option::PersistenceHook(fs, scope));
|
||||
}
|
||||
|
||||
if (fs->isNative()) {
|
||||
if (getStmts()) {
|
||||
parseTimeFatal(Compiler::InvalidAttribute,
|
||||
"Native functions must not have an implementation body");
|
||||
}
|
||||
if (m_params) {
|
||||
int nParams = m_params->getCount();
|
||||
for (int i = 0; i < nParams; ++i) {
|
||||
auto param = dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
|
||||
if (!param->hasUserType()) {
|
||||
parseTimeFatal(Compiler::InvalidAttribute,
|
||||
"Native function calls must have type hints "
|
||||
"on all args");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getReturnTypeConstraint().empty()) {
|
||||
parseTimeFatal(Compiler::InvalidAttribute,
|
||||
"Native function %s() must have a return type hint",
|
||||
getOriginalName().c_str());
|
||||
}
|
||||
} else if (!getStmts()) {
|
||||
parseTimeFatal(Compiler::InvalidAttribute,
|
||||
"Global function %s() must contain a body",
|
||||
getOriginalName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário