• 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.96
/pol-core/bscript/compiler/astbuilder/CompilerWorkspaceBuilder.cpp
1
#include "CompilerWorkspaceBuilder.h"
2

3
#include "bscript/compiler/Profile.h"
4
#include "bscript/compiler/Report.h"
5
#include "bscript/compiler/ast/ClassDeclaration.h"
6
#include "bscript/compiler/ast/GeneratedFunction.h"
7
#include "bscript/compiler/ast/ModuleFunctionDeclaration.h"
8
#include "bscript/compiler/ast/Program.h"
9
#include "bscript/compiler/ast/Statement.h"
10
#include "bscript/compiler/ast/TopLevelStatements.h"
11
#include "bscript/compiler/ast/UserFunction.h"
12
#include "bscript/compiler/astbuilder/AvailableParseTree.h"
13
#include "bscript/compiler/astbuilder/BuilderWorkspace.h"
14
#include "bscript/compiler/astbuilder/GeneratedFunctionBuilder.h"
15
#include "bscript/compiler/astbuilder/SourceFileProcessor.h"
16
#include "bscript/compiler/astbuilder/UserFunctionVisitor.h"
17
#include "bscript/compiler/file/SourceFile.h"
18
#include "bscript/compiler/file/SourceFileIdentifier.h"
19
#include "bscript/compiler/file/SourceLocation.h"
20
#include "bscript/compiler/model/CompilerWorkspace.h"
21
#include "bscript/compiler/model/ScopeName.h"
22
#include "clib/timer.h"
23

