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

polserver / polserver / 21100551564

17 Jan 2026 08:40PM UTC coverage: 60.504% (+0.01%) from 60.492%
21100551564

Pull #857

github

turleypol
fixed scope
Pull Request #857: ClangTidy readability-else-after-return

837 of 1874 new or added lines in 151 files covered. (44.66%)

48 existing lines in 26 files now uncovered.

44445 of 73458 relevant lines covered (60.5%)

515341.61 hits per line

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

92.03
/pol-core/bscript/compiler/Compiler.cpp
1
#include "Compiler.h"
2

3
#include "bscript/compiler/Profile.h"
4
#include "bscript/compiler/Report.h"
5
#include "bscript/compiler/analyzer/Disambiguator.h"
6
#include "bscript/compiler/analyzer/SemanticAnalyzer.h"
7
#include "bscript/compiler/analyzer/ShortCircuitWarning.h"
8
#include "bscript/compiler/ast/TopLevelStatements.h"
9
#include "bscript/compiler/astbuilder/CompilerWorkspaceBuilder.h"
10
#include "bscript/compiler/codegen/CodeGenerator.h"
11
#include "bscript/compiler/file/PrettifyBuilder.h"
12
#include "bscript/compiler/file/SourceFileCache.h"
13
#include "bscript/compiler/file/SourceFileIdentifier.h"
14
#include "bscript/compiler/format/CompiledScriptSerializer.h"
15
#include "bscript/compiler/format/DebugStoreSerializer.h"
16
#include "bscript/compiler/format/ListingWriter.h"
17
#include "bscript/compiler/model/CompilerWorkspace.h"
18
#include "bscript/compiler/optimizer/Optimizer.h"
19
#include "bscript/compiler/representation/CompiledScript.h"
20
#include "clib/fileutil.h"
21
#include "clib/logfacility.h"
22
#include "clib/timer.h"
23
#include "compilercfg.h"
24

