• 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

69.52
/pol-core/bscript/compiler/file/SourceLocation.cpp
1
#include "SourceLocation.h"
2

3
#include "bscript/compiler/Antlr4Inc.h"
4

5
#include "bscript/compiler/file/SourceFileIdentifier.h"
6
#include "clib/filecont.h"
7
#include "clib/logfacility.h"
8

9
#include <iterator>
10

11
#include <climits>
12

13
namespace Pol::Bscript::Compiler
14
{
15
Position calculate_end_position( const antlr4::Token* symbol )
1,136,936✔
16
{
17
  if ( !symbol )
1,136,936✔
18
  {
UNCOV
19
    return Position{ 0, 0, 0 };
×
20
  }
21
  auto line = symbol->getLine();
1,136,936✔
22
  auto character = symbol->getCharPositionInLine() + 1;
1,136,936✔
23
  const auto& str = symbol->getText();
1,136,936✔
24
  const auto size = str.size();
1,136,936✔
25

26
  for ( size_t i = 0; i < size; i++ )
5,065,951✔
27
  {
28
    if ( str[i] == '\r' && i + 1 < size && str[i + 1] == '\n' )
3,929,015✔
29
    {
30
      ++line;
×
UNCOV
31
      character = 1;
×
32
    }
33
    else if ( str[i] == '\r' )
3,929,015✔
34
    {
35
      ++line;
×
UNCOV
36
      character = 1;
×
37
    }
38
    else if ( str[i] == '\n' )
3,929,015✔
39
    {
40
      ++line;
279✔
41
      character = 1;
279✔
42
    }
43
    else
44
      ++character;
3,928,736✔
45
  }
46

47
  return Position{ line, character, symbol->getTokenIndex() };
1,136,936✔
48
}
1,136,936✔
49

50
Range::Range( Position start, Position end ) : start( std::move( start ) ), end( std::move( end ) )
27,222✔
51
{
52
}
27,222✔
53

54
Range::Range( const antlr4::ParserRuleContext& ctx )
1,028,280✔
55
    : start( Position{ ctx.getStart()->getLine(), ctx.getStart()->getCharPositionInLine() + 1,
1,028,280✔
56
                       ctx.getStart()->getTokenIndex() } ),
1,028,280✔
57
      end( calculate_end_position( ctx.getStop() ) )
1,028,280✔
58
{
59
}
1,028,280✔
60

61
Range::Range( const antlr4::tree::TerminalNode& ctx )
103,530✔
62
    : start( Position{ ctx.getSymbol()->getLine(), ctx.getSymbol()->getCharPositionInLine() + 1,
103,530✔
63
                       ctx.getSymbol()->getTokenIndex() } ),
103,530✔
64
      end( calculate_end_position( ctx.getSymbol() ) )
103,530✔
65
{
66
}
103,530✔
67

68
Range::Range( const antlr4::Token* token )
5,126✔
69
    : start( Position{ token->getLine(), token->getCharPositionInLine() + 1,
5,126✔
70
                       token->getTokenIndex() } ),
5,126✔
71
      end( calculate_end_position( token ) )
5,126✔
72
{
73
}
5,126✔
74

75
SourceLocation::SourceLocation( const SourceFileIdentifier* source_file_identifier,
3,401✔
76
                                size_t line_number, size_t character_column )
3,401✔
77
    : source_file_identifier( source_file_identifier ),
3,401✔
78
      range( Position{ line_number, character_column, 0 },
3,401✔
79
             Position{ std::numeric_limits<size_t>::max(), std::numeric_limits<size_t>::max(),
80
                       std::numeric_limits<size_t>::max() } )
81
{
82
}
3,401✔
83

84
SourceLocation::SourceLocation( const SourceFileIdentifier* source_file_identifier,
23,815✔
85
                                const Range& range )
23,815✔
86
    : source_file_identifier( source_file_identifier ), range( range )
23,815✔
87
{
88
}
23,815✔
89

90
SourceLocation::SourceLocation( const SourceFileIdentifier* source_file_identifier,
1,027,838✔
91
                                const antlr4::ParserRuleContext& ctx )
1,027,838✔
92
    : source_file_identifier( source_file_identifier ), range( ctx )
1,027,838✔
93
{
94
}
1,027,838✔
95

96
SourceLocation::SourceLocation( const SourceFileIdentifier* source_file_identifier,
55,521✔
97
                                const antlr4::tree::TerminalNode& ctx )
55,521✔
98
    : source_file_identifier( source_file_identifier ), range( ctx )
55,521✔
99
{
100
}
55,521✔
101

102
bool Range::contains( const Position& position ) const
1,674✔
103
{
104
  return contains( position.line_number, position.character_column );
1,674✔
105
}
106

107
bool Range::contains( size_t line_number, size_t character_column ) const
1,674✔
108
{
109
  if ( line_number < start.line_number || line_number > end.line_number )
1,674✔
110
  {
111
    return false;
220✔
112
  }
113
  if ( line_number == start.line_number && character_column < start.character_column )
1,454✔
114
  {
UNCOV
115
    return false;
×
116
  }
117
  if ( line_number == end.line_number && character_column > end.character_column )
1,454✔
118
  {
UNCOV
119
    return false;
×
120
  }
121
  return true;
1,454✔
122
}
123

UNCOV
124
bool Range::contains( const Range& otherRange ) const
×
125
{
126
  if ( otherRange.start.line_number < start.line_number ||
×
UNCOV
127
       otherRange.end.line_number < start.line_number )
×
128
  {
UNCOV
129
    return false;
×
130
  }
131
  if ( otherRange.start.line_number > end.line_number ||
×
UNCOV
132
       otherRange.end.line_number > end.line_number )
×
133
  {
UNCOV
134
    return false;
×
135
  }
136
  if ( otherRange.start.line_number == start.line_number &&
×
UNCOV
137
       otherRange.start.character_column < start.character_column )
×
138
  {
UNCOV
139
    return false;
×
140
  }
141
  if ( otherRange.end.line_number == end.line_number &&
×
UNCOV
142
       otherRange.end.character_column > end.character_column )
×
143
  {
UNCOV
144
    return false;
×
145
  }
UNCOV
146
  return true;
×
147
}
148

UNCOV
149
void SourceLocation::debug( const std::string& msg ) const
×
150
{
151
  ERROR_PRINTLN( "{}: {}", ( *this ), msg );
×
UNCOV
152
}
×
153

UNCOV
154
void SourceLocation::internal_error( const std::string& msg ) const
×
155
{
156
  ERROR_PRINTLN( "{}: {}", ( *this ), msg );
×
UNCOV
157
  throw std::runtime_error( msg );
×
158
}
159

UNCOV
160
void SourceLocation::internal_error( const std::string& msg, const SourceLocation& related ) const
×
161
{
162
  ERROR_PRINTLN( "{}: {}\n  See also: {}", ( *this ), msg, related );
×
UNCOV
163
  throw std::runtime_error( msg );
×
164
}
165

166
std::string SourceLocation::getSourceLine() const
23,831✔
167
{
168
  std::string lines;
23,831✔
169
  if ( !range.start.line_number )
23,831✔
UNCOV
170
    return {};
×
171
  auto& content = source_file_identifier->getLines();
23,831✔
172
  for ( size_t i = range.start.line_number - 1; i < range.end.line_number && i < content.size();
47,662✔
173
        ++i )
174
  {
175
    if ( !lines.empty() )
23,831✔
UNCOV
176
      lines += '\n';
×
177
    lines += content[i];
23,831✔
178
  }
179

180
  return lines;
23,831✔
181
}
23,831✔
182

183
}  // namespace Pol::Bscript::Compiler
184

185
fmt::format_context::iterator fmt::formatter<Pol::Bscript::Compiler::SourceLocation>::format(
1,023✔
186
    const Pol::Bscript::Compiler::SourceLocation& l, fmt::format_context& ctx ) const
187
{
188
  std::string tmp = l.source_file_identifier->pathname;
1,023✔
189
  if ( l.range.start.line_number || l.range.start.character_column )
1,023✔
190
    fmt::format_to( std::back_inserter( tmp ), ":{}:{}", l.range.start.line_number,
1,023✔
191
                    l.range.start.character_column );
1,023✔
192
  return fmt::formatter<std::string>::format( tmp, ctx );
2,046✔
193
}
1,023✔
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