mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-24 19:30:10 +08:00
C++ reads `x->m` on a class value as `x.operator->()->m`, and applies `->` again to a class it returns. Only a library holder's `->` and a container iterator's (`std::vector<T>::iterator`) were read. A call through a project iterator or smart-pointer wrapper was guessed by the method's name: - rocksdb's `fs_->NewWritableFile(…)` on a `FileSystemPtr`, whose `operator->` returns a `std::shared_ptr<FileSystem>`, reached `FaultInjectionTestFS`; - `writable_file_->Truncate(…)` on an `FSWritableFilePtr` reached the legacy `WritableFile::Truncate`; - `iter->lkey->user_key()` through `MultiGetContext::Range::Iterator`, whose `KeyContext* operator->()` is a `KeyContext*`, reached `BlobCountingIterator::user_key`. Both a member chain's `->` and a `->` call on a declared receiver end in cppIteratorTarget. For a type that is no container's iterator, it now falls back to cppOperatorTarget: - what the class's `operator->` returns, through the pointer it is, or with `->` applied again to a class it is: a library holder, or another of these; - else what its `operator*` returns; - the return type is read where the class declares it, and the class's own template parameters are bound to the type's written arguments (cppTemplateBound): `UnownedPtr<DB>`'s `T* operator->()` is a `DB*`; - a parameter the type doesn't bind names no particular class. A log-only census on mainbdf288a7found 304 rocksdb and 42 protobuf dereferences of a project class with an `operator->` that gave no element. Among the rocksdb calls, 77 were bare-name guesses and 56 were unlinked. Kit A/B againstbdf288a7: | repo | removed | added | retargeted | same target, now typed | |---|---|---|---|---| | rocksdb | 2 | 49 | 158 | 89 | | protobuf | 0 | 0 | 7 | 3 | | leveldb, fmt, redis | identical | | | | - Retargeted: - FaultInjectionTestFS → FileSystem (57), WritableFile → FSWritableFile (32), and TruncatedRangeDelIterator through UnownedPtr (16); - LookupKey and GetContext through MultiGetContext's iterator; - SequentialFile and RandomAccessFile → FSSequentialFile and FSRandomAccessFile; - protobuf's `map_field_->` calls from WeakRepeatedPtrField to the map field bases; - overloads (DB::Put, PinnableSlice) chosen on the now-known class. - Removed: `iter->timestamp->assign(…)` on a `std::string*`, which had reached `autovector::assign`. - Added: Status::PermitUncheckedError, FileSystem::OptimizeFor…, Cleanable::RegisterCleanup, and gtest's ParamGeneratorInterface through linked_ptr. - About 40 changed sites read by hand were all right. Mutations: dropping the fallback, the operator* fallback, the second `->` or the template binding each fail the new tests. Accepting an inexact class, found only as the sole one of its name, survives; the guard stays, as in the member-chain matcher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>