• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 25918451630

15 May 2026 12:43PM UTC coverage: 60.929% (+2.1%) from 58.859%
25918451630

push

github

turleypol
added dynamic property which returns a pointer of the object instead of
a copy like the current imp.
needed to be able to eg store a vector

43 of 61 new or added lines in 2 files covered. (70.49%)

14455 existing lines in 345 files now uncovered.

44695 of 73356 relevant lines covered (60.93%)

449621.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.73
/pol-core/bscript/compiler/analyzer/Variables.cpp
1
#include "Variables.h"
2

3
#include <ranges>
4

5
#include "bscript/compiler/Report.h"
6
#include "bscript/compiler/file/SourceLocation.h"
7
#include "bscript/compiler/model/Variable.h"
8

9
namespace Pol::Bscript::Compiler
10
{
11
Variables::Variables( VariableScope scope, Report& report )
7,191✔
12
    : scope( scope ), report( report ), variable_info_stack( { VariablesInfo() } )
21,573✔
13
{
14
}
14,382✔
15

16
std::shared_ptr<Variable> Variables::create( const std::string& name, BlockDepth block_depth,
13,186✔
17
                                             WarnOn warn_on, const SourceLocation& source_location )
18
{
19
  auto index = current().names_by_index.size();
13,186✔
20
  if ( index > std::numeric_limits<VariableIndex>::max() )
13,186✔
21
  {
UNCOV
22
    report.error( source_location, "Too many variables" );
×
23
  }
24
  auto variable =
UNCOV
25
      std::make_shared<Variable>( scope, name, block_depth, static_cast<VariableIndex>( index ),
×
26
                                  warn_on, nullptr, source_location );
13,186✔
27
  current().variables_by_name[name] = variable;
13,186✔
28
  current().names_by_index.push_back( name );
13,186✔
29
  return variable;
13,186✔
UNCOV
30
}
×
31

32
std::shared_ptr<Variable> Variables::capture( std::shared_ptr<Variable>& other )
420✔
33
{
34
  // The new variable "local variable" representing the capture at runtime have
35
  // consecutive indexes.
36
  // At compilation:
37
  // - Keep track of the current executing function
38
  // - When visiting an identifier:
39
  // - If type == Capture: ValueStack offset will be current function's param count + this variable
40
  // index
41
  // - If type == Local: if offset > function param count, add current function's capture count
42
  auto index = static_cast<VariableIndex>( current().names_by_index.size() );
420✔
43
  auto captured =
44
      std::make_shared<Variable>( VariableScope::Capture, other->name, other->block_depth, index,
420✔
45
                                  other->warn_on, other, other->source_location );
840✔
46

47
  current().variables_by_name[other->name] = captured;
420✔
48
  current().names_by_index.push_back( captured->name );
420✔
49
  return captured;
840✔
UNCOV
50
}
×
51

52
std::shared_ptr<Variable> Variables::find( const std::string& name ) const
70,763✔
53
{
54
  auto itr = variable_info_stack.back().variables_by_name.find( name );
70,763✔
55
  return ( itr != variable_info_stack.back().variables_by_name.end() )
141,526✔
56
             ? ( *itr ).second
70,763✔
57
             : std::shared_ptr<Variable>();
141,526✔
58
}
59

60
std::shared_ptr<Variable> Variables::find_in_ancestors( const std::string& name ) const
9,767✔
61
{
62
  for ( const auto& info : variable_info_stack | std::views::reverse | std::views::drop( 1 ) )
10,114✔
63
  {
64
    auto itr = info.variables_by_name.find( name );
686✔
65

66
    if ( itr != info.variables_by_name.end() )
686✔
67
    {
68
      return ( *itr ).second;
339✔
69
    }
70
  }
71
  return nullptr;
9,428✔
72
}
73

74
void Variables::restore_shadowed( std::shared_ptr<Variable> variable )
37✔
75
{
76
  // It's still in names_by_index
77
  current().variables_by_name[variable->name] = std::move( variable );
37✔
78
}
37✔
79

80
void Variables::remove_all_but( unsigned count )
11,609✔
81
{
82
  while ( current().names_by_index.size() > count )
22,542✔
83
  {
84
    std::string last_name = current().names_by_index.back();
10,933✔
85
    auto itr = current().variables_by_name.find( last_name );
10,933✔
86

87
    if ( itr != current().variables_by_name.end() )
10,933✔
88
    {
89
      auto& removing = ( *itr ).second;
10,933✔
90
      if ( removing->warn_on == WarnOn::IfUsed && removing->was_used() )
10,933✔
91
      {
92
        report.warning( removing->source_location,
3✔
93
                        "local variable '{}' declared as unused but used.", last_name );
94
      }
95
      else if ( removing->warn_on == WarnOn::IfNotUsed && !removing->was_used() )
10,930✔
96
      {
97
        report.warning( removing->source_location, "local variable '{}' was not used.", last_name );
414✔
98
      }
99
      current().variables_by_name.erase( itr );
10,933✔
100
    }
101
    current().names_by_index.pop_back();
10,933✔
102
  }
10,933✔
103
}
11,609✔
104

105
const std::vector<std::string>& Variables::get_names() const
2,397✔
106
{
107
  return variable_info_stack.back().names_by_index;
2,397✔
108
}
109

110
unsigned Variables::count() const
15,012✔
111
{
112
  return static_cast<unsigned>( variable_info_stack.back().names_by_index.size() );
15,012✔
113
}
114

115
Variables::VariablesInfo& Variables::current()
118,062✔
116
{
117
  return variable_info_stack.back();
118,062✔
118
}
119

120
}  // namespace Pol::Bscript::Compiler
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc