• 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.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,211✔
28
    : em_cache( em_cache ), inc_cache( inc_cache ), profile( profile )
3,211✔
29
{
30
}
3,211✔
31

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

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

UNCOV
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 )
132✔
76
{
77
  if ( output )
132✔
78
  {
79
    std::ofstream ofs( pathname );
132✔
80
    for ( auto& r : output->source_file_identifiers )
1,089✔
81
    {
82
      ofs << r->pathname << "\n";
957✔
83
    }
84
  }
132✔
85
}
132✔
86

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

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

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

102
    compile_file_steps( pathname, report );
2,551✔
103
    display_outcome( pathname, report );
2,549✔
104

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

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

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

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

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

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

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

142
  output = generate( std::move( workspace ), report );
2,237✔
143
}
2,549✔
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✔
UNCOV
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✔
UNCOV
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
UNCOV
163
    INFO_PRINTLN( formatted );
×
164
  return true;
660✔
165
}
660✔
166

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

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

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

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

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

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

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

224
void Compiler::display_outcome( const std::string& filename, Report& report )
2,549✔
225
{
226
  auto msg = fmt::format( "{}: {} errors", filename, report.error_count() );
2,549✔
227
  if ( compilercfg.DisplayWarnings || compilercfg.ErrorOnWarning )
2,549✔
228
    msg += fmt::format( ", {} warnings", report.warning_count() );
5,098✔
229
  INFO_PRINTLN( msg + '.' );
2,549✔
230
}
2,549✔
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