Flutter Engine
The Flutter Engine
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 4930 of file object.h.

Member Function Documentation

◆ col_offset()

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

Definition at line 4944 of file object.h.

4944{ 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:10959
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:5041
static Thread * Current()
Definition: thread.h:362
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 13209 of file object.cc.

13209 {
13210 return untag()->constant_coverage();
13211}
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)
Definition: raw_object.cc:558

◆ FindLibrary()

LibraryPtr dart::Script::FindLibrary ( ) const

Definition at line 13482 of file object.cc.

13482 {
13483 Thread* thread = Thread::Current();
13484 Zone* zone = thread->zone();
13485 auto isolate_group = thread->isolate_group();
13486 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
13487 zone, isolate_group->object_store()->libraries());
13488 Library& lib = Library::Handle(zone);
13489 Array& scripts = Array::Handle(zone);
13490 for (intptr_t i = 0; i < libs.Length(); i++) {
13491 lib ^= libs.At(i);
13492 scripts = lib.LoadedScripts();
13493 for (intptr_t j = 0; j < scripts.Length(); j++) {
13494 if (scripts.At(j) == ptr()) {
13495 return lib.ptr();
13496 }
13497 }
13498 }
13499 return Library::null();
13500}
ObjectPtr ptr() const
Definition: object.h:332

◆ GenerateLineNumberArray()

GrowableObjectArrayPtr dart::Script::GenerateLineNumberArray ( ) const

Definition at line 13125 of file object.cc.

13125 {
13126 Zone* zone = Thread::Current()->zone();
13127 const GrowableObjectArray& info =
13129 const Object& line_separator = Object::Handle(zone);
13130 if (line_starts() == TypedData::null()) {
13131 // Scripts in the AOT snapshot do not have a line starts array.
13132 // A well-formed line number array has a leading null.
13133 info.Add(line_separator); // New line.
13134 return info.ptr();
13135 }
13136#if !defined(DART_PRECOMPILED_RUNTIME)
13137 Smi& value = Smi::Handle(zone);
13138 const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
13139 intptr_t line_count = line_starts_data.Length();
13140 const Array& debug_positions_array = Array::Handle(debug_positions());
13141 intptr_t token_count = debug_positions_array.Length();
13142 int token_index = 0;
13143
13144 kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
13145 for (int line_index = 0; line_index < line_count; ++line_index) {
13146 intptr_t start = line_starts_reader.At(line_index);
13147 // Output the rest of the tokens if we have no next line.
13149 if (line_index + 1 < line_count) {
13150 end = line_starts_reader.At(line_index + 1);
13151 }
13152 bool first = true;
13153 while (token_index < token_count) {
13154 value ^= debug_positions_array.At(token_index);
13155 intptr_t debug_position = value.Value();
13156 if (debug_position >= end) break;
13157
13158 if (first) {
13159 info.Add(line_separator); // New line.
13160 value = Smi::New(line_index + 1); // Line number.
13161 info.Add(value);
13162 first = false;
13163 }
13164
13165 value ^= debug_positions_array.At(token_index);
13166 info.Add(value); // Token position.
13167 value = Smi::New(debug_position - start + 1); // Column.
13168 info.Add(value);
13169 ++token_index;
13170 }
13171 }
13172#endif // !defined(DART_PRECOMPILED_RUNTIME)
13173 return info.ptr();
13174}
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:11144
TypedDataPtr line_starts() const
Definition: object.cc:13218
static SmiPtr New(intptr_t value)
Definition: object.h:10006
Zone * zone() const
Definition: thread_state.h:37
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 13411 of file object.cc.

13411 {
13412 if (!HasSource()) {
13413 return Symbols::OptimizedOut().ptr();
13414 }
13415 const String& src = String::Handle(Source());
13416 const intptr_t start =
13417 GetRelativeSourceIndex(src, line_number, line_offset());
13418 if (start < 0) {
13419 return Symbols::Empty().ptr();
13420 }
13421 intptr_t end = start;
13422 for (; end < src.Length(); end++) {
13423 const uint16_t c = src.CharAt(end);
13424 if (c == '\n' || c == '\r') {
13425 break;
13426 }
13427 }
13428 return String::SubString(src, start, end - start, space);
13429}
StringPtr Source() const
Definition: object.cc:13093
bool HasSource() const
Definition: object.cc:13089
intptr_t line_offset() const
Definition: object.h:4943
static StringPtr SubString(const String &str, intptr_t begin_index, Heap::Space space=Heap::kNew)
Definition: object.cc:24080
static const String & Empty()
Definition: symbols.h:688
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:13363

◆ 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 13431 of file object.cc.

