Skip to content

Commit

Permalink
Merge of source position information from kernel-sdk.
Browse files Browse the repository at this point in the history
I.e. use offsets (on some nodes) in the dill file to
get stacktraces with line- and column numbers.

"sdk" version of "kernel-sdk"s
https://chromereviews.googleplex.com/520617013/

R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2512653002 .

Committed: 6fd3a42
  • Loading branch information
jensjoha committed Nov 21, 2016
1 parent 1056c56 commit 63e9c76
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 158 deletions.
5 changes: 2 additions & 3 deletions runtime/vm/bootstrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ static RawError* BootstrapFromKernel(Thread* thread,
const uint8_t* buffer,
intptr_t buffer_size) {
Zone* zone = thread->zone();
kernel::Program* program =
ReadPrecompiledKernelFromBuffer(buffer, buffer_size);
kernel::KernelReader reader(buffer, buffer_size, true);
kernel::Program* program = reader.ReadPrecompiledProgram();
if (program == NULL) {
const String& message =
String::Handle(zone, String::New("Failed to read Kernel file"));
Expand All @@ -343,7 +343,6 @@ static RawError* BootstrapFromKernel(Thread* thread,
Library& library = Library::Handle(zone);
String& dart_name = String::Handle(zone);
String& kernel_name = String::Handle(zone);
kernel::KernelReader reader(NULL, -1, true);
for (intptr_t i = 0; i < kBootstrapLibraryCount; ++i) {
ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index;
library = isolate->object_store()->bootstrap_library(id);
Expand Down
5 changes: 2 additions & 3 deletions runtime/vm/bootstrap_nocore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ RawError* BootstrapFromKernel(Thread* thread,
const uint8_t* buffer,
intptr_t buffer_length) {
Zone* zone = thread->zone();
kernel::Program* program =
ReadPrecompiledKernelFromBuffer(buffer, buffer_length);
kernel::KernelReader reader(buffer, buffer_length, true);
kernel::Program* program = reader.ReadPrecompiledProgram();
if (program == NULL) {
const String& message =
String::Handle(zone, String::New("Failed to read Kernel file"));
Expand All @@ -81,7 +81,6 @@ RawError* BootstrapFromKernel(Thread* thread,
Library& library = Library::Handle(zone);
String& dart_name = String::Handle(zone);
String& kernel_name = String::Handle(zone);
kernel::KernelReader reader(NULL, -1, true);
for (intptr_t i = 0; i < bootstrap_library_count; ++i) {
ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index;
library = isolate->object_store()->bootstrap_library(id);
Expand Down
13 changes: 8 additions & 5 deletions runtime/vm/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,15 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,

DartFrameIterator iterator;
const Script& script = Script::Handle(zone, GetCallerScript(&iterator));
intptr_t line;
intptr_t line = -1;
intptr_t column = -1;
if (script.HasSource()) {
script.GetTokenLocation(location, &line, &column);
} else {
script.GetTokenLocation(location, &line, NULL);
ASSERT(!script.IsNull());
if (location.IsReal()) {
if (script.HasSource() || script.kind() == RawScript::kKernelTag) {
script.GetTokenLocation(location, &line, &column);
} else {
script.GetTokenLocation(location, &line, NULL);
}
}
// Initialize '_url', '_line', and '_column' arguments.
args.SetAt(0, String::Handle(zone, script.url()));
Expand Down
28 changes: 20 additions & 8 deletions runtime/vm/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "platform/assert.h"
#include "vm/allocation.h"
#include "vm/globals.h"
#include "vm/token_position.h"


#define KERNEL_NODES_DO(M) \
Expand Down Expand Up @@ -308,7 +309,7 @@ class StringTable {

class LineStartingTable {
public:
void ReadFrom(Reader* reader, intptr_t length);
void ReadFrom(Reader* reader);
void WriteTo(Writer* writer);
~LineStartingTable() {
for (intptr_t i = 0; i < size_; ++i) {
Expand Down Expand Up @@ -413,6 +414,7 @@ class Library : public TreeNode {
virtual void VisitChildren(Visitor* visitor);

String* import_uri() { return import_uri_; }
intptr_t source_uri_index() { return source_uri_index_; }
String* name() { return name_; }
List<Class>& classes() { return classes_; }
List<Field>& fields() { return fields_; }
Expand Down Expand Up @@ -448,6 +450,7 @@ class Library : public TreeNode {

Ref<String> name_;
Ref<String> import_uri_;
intptr_t source_uri_index_;
List<Class> classes_;
List<Field> fields_;
List<Procedure> procedures_;
Expand All @@ -471,6 +474,7 @@ class Class : public TreeNode {

Library* parent() { return parent_; }
String* name() { return name_; }
intptr_t source_uri_index() { return source_uri_index_; }
bool is_abstract() { return is_abstract_; }
List<Expression>& annotations() { return annotations_; }

Expand All @@ -489,6 +493,7 @@ class Class : public TreeNode {

Ref<Library> parent_;
Ref<String> name_;
intptr_t source_uri_index_;
bool is_abstract_;
List<Expression> annotations_;

Expand Down Expand Up @@ -629,21 +634,25 @@ class Field : public Member {
bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; }
bool IsFinal() { return (flags_ & kFlagFinal) == kFlagFinal; }
bool IsStatic() { return (flags_ & kFlagStatic) == kFlagStatic; }
intptr_t source_uri_index() { return source_uri_index_; }

DartType* type() { return type_; }
InferredValue* inferred_value() { return inferred_value_; }
Expression* initializer() { return initializer_; }
TokenPosition position() { return position_; }

private:
Field() {}
Field() : position_(TokenPosition::kNoSource) {}

template <typename T>
friend class List;

word flags_;
intptr_t source_uri_index_;
Child<DartType> type_;
Child<InferredValue> inferred_value_;
Child<Expression> initializer_;
TokenPosition position_;

DISALLOW_COPY_AND_ASSIGN(Field);
};
Expand Down Expand Up @@ -725,6 +734,7 @@ class Procedure : public Member {
bool IsAbstract() { return (flags_ & kFlagAbstract) == kFlagAbstract; }
bool IsExternal() { return (flags_ & kFlagExternal) == kFlagExternal; }
bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; }
intptr_t source_uri_index() { return source_uri_index_; }

private:
Procedure() : kind_(kIncompleteProcedure), flags_(0), function_(NULL) {}
Expand All @@ -734,6 +744,7 @@ class Procedure : public Member {

ProcedureKind kind_;
word flags_;
intptr_t source_uri_index_;
Child<FunctionNode> function_;

DISALLOW_COPY_AND_ASSIGN(Procedure);
Expand Down Expand Up @@ -934,9 +945,11 @@ class Expression : public TreeNode {

virtual void AcceptTreeVisitor(TreeVisitor* visitor);
virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor) = 0;
TokenPosition position() { return position_; }

protected:
Expression() {}
Expression() : position_(TokenPosition::kNoSource) {}
TokenPosition position_;

private:
DISALLOW_COPY_AND_ASSIGN(Expression);
Expand Down Expand Up @@ -1281,11 +1294,6 @@ class StaticInvocation : public Expression {
public:
static StaticInvocation* ReadFrom(Reader* reader, bool is_const);
virtual void WriteTo(Writer* writer);

explicit StaticInvocation(Procedure* procedure,
Arguments* args,
bool is_const)
: procedure_(procedure), arguments_(args), is_const_(is_const) {}
~StaticInvocation();

virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor);
Expand Down Expand Up @@ -2785,6 +2793,8 @@ class Program : public TreeNode {
virtual void VisitChildren(Visitor* visitor);

StringTable& string_table() { return string_table_; }
StringTable& source_uri_table() { return source_uri_table_; }
LineStartingTable& line_starting_table() { return line_starting_table_; }
List<Library>& libraries() { return libraries_; }
Procedure* main_method() { return main_method_; }

Expand All @@ -2794,6 +2804,8 @@ class Program : public TreeNode {
List<Library> libraries_;
Ref<Procedure> main_method_;
StringTable string_table_;
StringTable source_uri_table_;
LineStartingTable line_starting_table_;

DISALLOW_COPY_AND_ASSIGN(Program);
};
Expand Down
Loading

0 comments on commit 63e9c76

Please sign in to comment.