| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // The result string is alive as long as the PrettyPrinter is alive. | 44 // The result string is alive as long as the PrettyPrinter is alive. |
| 45 const char* Print(AstNode* node); | 45 const char* Print(AstNode* node); |
| 46 const char* PrintExpression(FunctionLiteral* program); | 46 const char* PrintExpression(FunctionLiteral* program); |
| 47 const char* PrintProgram(FunctionLiteral* program); | 47 const char* PrintProgram(FunctionLiteral* program); |
| 48 | 48 |
| 49 void Print(const char* format, ...); | 49 void Print(const char* format, ...); |
| 50 | 50 |
| 51 // Print a node to stdout. | 51 // Print a node to stdout. |
| 52 static void PrintOut(AstNode* node); | 52 static void PrintOut(AstNode* node); |
| 53 | 53 |
| 54 virtual void VisitSlot(Slot* node); |
| 54 // Individual nodes | 55 // Individual nodes |
| 55 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); | 56 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 56 AST_NODE_LIST(DECLARE_VISIT) | 57 AST_NODE_LIST(DECLARE_VISIT) |
| 57 #undef DECLARE_VISIT | 58 #undef DECLARE_VISIT |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 char* output_; // output string buffer | 61 char* output_; // output string buffer |
| 61 int size_; // output_ size | 62 int size_; // output_ size |
| 62 int pos_; // current printing position | 63 int pos_; // current printing position |
| 63 | 64 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 | 79 |
| 79 // Prints the AST structure | 80 // Prints the AST structure |
| 80 class AstPrinter: public PrettyPrinter { | 81 class AstPrinter: public PrettyPrinter { |
| 81 public: | 82 public: |
| 82 AstPrinter(); | 83 AstPrinter(); |
| 83 virtual ~AstPrinter(); | 84 virtual ~AstPrinter(); |
| 84 | 85 |
| 85 const char* PrintProgram(FunctionLiteral* program); | 86 const char* PrintProgram(FunctionLiteral* program); |
| 86 | 87 |
| 87 // Individual nodes | 88 // Individual nodes |
| 89 virtual void VisitSlot(Slot* node); |
| 88 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); | 90 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 89 AST_NODE_LIST(DECLARE_VISIT) | 91 AST_NODE_LIST(DECLARE_VISIT) |
| 90 #undef DECLARE_VISIT | 92 #undef DECLARE_VISIT |
| 93 |
| 91 private: | 94 private: |
| 92 friend class IndentedScope; | 95 friend class IndentedScope; |
| 93 void PrintIndented(const char* txt); | 96 void PrintIndented(const char* txt); |
| 94 void PrintIndentedVisit(const char* s, AstNode* node); | 97 void PrintIndentedVisit(const char* s, AstNode* node); |
| 95 | 98 |
| 96 void PrintStatements(ZoneList<Statement*>* statements); | 99 void PrintStatements(ZoneList<Statement*>* statements); |
| 97 void PrintDeclarations(ZoneList<Declaration*>* declarations); | 100 void PrintDeclarations(ZoneList<Declaration*>* declarations); |
| 98 void PrintParameters(Scope* scope); | 101 void PrintParameters(Scope* scope); |
| 99 void PrintArguments(ZoneList<Expression*>* arguments); | 102 void PrintArguments(ZoneList<Expression*>* arguments); |
| 100 void PrintCaseClause(CaseClause* clause); | 103 void PrintCaseClause(CaseClause* clause); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 AttributesScope* attributes() { return attributes_scope_; } | 156 AttributesScope* attributes() { return attributes_scope_; } |
| 154 void set_attributes(AttributesScope* scope) { attributes_scope_ = scope; } | 157 void set_attributes(AttributesScope* scope) { attributes_scope_ = scope; } |
| 155 | 158 |
| 156 // Add an attribute to the currently opened attributes. | 159 // Add an attribute to the currently opened attributes. |
| 157 void AddAttribute(const char* name, Handle<String> value); | 160 void AddAttribute(const char* name, Handle<String> value); |
| 158 void AddAttribute(const char* name, const char* value); | 161 void AddAttribute(const char* name, const char* value); |
| 159 void AddAttribute(const char* name, int value); | 162 void AddAttribute(const char* name, int value); |
| 160 void AddAttribute(const char* name, bool value); | 163 void AddAttribute(const char* name, bool value); |
| 161 | 164 |
| 162 // AST node visit functions. | 165 // AST node visit functions. |
| 166 virtual void VisitSlot(Slot* node); |
| 163 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); | 167 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 164 AST_NODE_LIST(DECLARE_VISIT) | 168 AST_NODE_LIST(DECLARE_VISIT) |
| 165 #undef DECLARE_VISIT | 169 #undef DECLARE_VISIT |
| 166 | 170 |
| 167 private: | 171 private: |
| 168 int indent_; | 172 int indent_; |
| 169 TagScope* top_tag_scope_; | 173 TagScope* top_tag_scope_; |
| 170 AttributesScope* attributes_scope_; | 174 AttributesScope* attributes_scope_; |
| 171 | 175 |
| 172 // Utility function used by AddAttribute implementations. | 176 // Utility function used by AddAttribute implementations. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 private: | 214 private: |
| 211 JsonAstBuilder* builder_; | 215 JsonAstBuilder* builder_; |
| 212 int attribute_count_; | 216 int attribute_count_; |
| 213 }; | 217 }; |
| 214 | 218 |
| 215 #endif // DEBUG | 219 #endif // DEBUG |
| 216 | 220 |
| 217 } } // namespace v8::internal | 221 } } // namespace v8::internal |
| 218 | 222 |
| 219 #endif // V8_PRETTYPRINTER_H_ | 223 #endif // V8_PRETTYPRINTER_H_ |
| OLD | NEW |