1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <fstream> 6 #include <iostream> 7 8 #include "src/torque/declarable.h" 9 10 namespace v8 { 11 namespace internal { 12 namespace torque { 13 14 std::ostream& operator<<(std::ostream& os, const Callable& m) { 15 os << "callable " << m.name() << "(" << m.signature().parameter_types 16 << "): " << *m.signature().return_type; 17 return os; 18 } 19 20 std::ostream& operator<<(std::ostream& os, const Variable& v) { 21 os << "variable " << v.name() << ": " << *v.type(); 22 return os; 23 } 24 25 std::ostream& operator<<(std::ostream& os, const Builtin& b) { 26 os << "builtin " << *b.signature().return_type << " " << b.name() 27 << b.signature().parameter_types; 28 return os; 29 } 30 31 std::ostream& operator<<(std::ostream& os, const RuntimeFunction& b) { 32 os << "runtime function " << *b.signature().return_type << " " << b.name() 33 << b.signature().parameter_types; 34 return os; 35 } 36 37 std::string Variable::RValue() const { 38 if (!IsDefined()) { 39 ReportError("Reading uninitialized variable."); 40 } 41 if (type()->IsStructType()) { 42 return value(); 43 } 44 std::string result = "(*" + value() + ")"; 45 if (!IsConst()) result += ".value()"; 46 return result; 47 } 48 49 void PrintLabel(std::ostream& os, const Label& l, bool with_names) { 50 os << l.name(); 51 if (l.GetParameterCount() != 0) { 52 os << "("; 53 if (with_names) { 54 PrintCommaSeparatedList(os, l.GetParameters(), 55 [](Variable* v) -> std::string { 56 std::stringstream stream; 57 stream << v->name(); 58 stream << ": "; 59 stream << *(v->type()); 60 return stream.str(); 61 }); 62 } else { 63 PrintCommaSeparatedList( 64 os, l.GetParameters(), 65 [](Variable* v) -> const Type& { return *(v->type()); }); 66 } 67 os << ")"; 68 } 69 } 70 71 std::ostream& operator<<(std::ostream& os, const Label& l) { 72 PrintLabel(os, l, true); 73 return os; 74 } 75 76 std::ostream& operator<<(std::ostream& os, const Generic& g) { 77 os << "generic " << g.name() << "<"; 78 PrintCommaSeparatedList(os, g.declaration()->generic_parameters); 79 os << ">"; 80 81 return os; 82 } 83 84 size_t Label::next_id_ = 0; 85 86 } // namespace torque 87 } // namespace internal 88 } // namespace v8 89