25
namespace Pol::Bscript::Compiler
26
{
27
Compiler::Compiler( SourceFileCache& em_cache, SourceFileCache& inc_cache, Profile& profile )
3,208✔
28
    : em_cache( em_cache ), inc_cache( inc_cache ), profile( profile )
3,208✔
29
{
30
}
3,208✔
31

32
Compiler::~Compiler() = default;
3,208✔
33

34
bool Compiler::write_ecl( const std::string& pathname )
2,235✔
35
{
36
  if ( output )
2,235✔
37
  {
38
    CompiledScriptSerializer( *output ).write( pathname );
2,235✔
39
    return true;
2,235✔
40
  }
41

NEW
42
  return false;
×
43
}
44

45
void Compiler::write_listing( const std::string& pathname )
1,985✔
46
{
47
  if ( output )
1,985✔
48
  {
49
    std::ofstream ofs( pathname );
1,985✔
50
    ListingWriter( *output ).write( ofs );
1,985✔
51
  }
1,985✔
52
}
1,985✔
53

54
void Compiler::write_string_tree( const std::string& pathname )
8✔
55
{
56
  if ( output )
8✔
57
  {
58
    std::ofstream ofs( pathname );
8✔
59
    ofs << output->tree;
8✔
60
  }
8✔
61
}
8✔
62

63
void Compiler::write_dbg( const std::string& pathname, bool include_debug_text )
2,105✔
64
{
65
  if ( output )
2,105✔
66
  {
67
    std::ofstream ofs( pathname, std::ofstream::binary );
2,105✔
68
    auto text_ofs = include_debug_text ? std::make_unique<std::ofstream>( pathname + ".txt" )
2,105✔
69
                                       : std::unique_ptr<std::ofstream>();
2,105✔
70

71
    DebugStoreSerializer( *output ).write( ofs, text_ofs.get() );
2,105✔
72
  }
2,105✔
73
}
2,105✔
74

75
void Compiler::write_included_filenames( const std::string& pathname )
130✔
76
{
77
  if ( output )
130✔
78
  {
79
    std::ofstream ofs( pathname );
130✔
80
    for ( auto& r : output->source_file_identifiers )
1,062✔
81
    {
82
      ofs << r->pathname << "\n";
932✔
83
    }
84
  }
130✔
85
}
130✔
86

87
void Compiler::set_include_compile_mode()
×
88
{
89
  user_function_inclusion = UserFunctionInclusion::All;
×
90
}
×
91

92
bool Compiler::compile_file( const std::string& filename )
2,548✔
93
{
94
  bool success;
95
  try
96
  {
97
    auto pathname = Clib::FullPath( filename.c_str() );
2,548✔
98

99
    Report report( compilercfg.DisplayWarnings || compilercfg.ErrorOnWarning,
2,548✔
100
                   true /* display errors */, compilercfg.DisplayDebugs );
5,096✔
101

102
    compile_file_steps( pathname, report );
2,548✔
103
    display_outcome( pathname, report );
2,546✔
104

105
    bool have_warning_as_error = report.warning_count() && compilercfg.ErrorOnWarning;
2,546✔
106
    success = !report.error_count() && !have_warning_as_error;
2,546✔
107
  }
2,548✔
108
  catch ( std::exception& ex )
2✔
109
  {
110
    ERROR_PRINTLN( ex.what() );
2✔
111
    success = false;
2✔
112
  }
2✔
113
  return success;
2,548✔
114
}
115

116
void Compiler::compile_file_steps( const std::string& pathname, Report& report )
2,548✔
117
{
118
  std::unique_ptr<CompilerWorkspace> workspace = build_workspace( pathname, report );
2,548✔
119
  if ( report.error_count() )
2,546✔
120
    return;
139✔
121

122
  register_constants( *workspace, report );
2,407✔
123
  if ( report.error_count() )
2,407✔
124
    return;
2✔
125

126
  optimize( *workspace, report );
2,405✔
127
  if ( report.error_count() )
2,405✔
128
    return;
10✔
129

130
  disambiguate( *workspace, report );
2,395✔
131
  if ( report.error_count() )
2,395✔
132
    return;
×
133

134
  analyze( *workspace, report );
2,395✔
135
  if ( report.error_count() )
2,395✔
136
    return;
160✔
137

138
  check_short_circuit( *workspace, report );
2,235✔
139
  if ( report.error_count() )
2,235✔
140
    return;
×
141

142
  output = generate( std::move( workspace ), report );
2,235✔
143
}
2,546✔
144

145
bool Compiler::format_file( const std::string& filename, bool is_module, bool inplace )
660✔
146
{
147
  if ( !Clib::filesize( filename.c_str() ) )
660✔
148
    return true;
×
149

150
  Report report( false, true );
660✔
151
  PrettifyBuilder prettify_builder( profile, report );
660✔
152
  auto formatted = prettify_builder.build( filename, is_module );
660✔
153
  if ( report.error_count() )
660✔
154
    return false;
×
155
  if ( inplace )
660✔
156
  {
157
    std::ofstream filestream;
660✔
158
    filestream.open( filename, std::ios_base::out | std::ios_base::trunc | std::ios::binary );
660✔
159
    filestream << formatted;
660✔
160
    filestream.flush();
660✔
161
  }
660✔
162
  else
163
    INFO_PRINTLN( formatted );
×
164
  return true;
660✔
165
}
660✔
166

167
std::unique_ptr<CompilerWorkspace> Compiler::build_workspace( const std::string& pathname,
2,548✔
168
                                                              Report& report )
169
{
170
  Pol::Tools::HighPerfTimer timer;
2,548✔
171
  CompilerWorkspaceBuilder workspace_builder( em_cache, inc_cache, profile, report );
2,548✔
172
  auto workspace = workspace_builder.build( pathname, user_function_inclusion );
2,548✔
173
  profile.build_workspace_micros += timer.ellapsed().count();
2,546✔
174
  return workspace;
5,092✔
175
}
×
176

177
void Compiler::register_constants( CompilerWorkspace& workspace, Report& report )
2,407✔
178
{
179
  Pol::Tools::HighPerfTimer timer;
2,407✔
180
  SemanticAnalyzer::register_const_declarations( workspace, report );
2,407✔
181
  profile.register_const_declarations_micros += timer.ellapsed().count();
2,407✔
182
}
2,407✔
183

184
void Compiler::optimize( CompilerWorkspace& workspace, Report& report )
2,405✔
185
{
186
  Pol::Tools::HighPerfTimer timer;
2,405✔
187
  Optimizer optimizer( workspace.constants, report );
2,405✔
188
  optimizer.optimize( workspace, user_function_inclusion );
2,405✔
189
  profile.optimize_micros += timer.ellapsed().count();
2,405✔
190
}
2,405✔
191

192
void Compiler::disambiguate( CompilerWorkspace& workspace, Report& report )
2,395✔
193
{
194
  Pol::Tools::HighPerfTimer timer;
2,395✔
195
  Disambiguator disambiguator( workspace.constants, report );
2,395✔
196
  disambiguator.disambiguate( workspace );
2,395✔
197
  profile.disambiguate_micros += timer.ellapsed().count();
2,395✔
198
}
2,395✔
199

200
void Compiler::analyze( CompilerWorkspace& workspace, Report& report )
2,395✔
201
{
202
  Pol::Tools::HighPerfTimer timer;
2,395✔
203
  SemanticAnalyzer analyzer( workspace, report );
2,395✔
204
  analyzer.analyze();
2,395✔
205
  profile.analyze_micros += timer.ellapsed().count();
2,395✔
206
}
2,395✔
207

208
void Compiler::check_short_circuit( CompilerWorkspace& workspace, Report& report )
2,235✔
209
{
210
  ShortCircuitWarning warn{ report };
2,235✔
211
  warn.warn( workspace );
2,235✔
212
}
2,235✔
213

214
std::unique_ptr<CompiledScript> Compiler::generate( std::unique_ptr<CompilerWorkspace> workspace,
2,235✔
215
                                                    Report& report )
216
{
217
  Pol::Tools::HighPerfTimer codegen_timer;
2,235✔
218
  auto compiled_script = CodeGenerator::generate( std::move( workspace ), report,
2,235✔
219
                                                  compilercfg.GenerateAbstractSyntaxTree );
2,235✔
220
  profile.codegen_micros += codegen_timer.ellapsed().count();
2,235✔
221
  return compiled_script;
4,470✔
222
}
×
223

224
void Compiler::display_outcome( const std::string& filename, Report& report )
2,546✔
225
{
226
  auto msg = fmt::format( "{}: {} errors", filename, report.error_count() );
2,546✔
227
  if ( compilercfg.DisplayWarnings || compilercfg.ErrorOnWarning )
2,546✔
228
    msg += fmt::format( ", {} warnings", report.warning_count() );
5,092✔
229
  INFO_PRINTLN( msg + '.' );
2,546✔
230
}
2,546✔
231

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