13434 {
13435 if (!HasSource()) {
13436 return Symbols::OptimizedOut().ptr();
13437 }
13438 const String& src = String::Handle(Source());
13439 const intptr_t start = GetRelativeSourceIndex(src, from_line, line_offset(),
13440 from_column, col_offset());
13441 // Lines and columns are 1-based, so need to subtract one to get offsets.
13442 const intptr_t end = GetRelativeSourceIndex(
13443 src, to_line, from_line - 1, to_column, from_column - 1, start);
13444 // Only need to check end, because a negative start results in a negative end.
13445 if (end < 0) {
13446 return String::null();
13447 }
13448 return String::SubString(src, start, end - start);
13449}
intptr_t col_offset() const
Definition: object.h:4944

◆ GetTokenLength()

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

Definition at line 13301 of file object.cc.

13301 {
13302#if defined(DART_PRECOMPILED_RUNTIME)
13303 // Scripts in the AOT snapshot do not have their source.
13304 return -1;
13305#else
13306 if (!HasSource() || !token_pos.IsReal()) return -1;
13307 auto const zone = Thread::Current()->zone();
13308 // We don't explicitly save this data: Load the source and find it from there.
13309 const String& source = String::Handle(zone, Source());
13310 const intptr_t start = token_pos.Pos();
13311 if (start >= source.Length()) return -1; // Can't determine token_len.
13312 intptr_t end = start;
13313 if (IsIdentStartChar(source.CharAt(end++))) {
13314 for (; end < source.Length(); ++end) {
13315 if (!IsIdentChar(source.CharAt(end))) break;
13316 }
13317 }
13318 return end - start;
13319#endif
13320}
SkBitmap source
Definition: examples.cpp:28
static bool IsIdentChar(int32_t c)
Definition: object.cc:13278
static bool IsIdentStartChar(int32_t c)
Definition: object.cc:13274

◆ GetTokenLocation()

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

Definition at line 13283 of file object.cc.

13285 {
13286 ASSERT(line != nullptr);
13287#if defined(DART_PRECOMPILED_RUNTIME)
13288 // Scripts in the AOT snapshot do not have a line starts array.
13289 return false;
13290#else
13291 if (!token_pos.IsReal()) return false;
13292
13293 auto const zone = Thread::Current()->zone();
13294 const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
13295 if (line_starts_data.IsNull()) return false;
13296 kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
13297 return line_starts_reader.LocationForPosition(token_pos.Pos(), line, column);
13298#endif // defined(DART_PRECOMPILED_RUNTIME)
13299}

◆ HasSource()

bool dart::Script::HasSource ( ) const

Definition at line 13089 of file object.cc.

13089 {
13090 return untag()->source() != String::null();
13091}

◆ InitializeFromKernel()

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

Definition at line 13112 of file object.cc.

13116 {
13117 StoreNonPointer(&untag()->kernel_script_index_, script_index);
13118 untag()->set_kernel_program_info(info.ptr());
13119 untag()->set_line_starts(line_starts.ptr());
13120 untag()->set_debug_positions(Array::null_array().ptr());
13121 NOT_IN_PRODUCT(untag()->set_constant_coverage(constant_coverage.ptr()));
13122}
void StoreNonPointer(const FieldType *addr, ValueType value) const
Definition: object.h:819
TypedDataViewPtr constant_coverage() const
Definition: object.cc:13209
NOT_IN_PRODUCT(LibraryPtr ReloadTestScript(const char *script))

◆ InstanceSize()

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

Definition at line 5003 of file object.h.

5003 {
5004 return RoundedAllocationSize(sizeof(UntaggedScript));
5005 }
static constexpr intptr_t RoundedAllocationSize(intptr_t size)
Definition: object.h:758

◆ IsPartOfDartColonLibrary()

bool dart::Script::IsPartOfDartColonLibrary ( ) const

Definition at line 13097 of file object.cc.

13097 {
13098 const String& script_url = String::Handle(url());
13099 return (script_url.StartsWith(Symbols::DartScheme()) ||
13100 script_url.StartsWith(Symbols::DartSchemePrivate()));
13101}
StringPtr url() const
Definition: object.h:4932

◆ IsValidTokenPosition()

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

Definition at line 13256 of file object.cc.

13256 {
13257 const TokenPosition& max_position = MaxPosition();
13258 // We may end up with scripts that have the empty string as a source file
13259 // in testing and the like, so allow any token position when the max position
13260 // is 0 as well as when it is kNoSource.
13261 return !max_position.IsReal() || !token_pos.IsReal() ||
13262 max_position.Pos() == 0 || token_pos <= max_position;
13263}
TokenPosition MaxPosition() const
Definition: object.cc:13176

◆ kernel_script_index()

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

Definition at line 4962 of file object.h.

4962{ return untag()->kernel_script_index_; }

◆ line_offset()

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

Definition at line 4943 of file object.h.

4943{ return 0; }

◆ line_starts()

TypedDataPtr dart::Script::line_starts ( ) const

Definition at line 13218 of file object.cc.

13218 {
13219 return untag()->line_starts();
13220}

◆ line_starts_offset()

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

Definition at line 4964 of file object.h.

