Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug with duped __xhpAttributeDeclaration

Summary:
Currently XHP will define __xhpAttributeDeclaration on any class that uses the
leading-colon scheme. This is annoying because we can't define a base
implementation or __xhpAttributeDeclaration. So now it only defines
__xhpAttributeDeclaration if you define attributes.

Reviewed By: epriestley

Test Plan: xhpize

Revert: OK
  • Loading branch information...
commit 9d49b010581b91b5a074e20fb17ca25ff199f5ed 1 parent f6234cb
@laverdet laverdet authored
Showing with 17 additions and 11 deletions.
  1. +16 −11 xhp/parser.y
  2. +1 −0  xhp/xhp.hpp
View
27 xhp/parser.y
@@ -1651,20 +1651,24 @@ class_declaration_statement:
yyextra->expecting_xhp_class_statements = true;
yyextra->attribute_decls = "";
yyextra->attribute_inherit = "";
+ yyextra->used_attributes = false;
} class_statement_list {
yyextra->expecting_xhp_class_statements = false;
} '}' {
- $$ = $1 + " xhp_" + $3 + $4 + $5 + $6 + $8 +
- "protected static function &__xhpAttributeDeclaration() {" +
- "static $_ = -1;" +
- "if ($_ === -1) {" +
- "$_ = array_merge(parent::__xhpAttributeDeclaration(), " +
- yyextra->attribute_inherit +
- "array(" + yyextra->attribute_decls + "));" +
- "}" +
- "return $_;"
- "}" +
- $10;
+ $$ = $1 + " xhp_" + $3 + $4 + $5 + $6 + $8;
+ if (yyextra->used_attributes) {
+ $$ = $$ +
+ "protected static function &__xhpAttributeDeclaration() {" +
+ "static $_ = -1;" +
+ "if ($_ === -1) {" +
+ "$_ = array_merge(parent::__xhpAttributeDeclaration(), " +
+ yyextra->attribute_inherit +
+ "array(" + yyextra->attribute_decls + "));" +
+ "}" +
+ "return $_;"
+ "}";
+ }
+ $$ = $$ + $10;
yyextra->used = true;
}
;
@@ -1674,6 +1678,7 @@ class_statement:
T_XHP_ATTRIBUTE { push_state(XHP_ATTR_TYPE_DECL); } xhp_attribute_decls ';' {
pop_state();
yyextra->used = true;
+ yyextra->used_attributes = true;
$$ = ""; // this will be injected when the class closes
}
;
View
1  xhp/xhp.hpp
@@ -40,6 +40,7 @@ class yy_extra_type {
std::stack<int> curly_stack; // tokens appearing before a {
bool expecting_xhp_class_statements; // when we're one level deep in a class
bool old_expecting_xhp_class_statements; // store old value while inside class method
+ bool used_attributes; // did this class use the `attribute` keyword
code_rope attribute_decls; // array keys and values for __xhpAttributeDescription
code_rope attribute_inherit; // from which classes this class should inherit attributes
Please sign in to comment.
Something went wrong with that request. Please try again.