f98a2138b7
When uploading CLs, the presubmit checks verify that the lines in the diff are formatted correctly according to `git cl format runtime`. However, when `buildtools/<os>-<arch>/clang/bin/clang-format` is updated, it does not force reformatting of files that would be reformatted. This leads to two issues: * Inconsistent style within the code base and within a single file. * Spurious reformatting in CLs when (1) clang-format is used on the whole file, or (2) the diff lines overlap. `clang-format` doesn't change that frequently, so in general this is not a large issue, but I've seen a bit too many "spurious formatting, please revert" comments on CLs recently. This CL formats the runtime to be in line with the current pinned `clang-format`: ``` $ find runtime/ -iname *.h -o -iname *.cc | xargs buildtools/mac-arm64/clang/bin/clang-format -i ``` `git cl format` (which only formats changed lines, and does so with `clang-format`) seems to not agree with itself, or clang-format, or cpplint in a handful of places. This CL adds `// clang-format off` for these. (See previous patchsets for the specific instances.) TEST=A variety of bots including GCC, MacOS and Windows. Change-Id: I470892e898971899fda14bb3b8f2c8efefd67686 Cq-Include-Trybots: luci.dart.try:vm-gcc-linux-try,vm-ffi-qemu-linux-release-riscv64-try,vm-ffi-qemu-linux-release-arm-try,vm-aot-win-debug-x64-try,vm-win-debug-x64c-try,vm-mac-debug-x64-try,vm-mac-debug-arm64-try,vm-aot-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362780 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
129 lines
4.4 KiB
C++
129 lines
4.4 KiB
C++
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_VM_PROGRAM_VISITOR_H_
|
|
#define RUNTIME_VM_PROGRAM_VISITOR_H_
|
|
|
|
#if !defined(DART_PRECOMPILED_RUNTIME)
|
|
|
|
#include "vm/allocation.h"
|
|
|
|
namespace dart {
|
|
|
|
// Currently, we have three types of abstract visitors that can be extended and
|
|
// used for program walking:
|
|
//
|
|
// * ClassVisitor, a visitor for classes in the program.
|
|
// * FunctionVisitor, a visitor for functions in the program.
|
|
// * CodeVisitor, a visitor for code objects in the program.
|
|
//
|
|
// To find the functions in a program, we must traverse the classes in the
|
|
// program, and similarly for code objects and functions. Thus, each
|
|
// FunctionVisitor is also a ClassVisitor, and each CodeVisitor is also a
|
|
// FunctionVisitor (and thus a ClassVisitor).
|
|
//
|
|
// Only the most specific visitor method is abstract. Derived visitors have a
|
|
// default empty implementation for base visitor methods to limit boilerplate
|
|
// needed when extending. For example, subclasses of CodeVisitor that only do
|
|
// per-Code work do not need to add empty implementations for VisitClass and
|
|
// VisitFunction.
|
|
//
|
|
// There are no guarantees for the order in which objects of a given type will
|
|
// be visited, but each object will be visited only once. In addition, each
|
|
// object is visited before any visitable sub-objects it contains. For example,
|
|
// this means a FunctionVisitor with a VisitClass implementation that drops
|
|
// methods from a class will not visit the dropped methods unless they are also
|
|
// found via another source of function objects.
|
|
//
|
|
// Note that WalkProgram only visits objects in the isolate heap. Deduplicating
|
|
// visitors that want to use VM objects as canonical when possible should
|
|
// instead add the appropriate VM objects first in their constructor.
|
|
|
|
class Class;
|
|
class Code;
|
|
class Function;
|
|
|
|
class CodeVisitor;
|
|
class FunctionVisitor;
|
|
|
|
class ClassVisitor : public ValueObject {
|
|
public:
|
|
virtual ~ClassVisitor() {}
|
|
|
|
virtual bool IsFunctionVisitor() const { return false; }
|
|
const FunctionVisitor* AsFunctionVisitor() const {
|
|
return const_cast<FunctionVisitor*>(
|
|
const_cast<ClassVisitor*>(this)->AsFunctionVisitor());
|
|
}
|
|
FunctionVisitor* AsFunctionVisitor() {
|
|
if (!IsFunctionVisitor()) return nullptr;
|
|
return reinterpret_cast<FunctionVisitor*>(this);
|
|
}
|
|
|
|
virtual bool IsCodeVisitor() const { return false; }
|
|
const CodeVisitor* AsCodeVisitor() const {
|
|
return const_cast<CodeVisitor*>(
|
|
const_cast<ClassVisitor*>(this)->AsCodeVisitor());
|
|
}
|
|
CodeVisitor* AsCodeVisitor() {
|
|
if (!IsCodeVisitor()) return nullptr;
|
|
return reinterpret_cast<CodeVisitor*>(this);
|
|
}
|
|
|
|
virtual void VisitClass(const Class& cls) = 0;
|
|
};
|
|
|
|
class FunctionVisitor : public ClassVisitor {
|
|
public:
|
|
bool IsFunctionVisitor() const { return true; }
|
|
virtual void VisitClass(const Class& cls) {}
|
|
virtual void VisitFunction(const Function& function) = 0;
|
|
};
|
|
|
|
class CodeVisitor : public FunctionVisitor {
|
|
public:
|
|
bool IsCodeVisitor() const { return true; }
|
|
virtual void VisitFunction(const Function& function) {}
|
|
virtual void VisitCode(const Code& code) = 0;
|
|
};
|
|
|
|
class Thread;
|
|
class IsolateGroup;
|
|
|
|
class ProgramVisitor : public AllStatic {
|
|
public:
|
|
// Walks all non-null class, function, and code objects in the program as
|
|
// necessary for the given visitor.
|
|
static void WalkProgram(Zone* zone,
|
|
IsolateGroup* isolate_group,
|
|
ClassVisitor* visitor);
|
|
|
|
static void Dedup(Thread* thread);
|
|
#if defined(DART_PRECOMPILER)
|
|
static void AssignUnits(Thread* thread);
|
|
static uint32_t Hash(Thread* thread);
|
|
#endif
|
|
|
|
private:
|
|
static void BindStaticCalls(Thread* thread);
|
|
static void ShareMegamorphicBuckets(Thread* thread);
|
|
static void NormalizeAndDedupCompressedStackMaps(Thread* thread);
|
|
static void DedupPcDescriptors(Thread* thread);
|
|
static void DedupDeoptEntries(Thread* thread);
|
|
#if defined(DART_PRECOMPILER)
|
|
static void DedupCatchEntryMovesMaps(Thread* thread);
|
|
static void DedupUnlinkedCalls(Thread* thread);
|
|
static void PruneSubclasses(Thread* thread);
|
|
#endif
|
|
static void DedupCodeSourceMaps(Thread* thread);
|
|
static void DedupLists(Thread* thread);
|
|
static void DedupInstructions(Thread* thread);
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // !defined(DART_PRECOMPILED_RUNTIME)
|
|
|
|
#endif // RUNTIME_VM_PROGRAM_VISITOR_H_
|