Skip to content

Commit

Permalink
attributes on classes
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-therond committed May 24, 2024
1 parent 1557195 commit 919ccb1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/PHPCfg/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function renderOp(Op $op)

$result .= $this->renderAttributes($op->getAttributes());

if ($op instanceof Op\Stmt\Function_) {
if ($op instanceof Op\Stmt\Function_ || $op instanceof Op\Stmt\Class_) {
$result .= $this->renderAttrGroups($op->attrGroups);
}

Expand Down
4 changes: 4 additions & 0 deletions test/code/anonymous_class.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Block#1
expr: Var#1
result: Var#3
Stmt_Class
attrGroup[0]:
attr[0]:
name: LITERAL('Attr')
args[0]: LITERAL('foo')
name: LITERAL('{anonymousClass}#2')
stmts: Block#3
Expr_New
Expand Down
30 changes: 30 additions & 0 deletions test/code/class_attributes.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,34 @@ class NameOfClass6 {
-----
Block#1
Stmt_Class
attrGroup[0]:
attr[0]:
name: LITERAL('NameOfAttribute')
name: LITERAL('NameOfClass1')
stmts: Block#2
Stmt_Class
attrGroup[0]:
attr[0]:
name: LITERAL('ExampleAttribute')
args[0]: LITERAL('foo')
args[1]: LITERAL('bar')
name: LITERAL('NameOfClass2')
stmts: Block#3
Stmt_Class
attrGroup[0]:
attr[0]:
name: LITERAL('Attr')
attrGroup[1]:
attr[0]:
name: LITERAL('FooAttr')
name: LITERAL('NameOfClass3')
stmts: Block#4
Stmt_Class
attrGroup[0]:
attr[0]:
name: LITERAL('Attr')
attr[1]:
name: LITERAL('FooAttr')
name: LITERAL('NameOfClass4')
stmts: Block#5
Expr_ClassConstFetch
Expand All @@ -55,12 +74,23 @@ Block#1
right: Var#2
result: Var#3
Stmt_Class
attrGroup[0]:
attr[0]:
name: LITERAL('Attribute')
args[0]: Var#3
name: LITERAL('NameOfClass5')
stmts: Block#6
Expr_ConstFetch
name: LITERAL('null')
result: Var#4
Stmt_Class
attrGroup[0]:
attr[0]:
name: LITERAL('ConstAttr')
attrGroup[1]:
attr[0]:
name: LITERAL('FooAttribute')
args[0]: Var#4
name: LITERAL('NameOfClass6')
stmts: Block#7
Terminal_Return
Expand Down

0 comments on commit 919ccb1

Please sign in to comment.