Skip to content

Commit

Permalink
Merge pull request #333 from reliforp/count-grouping-context
Browse files Browse the repository at this point in the history
Add #count field to grouping contexts
  • Loading branch information
sj-i committed Nov 21, 2023
2 parents 4877c4f + 3638735 commit f99d12a
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -844,21 +844,6 @@ public function collectZendObject(
;
$object_context->add('object_handlers', $object_handlers_context);

if (
!is_null($object->properties)
and !is_null($object->ce)
and !$object->isEnum($dereferencer)
) {
$dynamic_properties_context = $this->collectZendArray(
$dereferencer->deref($object->properties),
$map_ptr_base,
$dereferencer,
$zend_type_reader,
$memory_locations,
$context_pools,
);
$object_context->add('dynamic_properties', $dynamic_properties_context);
}
$properties_exists = false;
$object_properties_context = new ObjectPropertiesContext();
$properties_iterator = $object->getPropertiesIterator(
Expand All @@ -884,6 +869,22 @@ public function collectZendObject(
$object_context->add('object_properties', $object_properties_context);
}

if (
!is_null($object->properties)
and !is_null($object->ce)
and !$object->isEnum($dereferencer)
) {
$dynamic_properties_context = $this->collectZendArray(
$dereferencer->deref($object->properties),
$map_ptr_base,
$dereferencer,
$zend_type_reader,
$memory_locations,
$context_pools,
);
$object_context->add('dynamic_properties', $dynamic_properties_context);
}

assert(!is_null($object->ce));
$class_entry = $dereferencer->deref($object->ce);
if ($class_entry->getClassName($dereferencer) === 'Closure') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public function getLocations(): iterable
{
return [$this->memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
final class CallFrameVariableTableContext implements ReferenceContext
{
use ReferenceContextDefault;

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
final class CallFramesContext implements ReferenceContext
{
use ReferenceContextDefault;

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public function getLocations(): iterable
{
return [$this->memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public function getLocations(): iterable
{
return [$this->memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
class DefinedClassesContext implements ReferenceContext
{
use ReferenceContextDefault;

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public function getLocations(): array
{
return [$this->header_memory_location, $this->table_memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public function getLocations(): iterable
{
return [$this->memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public function getLocations(): iterable
{
return [$this->memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
class ObjectPropertiesContext implements ReferenceContext
{
use ReferenceContextDefault;

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public function getLocations(): iterable
{
return [$this->objects_store_memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public function getLocations(): iterable
{
return [$this->memory_location];
}

public function getContexts(): iterable
{
return [
'#count' => count($this->referencing_contexts),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,29 @@ public function testCollectAll()
[
PHP_BINARY,
'-r',
<<<CODE
<<<'CODE'
/** class doc_comment */
class A {
public static \$output = STDOUT;
public string \$result = '';
public function wait(\$input): void {
\$this->result = fgets(\$input);
public static $output = STDOUT;
/** property doc_comment */
public string $result = '';
/** function doc_comment */
public function wait($input): void {
static $test_static_variable = 0xdeadbeef;
(function (...$_) use ($input) {
$this->result = fgets($input);
})(123, extra: 456);
}
}
\$object = new A;
fputs(A::\$output, "a\n");
\$object->wait(STDIN);
$tempfile = tempnam('', '');
include $tempfile;
$object = new A;
$ref_object =& $object;
$object->dynamic_property = 42;
fputs(A::$output, "a\n");
$object->wait(STDIN);
CODE
],
[
Expand Down Expand Up @@ -161,7 +173,7 @@ public function wait(\$input): void {
$region_analized->regional_memory_locations->locations_in_zend_mm_heap,
);
$this->assertSame(
1,
2,
$location_type_analized_result->per_type_usage['ZendObjectMemoryLocation']['count']
);
$object_class_analyzer = new ObjectClassAnalyzer();
Expand All @@ -181,5 +193,106 @@ public function wait(\$input): void {
'ResourceContext',
$contexts_analyzed['call_frames']['0']['local_variables']['$args_to_internal_function[0]']['#type']
);
$this->assertSame(
1,
$contexts_analyzed
['call_frames']
['1']
['this']
['object_properties']
['#count']
);
$this->assertSame(
42,
$contexts_analyzed
['call_frames']
['1']
['this']
['dynamic_properties']
['array_elements']
['dynamic_property']
['value']
['#value']
);
$this->assertSame(
123,
$contexts_analyzed
['call_frames']
['1']
['local_variables']
['_']
['array_elements']
['0']
['value']
['#value']
);
$this->assertSame(
456,
$contexts_analyzed
['call_frames']
['1']
['extra_named_params']
['array_elements']
['extra']
['value']
['#value']
);
$this->assertSame(
'A::wait',
$contexts_analyzed['call_frames']['2']['#function_name']
);
$this->assertSame(
$contexts_analyzed['call_frames']['3']['symbol_table']['array_elements']['object']['value']['#node_id'],
$contexts_analyzed
['call_frames']
['3']
['symbol_table']
['array_elements']
['ref_object']
['value']
['#reference_node_id']
);
$this->assertSame(
'/** class doc_comment */',
$contexts_analyzed['class_table']['a']['doc_comment']['#locations'][0]->value
);
$this->assertSame(
'/** property doc_comment */',
$contexts_analyzed['class_table']['a']['property_info']['result']['doc_comment']['#locations'][0]->value
);
$this->assertSame(
'/** function doc_comment */',
$contexts_analyzed['class_table']['a']['methods']['wait']['op_array']['doc_comment']['#locations'][0]->value
);
$this->assertSame(
1,
$contexts_analyzed
['class_table']
['a']
['methods']
['wait']
['op_array']
['static_variables']
['array_elements']
['#count']
);
$this->assertSame(
0xdeadbeef,
$contexts_analyzed
['class_table']
['a']
['methods']
['wait']
['op_array']
['static_variables']
['array_elements']
['test_static_variable']
['value']
['#value']
);
$this->assertSame(
1,
$contexts_analyzed['included_files']['#count']
);
}
}

0 comments on commit f99d12a

Please sign in to comment.