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

Side by Side Diff: src/ast.h

Issue 10759: Introduce text nodes (Closed)
Patch Set: Fixed repeated RemoveLast issue Created 12 years, 1 month 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 | « no previous file | src/ast.cc » ('j') | src/parser.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 class ThisFunction: public Expression { 1184 class ThisFunction: public Expression {
1185 public: 1185 public:
1186 virtual void Accept(Visitor* v); 1186 virtual void Accept(Visitor* v);
1187 }; 1187 };
1188 1188
1189 1189
1190 // ---------------------------------------------------------------------------- 1190 // ----------------------------------------------------------------------------
1191 // Regular expressions 1191 // Regular expressions
1192 1192
1193 1193
1194 #define FOR_EACH_REG_EXP_NODE_TYPE(VISIT) \
1195 VISIT(Disjunction) \
1196 VISIT(Alternative) \
1197 VISIT(Assertion) \
1198 VISIT(CharacterClass) \
1199 VISIT(Atom) \
1200 VISIT(Quantifier) \
1201 VISIT(Capture) \
1202 VISIT(Lookahead) \
1203 VISIT(Backreference) \
1204 VISIT(Empty)
1205
1206
1207 #define FORWARD_DECLARE(Name) class RegExp##Name;
1208 FOR_EACH_REG_EXP_NODE_TYPE(FORWARD_DECLARE)
1209 #undef FORWARD_DECLARE
1210
1211
1212 class RegExpTree: public ZoneObject { 1194 class RegExpTree: public ZoneObject {
1213 public: 1195 public:
1214 virtual ~RegExpTree() { } 1196 virtual ~RegExpTree() { }
1215 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; 1197 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
1216 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1198 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1217 RegExpNode* on_success, 1199 RegExpNode* on_success,
1218 RegExpNode* on_failure) = 0; 1200 RegExpNode* on_failure) = 0;
1201 virtual bool IsTextElement() { return false; }
1202 virtual void AppendToText(RegExpText* text);
1219 SmartPointer<const char> ToString(); 1203 SmartPointer<const char> ToString();
1220 #define MAKE_ASTYPE(Name) virtual RegExp##Name* As##Name(); 1204 #define MAKE_ASTYPE(Name) virtual RegExp##Name* As##Name();
1221 FOR_EACH_REG_EXP_NODE_TYPE(MAKE_ASTYPE) 1205 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
1222 #undef MAKE_ASTYPE 1206 #undef MAKE_ASTYPE
1223 }; 1207 };
1224 1208
1225 1209
1226 class RegExpDisjunction: public RegExpTree { 1210 class RegExpDisjunction: public RegExpTree {
1227 public: 1211 public:
1228 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) 1212 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives)
1229 : alternatives_(alternatives) { } 1213 : alternatives_(alternatives) { }
1230 virtual void* Accept(RegExpVisitor* visitor, void* data); 1214 virtual void* Accept(RegExpVisitor* visitor, void* data);
1231 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1215 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
(...skipping 13 matching lines...) Expand all
1245 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1229 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1246 RegExpNode* on_success, 1230 RegExpNode* on_success,
1247 RegExpNode* on_failure); 1231 RegExpNode* on_failure);
1248 virtual RegExpAlternative* AsAlternative(); 1232 virtual RegExpAlternative* AsAlternative();
1249 ZoneList<RegExpTree*>* nodes() { return nodes_; } 1233 ZoneList<RegExpTree*>* nodes() { return nodes_; }
1250 private: 1234 private:
1251 ZoneList<RegExpTree*>* nodes_; 1235 ZoneList<RegExpTree*>* nodes_;
1252 }; 1236 };
1253 1237
1254 1238
1239 class RegExpText: public RegExpTree {
1240 public:
1241 RegExpText() : elements_(2) { }
1242 virtual void* Accept(RegExpVisitor* visitor, void* data);
1243 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1244 RegExpNode* on_success,
1245 RegExpNode* on_failure);
1246 virtual RegExpText* AsText();
1247 virtual bool IsTextElement() { return true; }
1248 virtual void AppendToText(RegExpText* text);
1249 void AddElement(TextElement elm) { elements_.Add(elm); }
1250 ZoneList<TextElement>* elements() { return &elements_; }
1251 private:
1252 ZoneList<TextElement> elements_;
1253 };
1254
1255
1255 class RegExpAssertion: public RegExpTree { 1256 class RegExpAssertion: public RegExpTree {
1256 public: 1257 public:
1257 enum Type { 1258 enum Type {
1258 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT, 1259 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT,
1259 BOUNDARY, NON_BOUNDARY 1260 BOUNDARY, NON_BOUNDARY
1260 }; 1261 };
1261 explicit RegExpAssertion(Type type) : type_(type) { } 1262 explicit RegExpAssertion(Type type) : type_(type) { }
1262 virtual void* Accept(RegExpVisitor* visitor, void* data); 1263 virtual void* Accept(RegExpVisitor* visitor, void* data);
1263 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1264 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1264 RegExpNode* on_success, 1265 RegExpNode* on_success,
(...skipping 13 matching lines...) Expand all
1278 explicit RegExpCharacterClass(uc16 type) 1279 explicit RegExpCharacterClass(uc16 type)
1279 : ranges_(new ZoneList<CharacterRange>(2)), 1280 : ranges_(new ZoneList<CharacterRange>(2)),
1280 is_negated_(false) { 1281 is_negated_(false) {
1281 CharacterRange::AddClassEscape(type, ranges_); 1282 CharacterRange::AddClassEscape(type, ranges_);
1282 } 1283 }
1283 virtual void* Accept(RegExpVisitor* visitor, void* data); 1284 virtual void* Accept(RegExpVisitor* visitor, void* data);
1284 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1285 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1285 RegExpNode* on_success, 1286 RegExpNode* on_success,
1286 RegExpNode* on_failure); 1287 RegExpNode* on_failure);
1287 virtual RegExpCharacterClass* AsCharacterClass(); 1288 virtual RegExpCharacterClass* AsCharacterClass();
1289 virtual bool IsTextElement() { return true; }
1290 virtual void AppendToText(RegExpText* text);
1288 ZoneList<CharacterRange>* ranges() { return ranges_; } 1291 ZoneList<CharacterRange>* ranges() { return ranges_; }
1289 bool is_negated() { return is_negated_; } 1292 bool is_negated() { return is_negated_; }
1290 private: 1293 private:
1291 ZoneList<CharacterRange>* ranges_; 1294 ZoneList<CharacterRange>* ranges_;
1292 bool is_negated_; 1295 bool is_negated_;
1293 }; 1296 };
1294 1297
1295 1298
1296 class RegExpAtom: public RegExpTree { 1299 class RegExpAtom: public RegExpTree {
1297 public: 1300 public:
1298 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } 1301 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
1299 virtual void* Accept(RegExpVisitor* visitor, void* data); 1302 virtual void* Accept(RegExpVisitor* visitor, void* data);
1300 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1303 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1301 RegExpNode* on_success, 1304 RegExpNode* on_success,
1302 RegExpNode* on_failure); 1305 RegExpNode* on_failure);
1303 virtual RegExpAtom* AsAtom(); 1306 virtual RegExpAtom* AsAtom();
1307 virtual bool IsTextElement() { return true; }
1308 virtual void AppendToText(RegExpText* text);
1304 Vector<const uc16> data() { return data_; } 1309 Vector<const uc16> data() { return data_; }
1305 private: 1310 private:
1306 Vector<const uc16> data_; 1311 Vector<const uc16> data_;
1307 }; 1312 };
1308 1313
1309 1314
1310 class RegExpQuantifier: public RegExpTree { 1315 class RegExpQuantifier: public RegExpTree {
1311 public: 1316 public:
1312 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body) 1317 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body)
1313 : min_(min), 1318 : min_(min),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 private: 1424 private:
1420 static RegExpEmpty kInstance; 1425 static RegExpEmpty kInstance;
1421 }; 1426 };
1422 1427
1423 1428
1424 class RegExpVisitor BASE_EMBEDDED { 1429 class RegExpVisitor BASE_EMBEDDED {
1425 public: 1430 public:
1426 virtual ~RegExpVisitor() { } 1431 virtual ~RegExpVisitor() { }
1427 #define MAKE_CASE(Name) \ 1432 #define MAKE_CASE(Name) \
1428 virtual void* Visit##Name(RegExp##Name*, void* data) = 0; 1433 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
1429 FOR_EACH_REG_EXP_NODE_TYPE(MAKE_CASE) 1434 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
1430 #undef MAKE_CASE 1435 #undef MAKE_CASE
1431 }; 1436 };
1432 1437
1433 1438
1434 // ---------------------------------------------------------------------------- 1439 // ----------------------------------------------------------------------------
1435 // Basic visitor 1440 // Basic visitor
1436 // - leaf node visitors are abstract. 1441 // - leaf node visitors are abstract.
1437 1442
1438 class Visitor BASE_EMBEDDED { 1443 class Visitor BASE_EMBEDDED {
1439 public: 1444 public:
(...skipping 29 matching lines...) Expand all
1469 #undef DEF_VISIT 1474 #undef DEF_VISIT
1470 1475
1471 private: 1476 private:
1472 bool stack_overflow_; 1477 bool stack_overflow_;
1473 }; 1478 };
1474 1479
1475 1480
1476 } } // namespace v8::internal 1481 } } // namespace v8::internal
1477 1482
1478 #endif // V8_AST_H_ 1483 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698