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

Side by Side Diff: regexp2000/src/ast.h

Issue 11203: * Changed string-representation of regexps to handle unprintable chars. (Closed)
Patch Set: 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 | regexp2000/src/ast.cc » ('j') | regexp2000/src/ast.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 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 class RegExpTree: public ZoneObject { 1194 class RegExpTree: public ZoneObject {
1195 public: 1195 public:
1196 virtual ~RegExpTree() { } 1196 virtual ~RegExpTree() { }
1197 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; 1197 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
1198 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1198 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1199 RegExpNode* on_success, 1199 RegExpNode* on_success,
1200 RegExpNode* on_failure) = 0; 1200 RegExpNode* on_failure) = 0;
1201 virtual bool IsTextElement() { return false; } 1201 virtual bool IsTextElement() { return false; }
1202 virtual void AppendToText(RegExpText* text); 1202 virtual void AppendToText(RegExpText* text);
1203 SmartPointer<const char> ToString(); 1203 SmartPointer<const char> ToString();
1204 #define MAKE_ASTYPE(Name) virtual RegExp##Name* As##Name(); 1204 #define MAKE_ASTYPE(Name) \
1205 virtual RegExp##Name* As##Name(); \
1206 virtual bool Is##Name();
Christian Plesner Hansen 2008/11/17 10:54:35 I'm right on the edge of thinking that this is ove
1205 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) 1207 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
1206 #undef MAKE_ASTYPE 1208 #undef MAKE_ASTYPE
1207 }; 1209 };
1208 1210
1209 1211
1210 class RegExpDisjunction: public RegExpTree { 1212 class RegExpDisjunction: public RegExpTree {
1211 public: 1213 public:
1212 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) 1214 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives)
1213 : alternatives_(alternatives) { } 1215 : alternatives_(alternatives) { }
1214 virtual void* Accept(RegExpVisitor* visitor, void* data); 1216 virtual void* Accept(RegExpVisitor* visitor, void* data);
1215 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1217 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1216 RegExpNode* on_success, 1218 RegExpNode* on_success,
1217 RegExpNode* on_failure); 1219 RegExpNode* on_failure);
1218 virtual RegExpDisjunction* AsDisjunction(); 1220 virtual RegExpDisjunction* AsDisjunction();
1221 virtual bool IsDisjunction();
1219 ZoneList<RegExpTree*>* alternatives() { return alternatives_; } 1222 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
1220 private: 1223 private:
1221 ZoneList<RegExpTree*>* alternatives_; 1224 ZoneList<RegExpTree*>* alternatives_;
1222 }; 1225 };
1223 1226
1224 1227
1225 class RegExpAlternative: public RegExpTree { 1228 class RegExpAlternative: public RegExpTree {
1226 public: 1229 public:
1227 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { } 1230 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes) : nodes_(nodes) { }
1228 virtual void* Accept(RegExpVisitor* visitor, void* data); 1231 virtual void* Accept(RegExpVisitor* visitor, void* data);
1229 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1232 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1230 RegExpNode* on_success, 1233 RegExpNode* on_success,
1231 RegExpNode* on_failure); 1234 RegExpNode* on_failure);
1232 virtual RegExpAlternative* AsAlternative(); 1235 virtual RegExpAlternative* AsAlternative();
1236 virtual bool IsAlternative();
1233 ZoneList<RegExpTree*>* nodes() { return nodes_; } 1237 ZoneList<RegExpTree*>* nodes() { return nodes_; }
1234 private: 1238 private:
1235 ZoneList<RegExpTree*>* nodes_; 1239 ZoneList<RegExpTree*>* nodes_;
1236 }; 1240 };
1237 1241
1238 1242
1239 class RegExpText: public RegExpTree { 1243 class RegExpText: public RegExpTree {
1240 public: 1244 public:
1241 RegExpText() : elements_(2) { } 1245 RegExpText() : elements_(2) { }
1242 virtual void* Accept(RegExpVisitor* visitor, void* data); 1246 virtual void* Accept(RegExpVisitor* visitor, void* data);
1243 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1247 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1244 RegExpNode* on_success, 1248 RegExpNode* on_success,
1245 RegExpNode* on_failure); 1249 RegExpNode* on_failure);
1246 virtual RegExpText* AsText(); 1250 virtual RegExpText* AsText();
1251 virtual bool IsText();
1247 virtual bool IsTextElement() { return true; } 1252 virtual bool IsTextElement() { return true; }
1248 virtual void AppendToText(RegExpText* text); 1253 virtual void AppendToText(RegExpText* text);
1249 void AddElement(TextElement elm) { elements_.Add(elm); } 1254 void AddElement(TextElement elm) { elements_.Add(elm); }
1250 ZoneList<TextElement>* elements() { return &elements_; } 1255 ZoneList<TextElement>* elements() { return &elements_; }
1251 private: 1256 private:
1252 ZoneList<TextElement> elements_; 1257 ZoneList<TextElement> elements_;
1253 }; 1258 };
1254 1259
1255 1260
1256 class RegExpAssertion: public RegExpTree { 1261 class RegExpAssertion: public RegExpTree {
1257 public: 1262 public:
1258 enum Type { 1263 enum Type {
1259 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT, 1264 START_OF_LINE, START_OF_INPUT, END_OF_LINE, END_OF_INPUT,
1260 BOUNDARY, NON_BOUNDARY 1265 BOUNDARY, NON_BOUNDARY
1261 }; 1266 };
1262 explicit RegExpAssertion(Type type) : type_(type) { } 1267 explicit RegExpAssertion(Type type) : type_(type) { }
1263 virtual void* Accept(RegExpVisitor* visitor, void* data); 1268 virtual void* Accept(RegExpVisitor* visitor, void* data);
1264 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1269 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1265 RegExpNode* on_success, 1270 RegExpNode* on_success,
1266 RegExpNode* on_failure); 1271 RegExpNode* on_failure);
1267 virtual RegExpAssertion* AsAssertion(); 1272 virtual RegExpAssertion* AsAssertion();
1273 virtual bool IsAssertion();
1268 Type type() { return type_; } 1274 Type type() { return type_; }
1269 private: 1275 private:
1270 Type type_; 1276 Type type_;
1271 }; 1277 };
1272 1278
1273 1279
1274 class RegExpCharacterClass: public RegExpTree { 1280 class RegExpCharacterClass: public RegExpTree {
1275 public: 1281 public:
1276 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated) 1282 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
1277 : ranges_(ranges), 1283 : ranges_(ranges),
1278 is_negated_(is_negated) { } 1284 is_negated_(is_negated) { }
1279 explicit RegExpCharacterClass(uc16 type) 1285 explicit RegExpCharacterClass(uc16 type)
1280 : ranges_(new ZoneList<CharacterRange>(2)), 1286 : ranges_(new ZoneList<CharacterRange>(2)),
1281 is_negated_(false) { 1287 is_negated_(false) {
1282 CharacterRange::AddClassEscape(type, ranges_); 1288 CharacterRange::AddClassEscape(type, ranges_);
1283 } 1289 }
1284 virtual void* Accept(RegExpVisitor* visitor, void* data); 1290 virtual void* Accept(RegExpVisitor* visitor, void* data);
1285 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1291 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1286 RegExpNode* on_success, 1292 RegExpNode* on_success,
1287 RegExpNode* on_failure); 1293 RegExpNode* on_failure);
1288 virtual RegExpCharacterClass* AsCharacterClass(); 1294 virtual RegExpCharacterClass* AsCharacterClass();
1295 virtual bool IsCharacterClass();
1289 virtual bool IsTextElement() { return true; } 1296 virtual bool IsTextElement() { return true; }
1290 virtual void AppendToText(RegExpText* text); 1297 virtual void AppendToText(RegExpText* text);
1291 ZoneList<CharacterRange>* ranges() { return ranges_; } 1298 ZoneList<CharacterRange>* ranges() { return ranges_; }
1292 bool is_negated() { return is_negated_; } 1299 bool is_negated() { return is_negated_; }
1293 private: 1300 private:
1294 ZoneList<CharacterRange>* ranges_; 1301 ZoneList<CharacterRange>* ranges_;
1295 bool is_negated_; 1302 bool is_negated_;
1296 }; 1303 };
1297 1304
1298 1305
1299 class RegExpAtom: public RegExpTree { 1306 class RegExpAtom: public RegExpTree {
1300 public: 1307 public:
1301 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } 1308 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
1302 virtual void* Accept(RegExpVisitor* visitor, void* data); 1309 virtual void* Accept(RegExpVisitor* visitor, void* data);
1303 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1310 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1304 RegExpNode* on_success, 1311 RegExpNode* on_success,
1305 RegExpNode* on_failure); 1312 RegExpNode* on_failure);
1306 virtual RegExpAtom* AsAtom(); 1313 virtual RegExpAtom* AsAtom();
1314 virtual bool IsAtom();
1307 virtual bool IsTextElement() { return true; } 1315 virtual bool IsTextElement() { return true; }
1308 virtual void AppendToText(RegExpText* text); 1316 virtual void AppendToText(RegExpText* text);
1309 Vector<const uc16> data() { return data_; } 1317 Vector<const uc16> data() { return data_; }
1310 private: 1318 private:
1311 Vector<const uc16> data_; 1319 Vector<const uc16> data_;
1312 }; 1320 };
1313 1321
1314 1322
1315 class RegExpQuantifier: public RegExpTree { 1323 class RegExpQuantifier: public RegExpTree {
1316 public: 1324 public:
1317 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body) 1325 RegExpQuantifier(int min, int max, bool is_greedy, RegExpTree* body)
1318 : min_(min), 1326 : min_(min),
1319 max_(max), 1327 max_(max),
1320 is_greedy_(is_greedy), 1328 is_greedy_(is_greedy),
1321 body_(body) { } 1329 body_(body) { }
1322 virtual void* Accept(RegExpVisitor* visitor, void* data); 1330 virtual void* Accept(RegExpVisitor* visitor, void* data);
1323 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1331 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1324 RegExpNode* on_success, 1332 RegExpNode* on_success,
1325 RegExpNode* on_failure); 1333 RegExpNode* on_failure);
1326 static RegExpNode* ToNode(int min, 1334 static RegExpNode* ToNode(int min,
1327 int max, 1335 int max,
1328 bool is_greedy, 1336 bool is_greedy,
1329 RegExpTree* body, 1337 RegExpTree* body,
1330 RegExpCompiler* compiler, 1338 RegExpCompiler* compiler,
1331 RegExpNode* on_success, 1339 RegExpNode* on_success,
1332 RegExpNode* on_failure); 1340 RegExpNode* on_failure);
1333 virtual RegExpQuantifier* AsQuantifier(); 1341 virtual RegExpQuantifier* AsQuantifier();
1342 virtual bool IsQuantifier();
1334 int min() { return min_; } 1343 int min() { return min_; }
1335 int max() { return max_; } 1344 int max() { return max_; }
1336 bool is_greedy() { return is_greedy_; } 1345 bool is_greedy() { return is_greedy_; }
1337 RegExpTree* body() { return body_; } 1346 RegExpTree* body() { return body_; }
1338 // We just use a very large integer value as infinity because 2^30 1347 // We just use a very large integer value as infinity because 2^30
1339 // is infinite in practice. 1348 // is infinite in practice.
1340 static const int kInfinity = (1 << 30); 1349 static const int kInfinity = (1 << 30);
1341 private: 1350 private:
1342 int min_; 1351 int min_;
1343 int max_; 1352 int max_;
(...skipping 12 matching lines...) Expand all
1356 virtual void* Accept(RegExpVisitor* visitor, void* data); 1365 virtual void* Accept(RegExpVisitor* visitor, void* data);
1357 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1366 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1358 RegExpNode* on_success, 1367 RegExpNode* on_success,
1359 RegExpNode* on_failure); 1368 RegExpNode* on_failure);
1360 static RegExpNode* ToNode(RegExpTree* body, 1369 static RegExpNode* ToNode(RegExpTree* body,
1361 int index, 1370 int index,
1362 RegExpCompiler* compiler, 1371 RegExpCompiler* compiler,
1363 RegExpNode* on_success, 1372 RegExpNode* on_success,
1364 RegExpNode* on_failure); 1373 RegExpNode* on_failure);
1365 virtual RegExpCapture* AsCapture(); 1374 virtual RegExpCapture* AsCapture();
1375 virtual bool IsCapture();
1366 RegExpTree* body() { return body_; } 1376 RegExpTree* body() { return body_; }
1367 int index() { return index_; } 1377 int index() { return index_; }
1368 inline CaptureAvailability available() { return available_; } 1378 inline CaptureAvailability available() { return available_; }
1369 inline void set_available(CaptureAvailability availability) { 1379 inline void set_available(CaptureAvailability availability) {
1370 available_ = availability; 1380 available_ = availability;
1371 } 1381 }
1372 static int StartRegister(int index) { return index * 2; } 1382 static int StartRegister(int index) { return index * 2; }
1373 static int EndRegister(int index) { return index * 2 + 1; } 1383 static int EndRegister(int index) { return index * 2 + 1; }
1374 private: 1384 private:
1375 RegExpTree* body_; 1385 RegExpTree* body_;
1376 int index_; 1386 int index_;
1377 CaptureAvailability available_; 1387 CaptureAvailability available_;
1378 }; 1388 };
1379 1389
1380 1390
1381 class RegExpLookahead: public RegExpTree { 1391 class RegExpLookahead: public RegExpTree {
1382 public: 1392 public:
1383 RegExpLookahead(RegExpTree* body, bool is_positive) 1393 RegExpLookahead(RegExpTree* body, bool is_positive)
1384 : body_(body), 1394 : body_(body),
1385 is_positive_(is_positive) { } 1395 is_positive_(is_positive) { }
1386 virtual void* Accept(RegExpVisitor* visitor, void* data); 1396 virtual void* Accept(RegExpVisitor* visitor, void* data);
1387 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1397 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1388 RegExpNode* on_success, 1398 RegExpNode* on_success,
1389 RegExpNode* on_failure); 1399 RegExpNode* on_failure);
1390 virtual RegExpLookahead* AsLookahead(); 1400 virtual RegExpLookahead* AsLookahead();
1401 virtual bool IsLookahead();
1391 RegExpTree* body() { return body_; } 1402 RegExpTree* body() { return body_; }
1392 bool is_positive() { return is_positive_; } 1403 bool is_positive() { return is_positive_; }
1393 private: 1404 private:
1394 RegExpTree* body_; 1405 RegExpTree* body_;
1395 bool is_positive_; 1406 bool is_positive_;
1396 }; 1407 };
1397 1408
1398 1409
1399 class RegExpBackreference: public RegExpTree { 1410 class RegExpBackreference: public RegExpTree {
1400 public: 1411 public:
1401 explicit RegExpBackreference(RegExpCapture* capture) 1412 explicit RegExpBackreference(RegExpCapture* capture)
1402 : capture_(capture) { } 1413 : capture_(capture) { }
1403 virtual void* Accept(RegExpVisitor* visitor, void* data); 1414 virtual void* Accept(RegExpVisitor* visitor, void* data);
1404 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1415 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1405 RegExpNode* on_success, 1416 RegExpNode* on_success,
1406 RegExpNode* on_failure); 1417 RegExpNode* on_failure);
1407 virtual RegExpBackreference* AsBackreference(); 1418 virtual RegExpBackreference* AsBackreference();
1419 virtual bool IsBackreference();
1408 int index() { return capture_->index(); } 1420 int index() { return capture_->index(); }
1409 RegExpCapture* capture() { return capture_; } 1421 RegExpCapture* capture() { return capture_; }
1410 private: 1422 private:
1411 RegExpCapture* capture_; 1423 RegExpCapture* capture_;
1412 }; 1424 };
1413 1425
1414 1426
1415 class RegExpEmpty: public RegExpTree { 1427 class RegExpEmpty: public RegExpTree {
1416 public: 1428 public:
1417 RegExpEmpty() { } 1429 RegExpEmpty() { }
1418 virtual void* Accept(RegExpVisitor* visitor, void* data); 1430 virtual void* Accept(RegExpVisitor* visitor, void* data);
1419 virtual RegExpNode* ToNode(RegExpCompiler* compiler, 1431 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
1420 RegExpNode* on_success, 1432 RegExpNode* on_success,
1421 RegExpNode* on_failure); 1433 RegExpNode* on_failure);
1422 virtual RegExpEmpty* AsEmpty(); 1434 virtual RegExpEmpty* AsEmpty();
1435 virtual bool IsEmpty();
1423 static RegExpEmpty* GetInstance() { return &kInstance; } 1436 static RegExpEmpty* GetInstance() { return &kInstance; }
1424 private: 1437 private:
1425 static RegExpEmpty kInstance; 1438 static RegExpEmpty kInstance;
1426 }; 1439 };
1427 1440
1428 1441
1429 class RegExpVisitor BASE_EMBEDDED { 1442 class RegExpVisitor BASE_EMBEDDED {
1430 public: 1443 public:
1431 virtual ~RegExpVisitor() { } 1444 virtual ~RegExpVisitor() { }
1432 #define MAKE_CASE(Name) \ 1445 #define MAKE_CASE(Name) \
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 #undef DEF_VISIT 1487 #undef DEF_VISIT
1475 1488
1476 private: 1489 private:
1477 bool stack_overflow_; 1490 bool stack_overflow_;
1478 }; 1491 };
1479 1492
1480 1493
1481 } } // namespace v8::internal 1494 } } // namespace v8::internal
1482 1495
1483 #endif // V8_AST_H_ 1496 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | regexp2000/src/ast.cc » ('j') | regexp2000/src/ast.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698