Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
dart::kernel::KernelLineStartsReader Class Reference

#include <kernel.h>

Public Member Functions

 KernelLineStartsReader (const dart::TypedData &line_starts_data, dart::Zone *zone)
 
 ~KernelLineStartsReader ()
 
uint32_t At (intptr_t index) const
 
uint32_t MaxPosition () const
 
DART_WARN_UNUSED_RESULT bool LocationForPosition (intptr_t position, intptr_t *line, intptr_t *col=nullptr) const
 
DART_WARN_UNUSED_RESULT bool TokenRangeAtLine (intptr_t line_number, dart::TokenPosition *first_token_index, dart::TokenPosition *last_token_index) const
 

Detailed Description

Definition at line 130 of file kernel.h.

Constructor & Destructor Documentation

◆ KernelLineStartsReader()

dart::kernel::KernelLineStartsReader::KernelLineStartsReader ( const dart::TypedData line_starts_data,
dart::Zone zone 
)

Definition at line 21 of file kernel.cc.

24 : line_starts_data_(line_starts_data) {
25 TypedDataElementType type = line_starts_data_.ElementType();
26 if (type == kUint16ArrayElement) {
27 helper_ = new KernelUint16LineStartsHelper();
28 } else if (type == kUint32ArrayElement) {
29 helper_ = new KernelUint32LineStartsHelper();
30 } else {
32 }
33}
#define UNREACHABLE()
Definition: assert.h:248
GLenum type
TypedDataElementType ElementType() const
Definition: object.h:11527
TypedDataElementType
Definition: raw_object.h:124

◆ ~KernelLineStartsReader()

dart::kernel::KernelLineStartsReader::~KernelLineStartsReader ( )
inline

Definition at line 135 of file kernel.h.

135{ delete helper_; }

Member Function Documentation

◆ At()

uint32_t dart::kernel::KernelLineStartsReader::At ( intptr_t  index) const
inline

Definition at line 137 of file kernel.h.

137 {
138 return helper_->At(line_starts_data_, index);
139 }

◆ LocationForPosition()

bool dart::kernel::KernelLineStartsReader::LocationForPosition ( intptr_t  position,
intptr_t *  line,
intptr_t *  col = nullptr 
) const

Definition at line 43 of file kernel.cc.

45 {
46 const intptr_t line_count = line_starts_data_.Length();
47 if (position < 0 || static_cast<uint32_t>(position) > MaxPosition() ||
48 line_count == 0) {
49 return false;
50 }
51
52 intptr_t lo = 0;
53 intptr_t hi = line_count;
54 while (hi > lo + 1) {
55 const intptr_t mid = lo + (hi - lo) / 2;
56 const intptr_t mid_position = helper_->At(line_starts_data_, mid);
57 if (mid_position > position) {
58 hi = mid;
59 } else {
60 lo = mid;
61 }
62 }
63 *line = lo + 1;
64 if (col != nullptr) {
65 *col = position - helper_->At(line_starts_data_, lo) + 1;
66 }
67
68 return true;
69}
intptr_t Length() const
Definition: object.h:11518

◆ MaxPosition()

uint32_t dart::kernel::KernelLineStartsReader::MaxPosition ( ) const

Definition at line 35 of file kernel.cc.

35 {
36 const intptr_t line_count = line_starts_data_.Length();
37 if (line_count == 0) {
38 return 0;
39 }
40 return helper_->At(line_starts_data_, line_count - 1);
41}

◆ TokenRangeAtLine()

bool dart::kernel::KernelLineStartsReader::TokenRangeAtLine ( intptr_t  line_number,
dart::TokenPosition first_token_index,
dart::TokenPosition last_token_index 
) const

Definition at line 71 of file kernel.cc.

74 {
75 const intptr_t line_count = line_starts_data_.Length();
76 if (line_number <= 0 || line_number > line_count) {
77 return false;
78 }
79 *first_token_index = dart::TokenPosition::Deserialize(
80 helper_->At(line_starts_data_, line_number - 1));
81 if (line_number == line_count) {
82 *last_token_index = *first_token_index;
83 } else {
84 *last_token_index = dart::TokenPosition::Deserialize(
85 helper_->At(line_starts_data_, line_number) - 1);
86 }
87 return true;
88}
static TokenPosition Deserialize(int32_t value)

The documentation for this class was generated from the following files: