Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
dart::Script Class Reference

#include <object.h>

Inheritance diagram for dart::Script:
dart::Object

Public Member Functions

StringPtr url () const
 
void set_url (const String &value) const
 
StringPtr resolved_url () const
 
bool HasSource () const
 
StringPtr Source () const
 
bool IsPartOfDartColonLibrary () const
 
GrowableObjectArrayPtr GenerateLineNumberArray () const
 
intptr_t line_offset () const
 
intptr_t col_offset () const
 
TokenPosition MaxPosition () const
 
int64_t load_timestamp () const
 
void InitializeFromKernel (const KernelProgramInfo &info, intptr_t script_index, const TypedData &line_starts, const TypedDataView &constant_coverage) const
 
intptr_t kernel_script_index () const
 
TypedDataPtr line_starts () const
 
TypedDataViewPtr constant_coverage () const
 
LibraryPtr FindLibrary () const
 
StringPtr GetLine (intptr_t line_number, Heap::Space space=Heap::kNew) const
 
StringPtr GetSnippet (intptr_t from_line, intptr_t from_column, intptr_t to_line, intptr_t to_column) const
 
bool IsValidTokenPosition (TokenPosition token_pos) const
 
bool GetTokenLocation (const TokenPosition &token_pos, intptr_t *line, intptr_t *column=nullptr) const
 
intptr_t GetTokenLength (const TokenPosition &token_pos) const
 
bool TokenRangeAtLine (intptr_t line_number, TokenPosition *first_token_index, TokenPosition *last_token_index) const
 
void LoadSourceFromKernel (const uint8_t *kernel_buffer, intptr_t kernel_buffer_len) const
 
void CollectTokenPositionsFor () const
 
ArrayPtr CollectConstConstructorCoverageFrom () const
 
- Public Member Functions inherited from dart::Object
virtual ~Object ()
 
ObjectPtr ptr () const
 
void operator= (ObjectPtr value)
 
bool IsCanonical () const
 
void SetCanonical () const
 
void ClearCanonical () const
 
bool IsImmutable () const
 
void SetImmutable () const
 
void ClearImmutable () const
 
intptr_t GetClassId () const
 
ClassPtr clazz () const
 
 CLASS_LIST_FOR_HANDLES (DEFINE_CLASS_TESTER)
 
bool IsNull () const
 
virtual const char * ToCString () const
 
void PrintJSON (JSONStream *stream, bool ref=true) const
 
virtual void PrintJSONImpl (JSONStream *stream, bool ref) const
 
void PrintImplementationFields (JSONStream *stream) const
 
virtual void PrintImplementationFieldsImpl (const JSONArray &jsarr_fields) const
 
virtual const char * JSONType () const
 
virtual StringPtr DictionaryName () const
 
bool IsNew () const
 
bool IsOld () const
 
bool InVMIsolateHeap () const
 
void Print () const
 

Static Public Member Functions

static intptr_t line_starts_offset ()
 
static intptr_t InstanceSize ()
 
static ScriptPtr New (const String &url, const String &source)
 
static ScriptPtr New (const String &url, const String &resolved_url, const String &source)
 
- Static Public Member Functions inherited from dart::Object
static ObjectPtr RawCast (ObjectPtr obj)
 
static constexpr bool ContainsCompressedPointers ()
 
static intptr_t tags_offset ()
 
static ObjectHandle ()
 
static ObjectHandle (Zone *zone)
 
static ObjectHandle (ObjectPtr ptr)
 
static ObjectHandle (Zone *zone, ObjectPtr ptr)
 
static ObjectZoneHandle ()
 
static ObjectZoneHandle (Zone *zone)
 
static ObjectZoneHandle (ObjectPtr ptr)
 
static ObjectZoneHandle (Zone *zone, ObjectPtr ptr)
 
static ObjectReadOnlyHandle ()
 
static ObjectPtr null ()
 
static void set_vm_isolate_snapshot_object_table (const Array &table)
 
static ClassPtr class_class ()
 
static ClassPtr dynamic_class ()
 
static ClassPtr void_class ()
 
static ClassPtr type_parameters_class ()
 
static ClassPtr type_arguments_class ()
 
static ClassPtr patch_class_class ()
 
static ClassPtr function_class ()
 
static ClassPtr closure_data_class ()
 
static ClassPtr ffi_trampoline_data_class ()
 
static ClassPtr field_class ()
 
static ClassPtr script_class ()
 
static ClassPtr library_class ()
 
static ClassPtr namespace_class ()
 
static ClassPtr kernel_program_info_class ()
 
static ClassPtr code_class ()
 
static ClassPtr instructions_class ()
 
static ClassPtr instructions_section_class ()
 
static ClassPtr instructions_table_class ()
 
static ClassPtr object_pool_class ()
 
static ClassPtr pc_descriptors_class ()
 
static ClassPtr code_source_map_class ()
 
static ClassPtr compressed_stackmaps_class ()
 
static ClassPtr var_descriptors_class ()
 
static ClassPtr exception_handlers_class ()
 
static ClassPtr context_class ()
 
static ClassPtr context_scope_class ()
 
static ClassPtr sentinel_class ()
 
static ClassPtr api_error_class ()
 
static ClassPtr language_error_class ()
 
static ClassPtr unhandled_exception_class ()
 
static ClassPtr unwind_error_class ()
 
static ClassPtr singletargetcache_class ()
 
static ClassPtr unlinkedcall_class ()
 
static ClassPtr monomorphicsmiablecall_class ()
 
static ClassPtr icdata_class ()
 
static ClassPtr megamorphic_cache_class ()
 
static ClassPtr subtypetestcache_class ()
 
static ClassPtr loadingunit_class ()
 
static ClassPtr weak_serialization_reference_class ()
 
static ClassPtr weak_array_class ()
 
static void InitNullAndBool (IsolateGroup *isolate_group)
 
static void Init (IsolateGroup *isolate_group)
 
static void InitVtables ()
 
static void FinishInit (IsolateGroup *isolate_group)
 
static void FinalizeVMIsolate (IsolateGroup *isolate_group)
 
static void FinalizeReadOnlyObject (ObjectPtr object)
 
static void Cleanup ()
 
static ErrorPtr Init (IsolateGroup *isolate_group, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
 
static void MakeUnusedSpaceTraversable (const Object &obj, intptr_t original_size, intptr_t used_size)
 
static intptr_t InstanceSize ()
 
template<class FakeObject >
static void VerifyBuiltinVtable (intptr_t cid)
 
static void VerifyBuiltinVtables ()
 
static bool ShouldHaveImmutabilityBitSet (classid_t class_id)
 

Friends

class Class
 
class Precompiler
 

Additional Inherited Members

- Public Types inherited from dart::Object
enum  NameVisibility { kInternalName = 0 , kScrubbedName , kUserVisibleName }
 
enum class  NameDisambiguation { kYes , kNo }
 
using UntaggedObjectType = UntaggedObject
 
using ObjectPtrType = ObjectPtr
 
- Static Public Attributes inherited from dart::Object
static constexpr intptr_t kHashBits = 30
 
static const ClassId kClassId = kObjectCid
 
- Protected Member Functions inherited from dart::Object
 Object ()
 
uword raw_value () const
 
void setPtr (ObjectPtr value, intptr_t default_cid)
 
void CheckHandle () const
 
cpp_vtable vtable () const
 
void set_vtable (cpp_vtable value)
 
bool Contains (uword addr) const
 
template<typename type , std::memory_order order = std::memory_order_relaxed>
type LoadPointer (type const *addr) const
 
template<typename type , std::memory_order order = std::memory_order_relaxed>
void StorePointer (type const *addr, type value) const
 
template<typename type , typename compressed_type , std::memory_order order = std::memory_order_relaxed>
void StoreCompressedPointer (compressed_type const *addr, type value) const
 
template<typename type >
void StorePointerUnaligned (type const *addr, type value, Thread *thread) const
 
void StoreSmi (SmiPtr const *addr, SmiPtr value) const
 
template<typename FieldType >
void StoreSimd128 (const FieldType *addr, simd128_value_t value) const
 
template<typename FieldType >
FieldType LoadNonPointer (const FieldType *addr) const
 
template<typename FieldType , std::memory_order order>
FieldType LoadNonPointer (const FieldType *addr) const
 
template<typename FieldType , typename ValueType >
void StoreNonPointer (const FieldType *addr, ValueType value) const
 
template<typename FieldType , typename ValueType , std::memory_order order>
void StoreNonPointer (const FieldType *addr, ValueType value) const
 
template<typename FieldType >
FieldType * UnsafeMutableNonPointer (const FieldType *addr) const
 
 CLASS_LIST (STORE_NON_POINTER_ILLEGAL_TYPE)
 
void UnimplementedMethod () const
 
void AddCommonObjectProperties (JSONObject *jsobj, const char *protocol_type, bool ref) const
 
- Static Protected Member Functions inherited from dart::Object
static DART_NOINLINE ObjectHandleImpl (Zone *zone, ObjectPtr ptr, intptr_t default_cid)
 
static DART_NOINLINE ObjectZoneHandleImpl (Zone *zone, ObjectPtr ptr, intptr_t default_cid)
 
static DART_NOINLINE ObjectReadOnlyHandleImpl (intptr_t cid)
 
static ObjectPtr Allocate (intptr_t cls_id, intptr_t size, Heap::Space space, bool compressed, uword ptr_field_start_offset, uword ptr_field_end_offset)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType Allocate (Heap::Space space)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType Allocate (Heap::Space space, intptr_t elements)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType AllocateVariant (intptr_t class_id, Heap::Space space)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType AllocateVariant (intptr_t class_id, Heap::Space space, intptr_t elements)
 
static constexpr intptr_t RoundedAllocationSize (intptr_t size)
 
static ObjectPtr Clone (const Object &orig, Heap::Space space, bool load_with_relaxed_atomics=false)
 
template<typename T >
static DART_FORCE_INLINE uword from_offset ()
 
template<typename T >
static DART_FORCE_INLINE uword to_offset (intptr_t length=0)
 
- Protected Attributes inherited from dart::Object
ObjectPtr ptr_
 

Detailed Description

Definition at line 4901 of file object.h.

Member Function Documentation

◆ col_offset()

intptr_t dart::Script::col_offset ( ) const
inline

Definition at line 4915 of file object.h.

4915{ return 0; }

◆ CollectConstConstructorCoverageFrom()

ArrayPtr dart::Script::CollectConstConstructorCoverageFrom ( ) const

Definition at line 345 of file kernel.cc.

345 {
346 Thread* thread = Thread::Current();
347 Zone* zone = thread->zone();
348 kernel::TranslationHelper helper(thread);
349
350 const auto& interesting_script = *this;
351
352 const auto& kernel_info =
353 KernelProgramInfo::Handle(zone, kernel_program_info());
354 helper.InitFromKernelProgramInfo(kernel_info);
355
356 const auto& data =
357 TypedDataView::Handle(zone, interesting_script.constant_coverage());
358
359 kernel::KernelReaderHelper kernel_reader(zone, &helper, data, 0);
360
361 // Read "constant coverage constructors".
362 const intptr_t constant_coverage_constructors =
363 kernel_reader.ReadListLength();
364 const Array& constructors =
365 Array::Handle(Array::New(constant_coverage_constructors));
366 for (intptr_t i = 0; i < constant_coverage_constructors; ++i) {
367 kernel::NameIndex kernel_name = kernel_reader.ReadCanonicalNameReference();
368 Class& klass = Class::ZoneHandle(
369 zone,
370 helper.LookupClassByKernelClass(helper.EnclosingName(kernel_name)));
371 const Function& target = Function::ZoneHandle(
372 zone, helper.LookupConstructorByKernelConstructor(klass, kernel_name));
373 constructors.SetAt(i, target);
374 }
375 return constructors.ptr();
376}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10933
static Object & Handle()
Definition object.h:407
static Object & ZoneHandle()
Definition object.h:419
friend class Thread
Definition object.h:1025
friend class Class
Definition object.h:5012
static Thread * Current()
Definition thread.h:361
uint32_t * target
static int8_t data[kExtLength]

◆ CollectTokenPositionsFor()

void dart::Script::CollectTokenPositionsFor ( ) const

Definition at line 223 of file kernel.cc.

223 {
224 Thread* thread = Thread::Current();
225 Zone* zone = thread->zone();
226
227 const auto& kernel_info =
228 KernelProgramInfo::Handle(zone, kernel_program_info());
229
230 kernel::TranslationHelper helper(thread);
231 helper.InitFromKernelProgramInfo(kernel_info);
232
233 GrowableArray<intptr_t> token_positions(10);
234
235 auto isolate_group = thread->isolate_group();
236 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
237 zone, isolate_group->object_store()->libraries());
238 Library& lib = Library::Handle(zone);
239 Object& entry = Object::Handle(zone);
240 Script& entry_script = Script::Handle(zone);
241 auto& data = TypedDataView::Handle(zone);
242
243 auto& interesting_script = *this;
244
245 auto& temp_array = Array::Handle(zone);
246 auto& temp_field = Field::Handle(zone);
247 auto& temp_function = Function::Handle(zone);
248 for (intptr_t i = 0; i < libs.Length(); i++) {
249 lib ^= libs.At(i);
250 lib.EnsureTopLevelClassIsFinalized();
251 DictionaryIterator it(lib);
252 while (it.HasNext()) {
253 entry = it.GetNext();
255 if (entry.IsClass()) {
256 const Class& klass = Class::Cast(entry);
257 if (klass.script() == interesting_script.ptr()) {
258 token_positions.Add(klass.token_pos().Serialize());
259 token_positions.Add(klass.end_token_pos().Serialize());
260 }
261 if (klass.is_finalized()) {
262 temp_array = klass.fields();
263 for (intptr_t i = 0; i < temp_array.Length(); ++i) {
264 temp_field ^= temp_array.At(i);
265 if (temp_field.kernel_offset() <= 0) {
266 // Skip artificially injected fields.
267 continue;
268 }
269 entry_script = temp_field.Script();
270 if (entry_script.ptr() != interesting_script.ptr()) {
271 continue;
272 }
273 data = temp_field.KernelLibrary();
274 CollectKernelLibraryTokenPositions(data, interesting_script,
275 temp_field.kernel_offset(),
276 temp_field.KernelLibraryOffset(),
277 zone, &helper, &token_positions);
278 }
279 temp_array = klass.current_functions();
280 for (intptr_t i = 0; i < temp_array.Length(); ++i) {
281 temp_function ^= temp_array.At(i);
282 entry_script = temp_function.script();
283 if (entry_script.ptr() != interesting_script.ptr()) {
284 continue;
285 }
286 data = temp_function.KernelLibrary();
288 data, interesting_script, temp_function.kernel_offset(),
289 temp_function.KernelLibraryOffset(), zone, &helper,
290 &token_positions);
291 }
292 } else {
293 // Class isn't finalized yet: read the data attached to it.
294 ASSERT(klass.kernel_offset() > 0);
295 data = lib.KernelLibrary();
296 ASSERT(!data.IsNull());
297 const intptr_t library_kernel_offset = lib.KernelLibraryOffset();
298 ASSERT(library_kernel_offset > 0);
299 const intptr_t class_offset = klass.kernel_offset();
300
301 entry_script = klass.script();
302 if (entry_script.ptr() != interesting_script.ptr()) {
303 continue;
304 }
306 data, interesting_script, class_offset, library_kernel_offset,
307 zone, &helper, &token_positions);
308 }
309 } else if (entry.IsFunction()) {
310 temp_function ^= entry.ptr();
311 entry_script = temp_function.script();
312 if (entry_script.ptr() != interesting_script.ptr()) {
313 continue;
314 }
315 data = temp_function.KernelLibrary();
316 CollectKernelLibraryTokenPositions(data, interesting_script,
317 temp_function.kernel_offset(),
318 temp_function.KernelLibraryOffset(),
319 zone, &helper, &token_positions);
320 } else if (entry.IsField()) {
321 const Field& field = Field::Cast(entry);
322 if (field.kernel_offset() <= 0) {
323 // Skip artificially injected fields.
324 continue;
325 }
326 entry_script = field.Script();
327 if (entry_script.ptr() != interesting_script.ptr()) {
328 continue;
329 }
330 data = field.KernelLibrary();
332 data, interesting_script, field.kernel_offset(),
333 field.KernelLibraryOffset(), zone, &helper, &token_positions);
334 }
335 }
336 }
337
338 Script& script = Script::Handle(zone, interesting_script.ptr());
339 Array& array_object = Array::Handle(zone);
340 array_object = kernel::AsSortedDuplicateFreeArray(&token_positions);
341 script.set_debug_positions(array_object);
342}
static ObjectPtr null()
Definition object.h:433
#define ASSERT(E)
static void CollectKernelLibraryTokenPositions(const TypedDataView &kernel_data, const Script &script, intptr_t kernel_offset, intptr_t data_kernel_offset, Zone *zone, TranslationHelper *helper, GrowableArray< intptr_t > *token_positions)
Definition kernel.cc:201
static ArrayPtr AsSortedDuplicateFreeArray(GrowableArray< intptr_t > *source)
Definition kernel.cc:177

