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

polserver / polserver / 12956160445

24 Jan 2025 07:20PM UTC coverage: 58.017% (+0.05%) from 57.971%
12956160445

push

github

web-flow
moved remaining eprog2/3 methods to eprog (#752)

simplified Token

21 of 65 new or added lines in 4 files covered. (32.31%)

13 existing lines in 5 files now uncovered.

41375 of 71315 relevant lines covered (58.02%)

398443.96 hits per line

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

54.22
/pol-core/bscript/eprog.cpp
1
/** @file
2
 *
3
 * @par History
4
 */
5

6
#include "eprog.h"
7

8
#include <cstdio>
9

10
#include "../clib/refptr.h"
11
#include "../clib/stlutil.h"
12
#include "escriptv.h"
13
#include "fmodule.h"
14

15
namespace Pol
16
{
17
namespace Bscript
18
{
19
EScriptProgram::EScriptProgram()
1,293✔
20
    : ref_counted(),
21
      nglobals( 0 ),
1,293✔
22
      expectedArgs( 0 ),
1,293✔
23
      haveProgram( false ),
1,293✔
24
      name( "" ),
1,293✔
25
      modules(),
1,293✔
26
      tokens(),
1,293✔
27
      symbols(),
1,293✔
28
      exported_functions(),
1,293✔
29
      version( 0 ),
1,293✔
30
      invocations( 0 ),
1,293✔
31
      instr_cycles( 0 ),
1,293✔
32
      pkg( nullptr ),
1,293✔
33
      instr(),
1,293✔
34
      debug_loaded( false ),
1,293✔
35
      globalvarnames(),
1,293✔
36
      blocks(),
1,293✔
37
      dbg_functions(),
1,293✔
38
      dbg_filenames(),
1,293✔
39
      dbg_filenum(),
1,293✔
40
      dbg_linenum(),
1,293✔
41
      dbg_ins_blocks(),
1,293✔
42
      dbg_ins_statementbegin()
3,879✔
43
{
44
  ++escript_program_count;
1,293✔
45

46
  // compiler only:
47
  EPDbgBlock block;
1,293✔
48
  block.parentblockidx = 0;
1,293✔
49
  block.parentvariables = 0;
1,293✔
50
  blocks.push_back( block );
1,293✔
51
}
1,293✔
52

53
EScriptProgram::~EScriptProgram()
2,406✔
54
{
55
  Clib::delete_all( modules );
1,203✔
56
  --escript_program_count;
1,203✔
57
}
2,406✔
58

NEW
59
std::string EScriptProgram::dbg_get_instruction( size_t atPC ) const
×
60
{
NEW
61
  OSTRINGSTREAM os;
×
NEW
62
  os << instr[atPC].token;
×
NEW
63
  return OSTRINGSTREAM_STR( os );
×
NEW
64
}
×
65

66
size_t EScriptProgram::sizeEstimate() const
194✔
67
{
68
  using namespace Clib;
69
  size_t size = sizeof( EScriptProgram );
194✔
70
  size += memsize( globalvarnames );
194✔
71
  for ( const auto& l : globalvarnames )
208✔
72
    size += l.capacity();
14✔
73
  size += memsize( dbg_filenames );
194✔
74
  for ( const auto& l : dbg_filenames )
206✔
75
    size += l.capacity();
12✔
76
  size += memsize( dbg_filenum ) + memsize( dbg_linenum ) + memsize( dbg_ins_blocks ) +
194✔
77
          memsize( dbg_ins_statementbegin ) + memsize( modules ) + memsize( exported_functions ) +
194✔
78
          memsize( instr ) + memsize( blocks ) + memsize( dbg_functions );
194✔
79

80
  return size;
194✔
81
}
82

NEW
83
void EScriptProgram::dump( std::ostream& os )
×
84
{
NEW
85
  Token token;
×
86
  unsigned PC;
NEW
87
  if ( !exported_functions.empty() )
×
88
  {
NEW
89
    os << "Exported Functions:" << std::endl;
×
NEW
90
    os << "   PC  Args  Name" << std::endl;
×
NEW
91
    for ( auto& elem : exported_functions )
×
92
    {
NEW
93
      os << std::setw( 5 ) << elem.PC << std::setw( 6 ) << elem.nargs << "  " << elem.name
×
NEW
94
         << std::endl;
×
95
    }
96
  }
NEW
97
  unsigned nLines = tokens.length() / sizeof( StoredToken );
×
NEW
98
  for ( PC = 0; PC < nLines; PC++ )
×
99
  {
NEW
100
    if ( _readToken( token, PC ) )
×
101
    {
NEW
102
      return;
×
103
    }
104
    else
105
    {
NEW
106
      os << PC << ": " << token << std::endl;
×
NEW
107
      if ( token.id == INS_CASEJMP )
×
108
      {
NEW
109
        dump_casejmp( os, token );
×
110
      }
111
    }
112
  }
NEW
113
}
×
114

NEW
115
void EScriptProgram::dump_casejmp( std::ostream& os, const Token& token )
×
116
{
NEW
117
  const unsigned char* dataptr = token.dataptr;
×
118
  for ( ;; )
119
  {
120
    unsigned short offset;
NEW
121
    std::memcpy( &offset, dataptr, sizeof( unsigned short ) );
×
NEW
122
    dataptr += 2;
×
NEW
123
    unsigned char type = *dataptr;
×
NEW
124
    dataptr += 1;
×
NEW
125
    if ( type == CASE_TYPE_LONG )
×
126
    {
127
      int lval;
NEW
128
      std::memcpy( &lval, dataptr, sizeof( int ) );
×
NEW
129
      dataptr += 4;
×
NEW
130
      os << "\t" << lval << ": @" << offset << std::endl;
×
131
    }
NEW
132
    else if ( type == CASE_TYPE_DEFAULT )
×
133
    {
NEW
134
      os << "\tdefault: @" << offset << std::endl;
×
NEW
135
      break;
×
136
    }
137
    else
138
    {  // type is the length of the string, otherwise
NEW
139
      os << "\t\"" << std::string( (const char*)dataptr, type ) << "\": @" << offset << std::endl;
×
NEW
140
      dataptr += type;
×
141
    }
NEW
142
  }
×
NEW
143
}
×
144
}  // namespace Bscript
145
}  // namespace Pol
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