File: SwiftPersistentExpressionState.h

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (115 lines) | stat: -rw-r--r-- 4,155 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//===-- SwiftPersistentExpressionState.h ------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_SwiftPersistentExpressionState_h_
#define liblldb_SwiftPersistentExpressionState_h_

#include "SwiftExpressionVariable.h"

#include "lldb/Expression/ExpressionVariable.h"

#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"

#include <string>

namespace lldb_private {

/// Manages persistent values that need to be preserved between
/// expression invocations.
///
/// A list of variables that can be accessed and updated by any
/// expression.  See \ref ClangPersistentVariable for more discussion.
/// Also provides an increasing, 0-based counter for naming result
/// variables.
class SwiftPersistentExpressionState : public PersistentExpressionState {
public:
  class SwiftDeclMap {
  public:
    void AddDecl(CompilerDecl value_decl, bool check_existing,
                 llvm::StringRef name);

    /// Find decls matching `name`, excluding decls that are equivalent to
    /// decls in `excluding_equivalents`, and put the results in `matches`.
    /// Return true if there are any results.
    bool FindMatchingDecls(
        llvm::StringRef name,
        const std::vector<CompilerDecl> &excluding_equivalents,
        std::vector<CompilerDecl> &matches);

    void CopyDeclsTo(SwiftDeclMap &target_map);
    static bool DeclsAreEquivalent(CompilerDecl lhs, CompilerDecl rhs);

  private:
    /// Each decl also stores the context it comes from.
    llvm::StringMap<llvm::SmallVector<CompilerDecl, 1>> m_swift_decls;
  };

  //----------------------------------------------------------------------
  /// Constructor
  //----------------------------------------------------------------------
  SwiftPersistentExpressionState();

  ~SwiftPersistentExpressionState() {}

  //------------------------------------------------------------------
  // llvm casting support
  //------------------------------------------------------------------
  // LLVM RTTI Support
  static char ID;

  lldb::ExpressionVariableSP
  CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;

  lldb::ExpressionVariableSP
  CreatePersistentVariable(ExecutionContextScope *exe_scope, ConstString name,
                           const CompilerType &compiler_type,
                           lldb::ByteOrder byte_order,
                           uint32_t addr_byte_size) override;

  llvm::StringRef GetPersistentVariablePrefix(bool is_error) const override {
    return is_error ? "$E" : "$R";
  }

  void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;

  ConstString GetNextPersistentVariableName(bool is_error = false) override;

  std::optional<CompilerType>
  GetCompilerTypeFromPersistentDecl(ConstString type_name) override;

  void RegisterSwiftPersistentDecl(CompilerDecl value_decl);

  void RegisterSwiftPersistentDeclAlias(CompilerDecl value_decl,
                                        llvm::StringRef name);

  void CopyInSwiftPersistentDecls(SwiftDeclMap &source_map);

  /// Find decls matching `name`, excluding decls that are equivalent to decls
  /// in `excluding_equivalents`, and put the results in `matches`.  Return true
  /// if there are any results.
  bool GetSwiftPersistentDecls(
      llvm::StringRef name,
      const std::vector<CompilerDecl> &excluding_equivalents,
      std::vector<CompilerDecl> &matches);

private:
  /// The counter used by GetNextResultName().
  uint32_t m_next_persistent_variable_id;
  /// The counter used by GetNextResultName() when is_error is true.
  uint32_t m_next_persistent_error_id;
  /// The persistent functions declared by the user.
  SwiftDeclMap m_swift_persistent_decls;
};
} // namespace lldb_private

#endif