◆ constant_coverage()

TypedDataViewPtr dart::Script::constant_coverage ( ) const

Definition at line 13256 of file object.cc.

13256 {
13257 return untag()->constant_coverage();
13258}
raw_obj untag() -> num_entries()) VARIABLE_COMPRESSED_VISITOR(Array, Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(TypedData, TypedData::ElementSizeInBytes(raw_obj->GetClassId()) *Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(Record, RecordShape(raw_obj->untag() ->shape()).num_fields()) VARIABLE_NULL_VISITOR(CompressedStackMaps, CompressedStackMaps::PayloadSizeOf(raw_obj)) VARIABLE_NULL_VISITOR(OneByteString, Smi::Value(raw_obj->untag() ->length())) VARIABLE_NULL_VISITOR(TwoByteString, Smi::Value(raw_obj->untag() ->length())) intptr_t UntaggedField::VisitFieldPointers(FieldPtr raw_obj, ObjectPointerVisitor *visitor)

◆ FindLibrary()

LibraryPtr dart::Script::FindLibrary ( ) const

Definition at line 13529 of file object.cc.

13529 {
13530 Thread* thread = Thread::Current();
13531 Zone* zone = thread->zone();
13532 auto isolate_group = thread->isolate_group();
13533 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
13534 zone, isolate_group->object_store()->libraries());
13535 Library& lib = Library::Handle(zone);
13536 Array& scripts = Array::Handle(zone);
13537 for (intptr_t i = 0; i < libs.Length(); i++) {
13538 lib ^= libs.At(i);
13539 scripts = lib.LoadedScripts();
13540 for (intptr_t j = 0; j < scripts.Length(); j++) {
13541 if (scripts.At(j) == ptr()) {
13542 return lib.ptr();
13543 }
13544 }
13545 }
13546 return Library::null();
13547}
ObjectPtr ptr() const
Definition object.h:332

◆ GenerateLineNumberArray()

GrowableObjectArrayPtr dart::Script::GenerateLineNumberArray ( ) const

Definition at line 13172 of file object.cc.

13172 {
13173 Zone* zone = Thread::Current()->zone();
13174 const GrowableObjectArray& info =
13176 const Object& line_separator = Object::Handle(zone);
13177 if (line_starts() == TypedData::null()) {
13178 // Scripts in the AOT snapshot do not have a line starts array.
13179 // A well-formed line number array has a leading null.
13180 info.Add(line_separator); // New line.
13181 return info.ptr();
13182 }
13183#if !defined(DART_PRECOMPILED_RUNTIME)
13184 Smi& value = Smi::Handle(zone);
13185 const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
13186 intptr_t line_count = line_starts_data.Length();
13187 const Array& debug_positions_array = Array::Handle(debug_positions());
13188 intptr_t token_count = debug_positions_array.Length();
13189 int token_index = 0;
13190
13191 kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
13192 for (int line_index = 0; line_index < line_count; ++line_index) {
13193 intptr_t start = line_starts_reader.At(line_index);
13194 // Output the rest of the tokens if we have no next line.
13196 if (line_index + 1 < line_count) {
13197 end = line_starts_reader.At(line_index + 1);
13198 }
13199 bool first = true;
13200 while (token_index < token_count) {
13201 value ^= debug_positions_array.At(token_index);
13202 intptr_t debug_position = value.Value();
13203 if (debug_position >= end) break;
13204
13205 if (first) {
13206 info.Add(line_separator); // New line.
13207 value = Smi::New(line_index + 1); // Line number.
13208 info.Add(value);
13209 first = false;
13210 }
13211
13212 value ^= debug_positions_array.At(token_index);
13213 info.Add(value); // Token position.
13214 value = Smi::New(debug_position - start + 1); // Column.
13215 info.Add(value);
13216 ++token_index;
13217 }
13218 }
13219#endif // !defined(DART_PRECOMPILED_RUNTIME)
13220 return info.ptr();
13221}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static GrowableObjectArrayPtr New(Heap::Space space=Heap::kNew)
Definition object.h:11118
TypedDataPtr line_starts() const
Definition object.cc:13265
static SmiPtr New(intptr_t value)
Definition object.h:9985
Zone * zone() const
static constexpr int32_t kMaxSourcePos
glong glong end
uint8_t value

◆ GetLine()

StringPtr dart::Script::GetLine ( intptr_t  line_number,
Heap::Space  space = Heap::kNew 
) const

Definition at line 13458 of file object.cc.

13458 {
13459 if (!HasSource()) {
13460 return Symbols::OptimizedOut().ptr();
13461 }
13462 const String& src = String::Handle(Source());
13463 const intptr_t start =
13464 GetRelativeSourceIndex(src, line_number, line_offset());
13465 if (start < 0) {
13466 return Symbols::Empty().ptr();
13467 }
13468 intptr_t end = start;
13469 for (; end < src.Length(); end++) {
13470 const uint16_t c = src.CharAt(end);
13471 if (c == '\n' || c == '\r') {
13472 break;
13473 }
13474 }
13475 return String::SubString(src, start, end - start, space);
13476}
StringPtr Source() const
Definition object.cc:13140
bool HasSource() const
Definition object.cc:13136
intptr_t line_offset() const
Definition object.h:4914
static StringPtr SubString(const String &str, intptr_t begin_index, Heap::Space space=Heap::kNew)
Definition object.cc:24159
static const String & Empty()
Definition symbols.h:687
static intptr_t GetRelativeSourceIndex(const String &src, intptr_t line, intptr_t line_offset=0, intptr_t column=1, intptr_t column_offset=0, intptr_t starting_index=0)
Definition object.cc:13410

◆ GetSnippet()

StringPtr dart::Script::GetSnippet ( intptr_t  from_line,
intptr_t  from_column,
intptr_t  to_line,
intptr_t  to_column 
) const

Definition at line 13478 of file object.cc.

13481 {
13482 if (!HasSource()) {
13483 return Symbols::OptimizedOut().ptr();
13484 }
13485 const String& src = String::Handle(Source());
13486 const intptr_t start = GetRelativeSourceIndex(src, from_line, line_offset(),
13487 from_column, col_offset());
13488 // Lines and columns are 1-based, so need to subtract one to get offsets.
13489 const intptr_t end = GetRelativeSourceIndex(
13490 src, to_line, from_line - 1, to_column, from_column - 1, start);
13491 // Only need to check end, because a negative start results in a negative end.
13492 if (end < 0) {
13493 return String::null();
13494 }
13495 return String::SubString(src, start, end - start);
13496}
intptr_t col_offset() const
Definition object.h:4915

◆ GetTokenLength()

intptr_t dart::Script::GetTokenLength ( const TokenPosition token_pos) const

Definition at line 13348 of file object.cc.

13348 {
13349#if defined(DART_PRECOMPILED_RUNTIME)
13350 // Scripts in the AOT snapshot do not have their source.
13351 return -1;
13352#else
13353 if (!HasSource() || !token_pos.IsReal()) return -1;
13354 auto const zone = Thread::Current()->zone();
13355 // We don't explicitly save this data: Load the source and find it from there.
13356 const String& source = String::Handle(zone, Source());
13357 const intptr_t start = token_pos.Pos();
13358 if (start >= source.Length()) return -1; // Can't determine token_len.
13359 intptr_t end = start;
13360 if (IsIdentStartChar(source.CharAt(end++))) {
13361 for (; end < source.Length(); ++end) {
13362 if (!IsIdentChar(source.CharAt(end))) break;
13363 }
13364 }
13365 return end - start;
13366#endif
13367}
SkBitmap source
Definition examples.cpp:28
static bool IsIdentChar(int32_t c)
Definition object.cc:13325
static bool IsIdentStartChar(int32_t c)
Definition object.cc:13321

◆ GetTokenLocation()

bool dart::Script::GetTokenLocation ( const TokenPosition token_pos,
intptr_t *  line,
intptr_t *  column = nullptr 
) const

Definition at line 13330 of file object.cc.

13332 {
13333 ASSERT(line != nullptr);
13334#if defined(DART_PRECOMPILED_RUNTIME)
13335 // Scripts in the AOT snapshot do not have a line starts array.
13336 return false;
13337#else
13338 if (!token_pos.IsReal()) return false;
13339
13340 auto const zone = Thread::Current()->zone();
13341 const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
13342 if (line_starts_data.IsNull()) return false;
13343 kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
13344 return line_starts_reader.LocationForPosition(token_pos.Pos(), line, column);
13345#endif // defined(DART_PRECOMPILED_RUNTIME)
13346}

◆ HasSource()

bool dart::Script::HasSource ( ) const

Definition at line 13136 of file object.cc.

13136 {
13137 return untag()->source() != String::null();
13138}

◆ InitializeFromKernel()

void dart::Script::InitializeFromKernel ( const KernelProgramInfo info,
intptr_t  script_index,
const TypedData line_starts,
const TypedDataView constant_coverage 
) const

Definition at line 13159 of file object.cc.

13163 {
13164 StoreNonPointer(&untag()->kernel_script_index_, script_index);
13165 untag()->set_kernel_program_info(info.ptr());
13166 untag()->set_line_starts(line_starts.ptr());
13167 untag()->set_debug_positions(Array::null_array().ptr());
13168 NOT_IN_PRODUCT(untag()->set_constant_coverage(constant_coverage.ptr()));
13169}
void StoreNonPointer(const FieldType *addr, ValueType value) const
Definition object.h:819
TypedDataViewPtr constant_coverage() const
Definition object.cc:13256
#define NOT_IN_PRODUCT(code)
Definition globals.h:84

◆ InstanceSize()

static intptr_t dart::Script::InstanceSize ( )
inlinestatic

Definition at line 4974 of file object.h.

4974 {
4975 return RoundedAllocationSize(sizeof(UntaggedScript));
4976 }
static constexpr intptr_t RoundedAllocationSize(intptr_t size)
Definition object.h:758

◆ IsPartOfDartColonLibrary()

bool dart::Script::IsPartOfDartColonLibrary ( ) const

Definition at line 13144 of file object.cc.

13144 {
13145 const String& script_url = String::Handle(url());
13146 return (script_url.StartsWith(Symbols::DartScheme()) ||
13147 script_url.StartsWith(Symbols::DartSchemePrivate()));
13148}
StringPtr url() const
Definition object.h:4903

◆ IsValidTokenPosition()

bool dart::Script::IsValidTokenPosition ( TokenPosition  token_pos) const

Definition at line 13303 of file object.cc.

13303 {
13304 const TokenPosition& max_position = MaxPosition();
13305 // We may end up with scripts that have the empty string as a source file
13306 // in testing and the like, so allow any token position when the max position
13307 // is 0 as well as when it is kNoSource.
13308 return !max_position.IsReal() || !token_pos.IsReal() ||
13309 max_position.Pos() == 0 || token_pos <= max_position;
13310}
TokenPosition MaxPosition() const
Definition object.cc:13223

◆ kernel_script_index()

intptr_t dart::Script::kernel_script_index ( ) const
inline

Definition at line 4933 of file object.h.

4933{ return untag()->kernel_script_index_; }

◆ line_offset()

intptr_t dart::Script::line_offset ( ) const
inline

Definition at line 4914 of file object.h.

4914{ return 0; }

◆ line_starts()

TypedDataPtr dart::Script::line_starts ( ) const

Definition at line 13265 of file object.cc.

13265 {
13266 return untag()->line_starts();
13267}

◆ line_starts_offset()

static intptr_t dart::Script::line_starts_offset ( )
inlinestatic

Definition at line 4935 of file object.h.

4935 {
4936 return OFFSET_OF(UntaggedScript, line_starts_);
4937 }
#define OFFSET_OF(type, field)
Definition globals.h:138

◆ load_timestamp()

int64_t dart::Script::load_timestamp ( ) const
inline

Definition at line 4921 of file object.h.

4921{ return untag()->load_timestamp_; }

◆ LoadSourceFromKernel()

void dart::Script::LoadSourceFromKernel ( const uint8_t *  kernel_buffer,
intptr_t  kernel_buffer_len 
) const

Definition at line 13151 of file object.cc.

13152 {
13153 String& uri = String::Handle(resolved_url());
13155 kernel_buffer, kernel_buffer_len, uri));
13156 set_source(source);
13157}
StringPtr resolved_url() const
Definition object.cc:13127
static StringPtr FindSourceForScript(const uint8_t *kernel_buffer, intptr_t kernel_buffer_length, const String &url)

