Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: src/source-position.cc

Issue 2568303008: [source-positions] make the SourcePositionInfo constructor actually compute position info (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/source-position.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/source-position.h" 5 #include "src/source-position.h"
6 #include "src/compilation-info.h" 6 #include "src/compilation-info.h"
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 25 matching lines...) Expand all
36 std::ostream& operator<<(std::ostream& out, const SourcePosition& pos) { 36 std::ostream& operator<<(std::ostream& out, const SourcePosition& pos) {
37 if (pos.isInlined()) { 37 if (pos.isInlined()) {
38 out << "<inlined(" << pos.InliningId() << "):"; 38 out << "<inlined(" << pos.InliningId() << "):";
39 } else { 39 } else {
40 out << "<not inlined:"; 40 out << "<not inlined:";
41 } 41 }
42 out << pos.ScriptOffset() << ">"; 42 out << pos.ScriptOffset() << ">";
43 return out; 43 return out;
44 } 44 }
45 45
46 SourcePositionInfo SourcePosition::Info(
47 Handle<SharedFunctionInfo> function) const {
48 SourcePositionInfo result(*this, function);
49 Handle<Script> script(Script::cast(function->script()));
50 Script::PositionInfo pos;
51 if (Script::GetPositionInfo(script, ScriptOffset(), &pos,
52 Script::WITH_OFFSET)) {
53 result.line = pos.line;
54 result.column = pos.column;
55 }
56 return result;
57 }
58
59 std::vector<SourcePositionInfo> SourcePosition::InliningStack( 46 std::vector<SourcePositionInfo> SourcePosition::InliningStack(
60 CompilationInfo* cinfo) const { 47 CompilationInfo* cinfo) const {
61 SourcePosition pos = *this; 48 SourcePosition pos = *this;
62 std::vector<SourcePositionInfo> stack; 49 std::vector<SourcePositionInfo> stack;
63 while (pos.isInlined()) { 50 while (pos.isInlined()) {
64 const auto& inl = cinfo->inlined_functions()[pos.InliningId()]; 51 const auto& inl = cinfo->inlined_functions()[pos.InliningId()];
65 stack.push_back(pos.Info(inl.shared_info)); 52 stack.push_back(SourcePositionInfo(pos, inl.shared_info));
66 pos = inl.position.position; 53 pos = inl.position.position;
67 } 54 }
68 stack.push_back(pos.Info(cinfo->shared_info())); 55 stack.push_back(SourcePositionInfo(pos, cinfo->shared_info()));
69 return stack; 56 return stack;
70 } 57 }
71 58
72 std::vector<SourcePositionInfo> SourcePosition::InliningStack( 59 std::vector<SourcePositionInfo> SourcePosition::InliningStack(
73 Handle<Code> code) const { 60 Handle<Code> code) const {
74 Handle<DeoptimizationInputData> deopt_data( 61 Handle<DeoptimizationInputData> deopt_data(
75 DeoptimizationInputData::cast(code->deoptimization_data())); 62 DeoptimizationInputData::cast(code->deoptimization_data()));
76 SourcePosition pos = *this; 63 SourcePosition pos = *this;
77 std::vector<SourcePositionInfo> stack; 64 std::vector<SourcePositionInfo> stack;
78 while (pos.isInlined()) { 65 while (pos.isInlined()) {
79 InliningPosition inl = 66 InliningPosition inl =
80 deopt_data->InliningPositions()->get(pos.InliningId()); 67 deopt_data->InliningPositions()->get(pos.InliningId());
81 Handle<SharedFunctionInfo> function( 68 Handle<SharedFunctionInfo> function(
82 deopt_data->GetInlinedFunction(inl.inlined_function_id)); 69 deopt_data->GetInlinedFunction(inl.inlined_function_id));
83 stack.push_back(pos.Info(function)); 70 stack.push_back(SourcePositionInfo(pos, function));
84 pos = inl.position; 71 pos = inl.position;
85 } 72 }
86 Handle<SharedFunctionInfo> function( 73 Handle<SharedFunctionInfo> function(
87 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo())); 74 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo()));
88 stack.push_back(pos.Info(function)); 75 stack.push_back(SourcePositionInfo(pos, function));
89 return stack; 76 return stack;
90 } 77 }
91 78
92 void SourcePosition::Print(std::ostream& out, 79 void SourcePosition::Print(std::ostream& out,
93 SharedFunctionInfo* function) const { 80 SharedFunctionInfo* function) const {
94 Script* script = Script::cast(function->script()); 81 Script* script = Script::cast(function->script());
95 Object* source_name = script->name(); 82 Object* source_name = script->name();
96 Script::PositionInfo pos; 83 Script::PositionInfo pos;
97 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET); 84 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET);
98 out << "<"; 85 out << "<";
(...skipping 21 matching lines...) Expand all
120 } else { 107 } else {
121 SharedFunctionInfo* function = 108 SharedFunctionInfo* function =
122 deopt_data->GetInlinedFunction(inl.inlined_function_id); 109 deopt_data->GetInlinedFunction(inl.inlined_function_id);
123 Print(out, function); 110 Print(out, function);
124 } 111 }
125 out << " inlined at "; 112 out << " inlined at ";
126 inl.position.Print(out, code); 113 inl.position.Print(out, code);
127 } 114 }
128 } 115 }
129 116
117 SourcePositionInfo::SourcePositionInfo(SourcePosition pos,
118 Handle<SharedFunctionInfo> f)
119 : position(pos), function(f) {
120 Handle<Script> script(Script::cast(function->script()));
121 Script::PositionInfo info;
122 if (Script::GetPositionInfo(script, pos.ScriptOffset(), &info,
123 Script::WITH_OFFSET)) {
124 line = info.line;
125 column = info.column;
126 }
127 }
128
130 } // namespace internal 129 } // namespace internal
131 } // namespace v8 130 } // namespace v8
OLDNEW
« no previous file with comments | « src/source-position.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698