4964 {
4965 return OFFSET_OF(UntaggedScript, line_starts_);
4966 }
#define OFFSET_OF(type, field)
Definition: globals.h:138

◆ load_timestamp()

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

Definition at line 4950 of file object.h.

4950{ return untag()->load_timestamp_; }

◆ LoadSourceFromKernel()

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

Definition at line 13104 of file object.cc.

13105 {
13106 String& uri = String::Handle(resolved_url());
13108 kernel_buffer, kernel_buffer_len, uri));
13109 set_source(source);
13110}
StringPtr resolved_url() const
Definition: object.cc:13080
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 13176 of file object.cc.

13176 {
13177#if !defined(DART_PRECOMPILED_RUNTIME)
13178 if (HasCachedMaxPosition()) {
13181 untag()->flags_and_max_position_));
13182 }
13183 auto const zone = Thread::Current()->zone();
13184 if (!HasCachedMaxPosition() && line_starts() != TypedData::null()) {
13185 const auto& starts = TypedData::Handle(zone, line_starts());
13186 kernel::KernelLineStartsReader reader(starts, zone);
13187 const intptr_t max_position = reader.MaxPosition();
13188 SetCachedMaxPosition(max_position);
13189 SetHasCachedMaxPosition(true);
13190 return TokenPosition::Deserialize(max_position);
13191 }
13192#endif
13193 return TokenPosition::kNoSource;
13194}
static constexpr T decode(S value)
Definition: bitfield.h:171
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 13455 of file object.cc.

13457 {
13459 Thread* thread = Thread::Current();
13460 Zone* zone = thread->zone();
13461 const Script& result =
13462 Script::Handle(zone, Object::Allocate<Script>(Heap::kOld));
13463 result.set_url(String::Handle(zone, Symbols::New(thread, url)));
13464 result.set_resolved_url(
13465 String::Handle(zone, Symbols::New(thread, resolved_url)));
13466 result.set_source(source);
13467 NOT_IN_PRECOMPILED(ASSERT_EQUAL(result.HasCachedMaxPosition(), false));
13468 ASSERT_EQUAL(result.kernel_script_index(), 0);
13469 if (FLAG_remove_script_timestamps_for_test) {
13470 ASSERT_EQUAL(result.load_timestamp(), 0);
13471 } else {
13472 result.set_load_timestamp(OS::GetCurrentTimeMillis());
13473 }
13474 return result.ptr();
13475}
#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:723
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 13451 of file object.cc.

13451 {
13452 return Script::New(url, url, source);
13453}
static ScriptPtr New(const String &url, const String &source)
Definition: object.cc:13451

◆ resolved_url()

StringPtr dart::Script::resolved_url ( ) const

Definition at line 13080 of file object.cc.

13080 {
13081#if defined(DART_PRECOMPILER)
13082 return String::RawCast(
13084#else
13085 return untag()->resolved_url();
13086#endif
13087}
static ObjectPtr RawCast(ObjectPtr obj)
Definition: object.h:325
static ObjectPtr Unwrap(ObjectPtr obj)
Definition: object.h:6667

◆ set_url()

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

Definition at line 13196 of file object.cc.

13196 {
13197 untag()->set_url(value.ptr());
13198}

◆ Source()

StringPtr dart::Script::Source ( ) const

Definition at line 13093 of file object.cc.

13093 {
13094 return untag()->source();
13095}

◆ TokenRangeAtLine()

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

Definition at line 13322 of file object.cc.

13324 {
13325 ASSERT(first_token_index != nullptr && last_token_index != nullptr);
13326#if defined(DART_PRECOMPILED_RUNTIME)
13327 // Scripts in the AOT snapshot do not have a line starts array.
13328 return false;
13329#else
13330 // Line numbers are 1-indexed.
13331 if (line_number <= 0) return false;
13332 Zone* zone = Thread::Current()->zone();
13333 const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
13334 kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
13335 if (!line_starts_reader.TokenRangeAtLine(line_number, first_token_index,
13336 last_token_index)) {
13337 return false;
13338 }
13339#if defined(DEBUG)
13340 intptr_t source_length;
13341 if (!HasSource()) {
13342 Smi& value = Smi::Handle(zone);
13343 const Array& debug_positions_array = Array::Handle(zone, debug_positions());
13344 value ^= debug_positions_array.At(debug_positions_array.Length() - 1);
13345 source_length = value.Value();
13346 } else {
13347 const String& source = String::Handle(zone, Source());
13348 source_length = source.Length();
13349 }
13350 ASSERT(last_token_index->Serialize() <= source_length);
13351#endif
13352 return true;
13353#endif // !defined(DART_PRECOMPILED_RUNTIME)
13354}

◆ url()

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

Definition at line 4932 of file object.h.

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

Friends And Related Function Documentation

◆ Class

friend class Class
friend

Definition at line 5041 of file object.h.

◆ Precompiler

friend class Precompiler
friend

Definition at line 5042 of file object.h.


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