◆ MaxPosition()

TokenPosition dart::Script::MaxPosition ( ) const

Definition at line 13223 of file object.cc.

13223 {
13224#if !defined(DART_PRECOMPILED_RUNTIME)
13225 if (HasCachedMaxPosition()) {
13228 untag()->flags_and_max_position_));
13229 }
13230 auto const zone = Thread::Current()->zone();
13231 if (!HasCachedMaxPosition() && line_starts() != TypedData::null()) {
13232 const auto& starts = TypedData::Handle(zone, line_starts());
13233 kernel::KernelLineStartsReader reader(starts, zone);
13234 const intptr_t max_position = reader.MaxPosition();
13235 SetCachedMaxPosition(max_position);
13236 SetHasCachedMaxPosition(true);
13237 return TokenPosition::Deserialize(max_position);
13238 }
13239#endif
13240 return TokenPosition::kNoSource;
13241}
static constexpr T decode(S value)
Definition bitfield.h:173
static TokenPosition Deserialize(int32_t value)

◆ New() [1/2]

ScriptPtr dart::Script::New ( const String url,
const String resolved_url,
const String source 
)
static

Definition at line 13502 of file object.cc.

13504 {
13506 Thread* thread = Thread::Current();
13507 Zone* zone = thread->zone();
13508 const Script& result =
13509 Script::Handle(zone, Object::Allocate<Script>(Heap::kOld));
13510 result.set_url(String::Handle(zone, Symbols::New(thread, url)));
13511 result.set_resolved_url(
13512 String::Handle(zone, Symbols::New(thread, resolved_url)));
13513 result.set_source(source);
13514 NOT_IN_PRECOMPILED(ASSERT_EQUAL(result.HasCachedMaxPosition(), false));
13515 ASSERT_EQUAL(result.kernel_script_index(), 0);
13516 if (FLAG_remove_script_timestamps_for_test) {
13517 ASSERT_EQUAL(result.load_timestamp(), 0);
13518 } else {
13519 result.set_load_timestamp(OS::GetCurrentTimeMillis());
13520 }
13521 return result.ptr();
13522}
#define ASSERT_EQUAL(expected, actual)
Definition assert.h:309
@ kOld
Definition heap.h:39
static int64_t GetCurrentTimeMillis()
static ClassPtr script_class()
Definition object.h:525
static StringPtr New(Thread *thread, const char *cstr)
Definition symbols.h:722
GAsyncResult * result
#define NOT_IN_PRECOMPILED(code)
Definition globals.h:100

