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

polserver / polserver / 21066490217

16 Jan 2026 12:22PM UTC coverage: 60.507%. Remained the same
21066490217

push

github

web-flow
misc clang-tidy (#853)

* trigger tidy

* Automated clang-tidy change: modernize-use-equals-delete,modernize-make-shared,modernize-make-unique,modernize-use-constraints,readability-container-size-empty,modernize-redundant-void-arg,modernize-use-emplace

* removed non needed macros

* missed to disable tidy build

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

174 of 248 new or added lines in 74 files covered. (70.16%)

2 existing lines in 2 files now uncovered.

44459 of 73477 relevant lines covered (60.51%)

515895.79 hits per line

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

33.77
/pol-core/bscript/compiler/analyzer/ExpressionEvaluator.cpp
1
#include "ExpressionEvaluator.h"
2

3
#include "bscript/compiler/ast/BooleanValue.h"
4
#include "bscript/compiler/ast/ElementAccess.h"
5
#include "bscript/compiler/ast/ElementIndexes.h"
6
#include "bscript/compiler/ast/Expression.h"
7
#include "bscript/compiler/ast/FloatValue.h"
8
#include "bscript/compiler/ast/FunctionCall.h"
9
#include "bscript/compiler/ast/FunctionReference.h"
10
#include "bscript/compiler/ast/Identifier.h"
11
#include "bscript/compiler/ast/IntegerValue.h"
12
#include "bscript/compiler/ast/MemberAccess.h"
13
#include "bscript/compiler/ast/StringValue.h"
14
#include "bscript/compiler/ast/UninitializedValue.h"
15
#include "bscript/compiler/file/SourceFile.h"
16
#include "bscript/executor.h"
17
#include "bscript/impstr.h"
18

19
namespace Pol::Bscript::Compiler
20
{
21

22
ExpressionEvaluator::ExpressionEvaluator()
2✔
23
    : _profile(),
2✔
24
      _report( false, false ),
2✔
25
      _ident( 0, "<eval>" ),
2✔
26
      _compiler_workspace( _report ),
2✔
27
      _cache( _profile ),
2✔
28
      _builder_workspace( _compiler_workspace, _cache, _cache, _profile, _report ),
2✔
29
      _expression_builder( _ident, _builder_workspace )
2✔
30
{
31
}
2✔
32

33
BObjectRef ExpressionEvaluator::evaluate( Executor* exec, EScriptProgram* script,
14✔
34
                                          std::string expression )
35
{
36
  SourceFile source_file( "<eval>", expression, _profile );
14✔
37

38
  _report.reset();
14✔
39
  auto unit = source_file.get_evaluate_unit( _report );
14✔
40
  if ( unit == nullptr || _report.error_count() || !unit->expression() )
14✔
41
  {
42
    throw std::runtime_error( "Invalid expression" );
×
43
  }
44

45
  EvaluationVisitor visitor( exec, script );
14✔
46

47
  auto expression_node = _expression_builder.expression( unit->expression() );
14✔
48
  expression_node->accept( visitor );
14✔
49

50
  return visitor.result();
28✔
51
}
14✔
52

53
EvaluationVisitor::EvaluationVisitor( Executor* exec, EScriptProgram* script )
14✔
54
    : _exec( exec ), _script( script )
14✔
55
{
56
}
14✔
57

58
void EvaluationVisitor::visit_identifier( Identifier& identifier )
12✔
59
{
60
  visit_children( identifier );
12✔
61
  BObjectRefVec::const_iterator itr = _exec->Globals2->begin(), end = _exec->Globals2->end();
12✔
62
  BObjectRef result;
12✔
63

64
  if ( !identifier.scoped_name.scope.empty() )
12✔
65
    throw_invalid_expression();
×
66

67
  auto name = identifier.name();
12✔
68

69
  unsigned block = _script->dbg_ins_blocks[_exec->PC];
12✔
70
  size_t left = _exec->Locals2->size();
12✔
71

72
  while ( left )
23✔
73
  {
74
    while ( left <= _script->blocks[block].parentvariables )
25✔
75
    {
76
      block = _script->blocks[block].parentblockidx;
10✔
77
    }
78
    size_t varidx = left - 1 - _script->blocks[block].parentvariables;
15✔
79
    if ( _script->blocks[block].localvarnames[varidx] == name )
15✔
80
    {
81
      stack.push( ( *_exec->Locals2 )[left - 1] );
4✔
82
      return;
4✔
83
    }
84
    --left;
11✔
85
  }
86

87
  // Then check globals
88
  for ( unsigned idx = 0; itr != end; ++itr, ++idx )
31✔
89
  {
90
    if ( _script->globalvarnames.size() > idx && _script->globalvarnames[idx] == name )
31✔
91
    {
92
      stack.push( ( *_exec->Globals2 )[idx] );
8✔
93
      return;
8✔
94
    }
95
  }
96

97
  throw std::runtime_error( "Unknown variable " + name );
×
98
}
12✔
99

100
void EvaluationVisitor::visit_float_value( FloatValue& node )
1✔
101
{
102
  stack.push( BObjectRef( new Double( node.value ) ) );
1✔
103
}
1✔
104

105
void EvaluationVisitor::visit_string_value( StringValue& node )
×
106
{
107
  stack.push( BObjectRef( new String( node.value ) ) );
×
108
}
×
109

110
void EvaluationVisitor::visit_integer_value( IntegerValue& node )
1✔
111
{
112
  stack.push( BObjectRef( new BLong( node.value ) ) );
1✔
113
}
1✔
114

115
void EvaluationVisitor::visit_boolean_value( BooleanValue& node )
×
116
{
117
  stack.push( BObjectRef( new BBoolean( node.value ) ) );
×
118
}
×
119

120
void EvaluationVisitor::visit_uninitialized_value( UninitializedValue& )
×
121
{
NEW
122
  stack.emplace( UninitObject::create() );
×
123
}
×
124

125
// Operators
126
void EvaluationVisitor::visit_member_access( MemberAccess& member_access )
×
127
{
128
  visit_children( member_access );
×
129

130
  if ( member_access.known_member )
×
131
  {
132
    BObjectRef& leftref = stack.top();
×
133

134
    BObject& left = *leftref;
×
135
    leftref = left->get_member_id( member_access.known_member->id );
×
136
  }
137
  else
138
  {
139
    BObjectRef& leftref = stack.top();
×
140

141
    BObject& left = *leftref;
×
142
    leftref = left->get_member( member_access.name.c_str() );
×
143
  }
144
}
×
145

146
void EvaluationVisitor::visit_element_access( ElementAccess& acc )
×
147
{
148
  visit_children( acc );
×
149
  auto indices_count = static_cast<unsigned>( acc.indexes().children.size() );
×
150
  if ( indices_count == 1 )
×
151
  {
152
    BObjectRef rightref = stack.top();
×
153
    stack.pop();
×
154
    BObjectRef& leftref = stack.top();
×
155

156
    leftref = ( *leftref )->OperSubscript( *rightref );
×
157
  }
×
158
  else
159
  {
160
    std::stack<BObjectRef> indices;
×
161
    for ( size_t i = 0; i < indices_count; ++i )
×
162
    {
163
      indices.push( stack.top() );
×
164
      stack.pop();
×
165
    }
166

167
    BObjectRef& leftref = stack.top();
×
168
    leftref = ( *leftref )->OperMultiSubscript( indices );
×
169
  }
×
170
}
×
171

172
void EvaluationVisitor::visit_argument( Argument& )
×
173
{
174
  throw_invalid_expression();
×
175
}
×
176

177
void EvaluationVisitor::visit_array_initializer( ArrayInitializer& )
×
178
{
179
  throw_invalid_expression();
×
180
}
×
181

182
void EvaluationVisitor::visit_binary_operator( BinaryOperator& )
×
183
{
184
  throw_invalid_expression();
×
185
}
×
186

187
void EvaluationVisitor::visit_dictionary_entry( DictionaryEntry& )
×
188
{
189
  throw_invalid_expression();
×
190
}
×
191

192
void EvaluationVisitor::visit_element_assignment( ElementAssignment& )
×
193
{
194
  throw_invalid_expression();
×
195
}
×
196

197
void EvaluationVisitor::visit_elvis_operator( ElvisOperator& )
×
198
{
199
  throw_invalid_expression();
×
200
}
×
201

202
void EvaluationVisitor::visit_error_initializer( ErrorInitializer& )
×
203
{
204
  throw_invalid_expression();
×
205
}
×
206

207
void EvaluationVisitor::visit_member_assignment( MemberAssignment& )
×
208
{
209
  throw_invalid_expression();
×
210
}
×
211

212
void EvaluationVisitor::visit_member_assignment_by_operator( MemberAssignmentByOperator& )
×
213
{
214
  throw_invalid_expression();
×
215
}
×
216

217
void EvaluationVisitor::visit_method_call( MethodCall& )
×
218
{
219
  throw_invalid_expression();
×
220
}
×
221

222
void EvaluationVisitor::visit_method_call_argument_list( MethodCallArgumentList& )
×
223
{
224
  throw_invalid_expression();
×
225
}
×
226

227
void EvaluationVisitor::visit_interpolate_string( InterpolateString& )
×
228
{
229
  throw_invalid_expression();
×
230
}
×
231

232
void EvaluationVisitor::visit_format_expression( FormatExpression& )
×
233
{
234
  throw_invalid_expression();
×
235
}
×
236

237
void EvaluationVisitor::visit_struct_initializer( StructInitializer& )
×
238
{
239
  throw_invalid_expression();
×
240
}
×
241

242
void EvaluationVisitor::visit_struct_member_initializer( StructMemberInitializer& )
×
243
{
244
  throw_invalid_expression();
×
245
}
×
246

247
void EvaluationVisitor::visit_unary_operator( UnaryOperator& )
×
248
{
249
  throw_invalid_expression();
×
250
}
×
251

252
void EvaluationVisitor::visit_function_call( FunctionCall& )
×
253
{
254
  throw_invalid_expression();
×
255
}
×
256

257
void EvaluationVisitor::visit_function_reference( FunctionReference& )
×
258
{
259
  throw_invalid_expression();
×
260
}
×
261

262
void EvaluationVisitor::visit_variable_assignment_statement( VariableAssignmentStatement& )
×
263
{
264
  throw_invalid_expression();
×
265
}
×
266

267
void EvaluationVisitor::visit_conditional_operator( ConditionalOperator& )
×
268
{
269
  throw_invalid_expression();
×
270
}
×
271

272
BObjectRef& EvaluationVisitor::result()
14✔
273
{
274
  if ( stack.empty() )
14✔
275
  {
276
    throw std::runtime_error( "Error evaluating expression (empty result?)" );
×
277
  }
278

279
  return stack.top();
14✔
280
}
281

282
void EvaluationVisitor::throw_invalid_expression() const
×
283
{
284
  throw std::runtime_error( "Unsupported expression" );
×
285
}
286

287
}  // 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