24
namespace Pol::Bscript::Compiler
25
{
26
CompilerWorkspaceBuilder::CompilerWorkspaceBuilder( SourceFileCache& em_cache,
2,551✔
27
                                                    SourceFileCache& inc_cache, Profile& profile,
28
                                                    Report& report )
2,551✔
29
    : em_cache( em_cache ), inc_cache( inc_cache ), profile( profile ), report( report )
2,551✔
30
{
31
}
2,551✔
32

33
std::unique_ptr<CompilerWorkspace> CompilerWorkspaceBuilder::build(
2,551✔
34
    const std::string& pathname, UserFunctionInclusion user_function_inclusion )
35
{
36
  auto compiler_workspace = std::make_unique<CompilerWorkspace>( report );
2,551✔
37
  BuilderWorkspace workspace( *compiler_workspace, em_cache, inc_cache, profile, report );
2,551✔
38

39
  auto ident = std::make_unique<SourceFileIdentifier>( 0, pathname );
2,551✔
40

41
  SourceLocation source_location( ident.get(), 0, 0 );
2,551✔
42

43
  if ( SourceFile::enforced_case_sensitivity_mismatch( source_location, pathname, report ) )
2,551✔
44
  {
45
    report.error( *ident, "Refusing to load '{}'.", pathname );
×
UNCOV
46
    return {};
×
47
  }
48

49
  auto sf = SourceFile::load( *ident, profile, report );
2,551✔
50

51
  if ( !sf || report.error_count() )
2,551✔
52
  {
53
    report.error( *ident, "Unable to load '{}'.", pathname );
×
UNCOV
54
    return {};
×
55
  }
56

57
  SourceFileProcessor src_processor( *ident, workspace, true, user_function_inclusion );
2,551✔
58

59
  workspace.compiler_workspace.referenced_source_file_identifiers.push_back( std::move( ident ) );
2,551✔
60
  workspace.source_files[sf->pathname] = sf;
2,551✔
61

62
  compiler_workspace->top_level_statements =
2,551✔
63
      std::make_unique<TopLevelStatements>( source_location );
5,102✔
64

65
  src_processor.use_module( "basic", source_location );
2,551✔
66
  src_processor.use_module( "basicio", source_location );
2,551✔
67
  src_processor.process_source( *sf );
2,551✔
68

69
  if ( report.error_count() == 0 )
2,549✔
70
    build_referenced_user_functions( workspace );
2,419✔
71

72
  return compiler_workspace;
2,549✔
73
}
2,559✔
74

75

76
void CompilerWorkspaceBuilder::build_referenced_user_functions( BuilderWorkspace& workspace )
2,419✔
77
{
78
  Pol::Tools::HighPerfTimer timer;
2,419✔
79

80
  std::vector<std::unique_ptr<AvailableSecondPassTarget>> to_build;
2,419✔
81
  std::vector<std::unique_ptr<GeneratedFunction>> generated_functions;
2,419✔
82

83
  int resolves_done = 0;
2,419✔
84
  while ( workspace.function_resolver.resolve( to_build ) )
4,325✔
85
  {
86
    Pol::Tools::HighPerfTimer resolve_timer;
1,906✔
87
    ++resolves_done;
1,906✔
88
    report.debug( *workspace.compiler_workspace.top_level_statements, "Resolution {} starting.",
1,906✔
89
                  resolves_done );
90

91
    for ( auto& target : to_build )
6,213✔
92
    {
93
      report.debug( *workspace.compiler_workspace.top_level_statements, "Resolving {}", *target );
4,307✔
94
      if ( target->type == AvailableSecondPassTarget::Type::ParseTree )
4,307✔
95
      {
96
        auto apt = static_cast<AvailableParseTree*>( target.get() );
4,130✔
97
        UserFunctionVisitor user_function_visitor( *apt->source_location.source_file_identifier,
4,130✔
98
                                                   workspace, apt->scope.string(), apt->context );
4,130✔
99

100
        apt->parse_rule_context->accept( &user_function_visitor );
4,130✔
101
      }
4,130✔
102
      else if ( target->type == AvailableSecondPassTarget::Type::GeneratedFunction )
177✔
103
      {
104
        auto agf = static_cast<AvailableGeneratedFunction*>( target.get() );
177✔
105
        auto cd = static_cast<ClassDeclaration*>( agf->context );
177✔
106
        auto name = agf->type == UserFunctionType::Super ? Compiler::SUPER : cd->name;
177✔
107

108
        auto generated_func =
109
            std::make_unique<GeneratedFunction>( cd->source_location, cd, agf->type, name );
177✔
110
        workspace.function_resolver.register_user_function( cd->name, generated_func.get() );
177✔
111

112
        generated_functions.push_back( std::move( generated_func ) );
177✔
113
      }
177✔
114
    }
115
    report.debug( *workspace.compiler_workspace.top_level_statements,
1,906✔
116
                  "Resolution {} complete with {} parse trees in {} micros.", resolves_done,
117
                  to_build.size(), resolve_timer.ellapsed().count() );
1,906✔
118
    to_build.clear();
1,906✔
119
  };
120

121
  // We must build the generated functions _after_ the AST resolution: generated
122
  // functions reference class links.
123
  for ( auto& function : generated_functions )
2,596✔
124
  {
125
    GeneratedFunctionBuilder tree_builder( *function->source_location.source_file_identifier,
177✔
126
                                           workspace );
177✔
127

128
    if ( function->type == UserFunctionType::Super )
177✔
129
      tree_builder.super_function( function );
151✔
130
    else if ( function->type == UserFunctionType::Constructor )
26✔
131
      tree_builder.constructor_function( function );
26✔
132
    else
UNCOV
133
      function->internal_error( "unknown UserFunctionType" );
×
134

135
    report.debug( *workspace.compiler_workspace.top_level_statements,
177✔
136
                  "Generated function {} takes {} params", function->name,
177✔
137
                  function->parameter_count() );
177✔
138

139
    workspace.compiler_workspace.user_functions.push_back( std::move( function ) );
177✔
140
  }
177✔
141

142
  workspace.profile.ast_resolve_functions_micros += timer.ellapsed().count();
2,419✔
143
}
2,419✔
144

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