◆ New() [2/2]

ScriptPtr dart::Script::New ( const String url,
const String source 
)
static

Definition at line 13498 of file object.cc.

13498 {
13499 return Script::New(url, url, source);
13500}
static ScriptPtr New(const String &url, const String &source)
Definition object.cc:13498

◆ resolved_url()

StringPtr dart::Script::resolved_url ( ) const

Definition at line 13127 of file object.cc.

13127 {
13128#if defined(DART_PRECOMPILER)
13129 return String::RawCast(
13131#else
13132 return untag()->resolved_url();
13133#endif
13134}
static ObjectPtr RawCast(ObjectPtr obj)
Definition object.h:325
static ObjectPtr Unwrap(ObjectPtr obj)
Definition object.h:6640

◆ set_url()

void dart::Script::set_url ( const String value) const

Definition at line 13243 of file object.cc.

13243 {
13244 untag()->set_url(value.ptr());
13245}

◆ Source()

StringPtr dart::Script::Source ( ) const

Definition at line 13140 of file object.cc.

13140 {
13141 return untag()->source();
13142}

◆ TokenRangeAtLine()

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

Definition at line 13369 of file object.cc.

13371 {
13372 ASSERT(first_token_index != nullptr && last_token_index != nullptr);
13373#if defined(DART_PRECOMPILED_RUNTIME)
13374 // Scripts in the AOT snapshot do not have a line starts array.
13375 return false;
13376#else
13377 // Line numbers are 1-indexed.
13378 if (line_number <= 0) return false;
13379 Zone* zone = Thread::Current()->zone();
13380 const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
13381 kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
13382 if (!line_starts_reader.TokenRangeAtLine(line_number, first_token_index,
13383 last_token_index)) {
13384 return false;
13385 }
13386#if defined(DEBUG)
13387 intptr_t source_length;
13388 if (!HasSource()) {
13389 Smi& value = Smi::Handle(zone);
13390 const Array& debug_positions_array = Array::Handle(zone, debug_positions());
13391 value ^= debug_positions_array.At(debug_positions_array.Length() - 1);
13392 source_length = value.Value();
13393 } else {
13394 const String& source = String::Handle(zone, Source());
13395 source_length = source.Length();
13396 }
13397 ASSERT(last_token_index->Serialize() <= source_length);
13398#endif
13399 return true;
13400#endif // !defined(DART_PRECOMPILED_RUNTIME)
13401}

◆ url()

StringPtr dart::Script::url ( ) const
inline

Definition at line 4903 of file object.h.

4903{ return untag()->url(); }

Friends And Related Symbol Documentation

◆ Class

friend class Class
friend

Definition at line 5012 of file object.h.

◆ Precompiler

friend class Precompiler
friend

Definition at line 5013 of file object.h.


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