iv-phonic 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'hoe'
6
6
  require 'pp'
7
7
  $root = File.dirname(__FILE__)
8
8
  $name = 'iv-phonic'
9
- $version = '0.0.9'
9
+ $version = '0.1.0'
10
10
 
11
11
  directory "ext/include/iv"
12
12
 
data/ext/include/iv/ast.h CHANGED
@@ -116,6 +116,10 @@ class AstNode : public AstNodeBase<Factory> {
116
116
  public:
117
117
  virtual ~AstNode() = 0;
118
118
 
119
+ typedef typename SpaceVector<Factory, Statement<Factory>*>::type Statements;
120
+ typedef typename SpaceVector<Factory, Identifier<Factory>*>::type Identifiers;
121
+ typedef typename SpaceVector<Factory, Expression<Factory>*>::type Expressions;
122
+
119
123
  STATEMENT_NODE_LIST(DECLARE_NODE_TYPE_BASE)
120
124
  EXPRESSION_NODE_LIST(DECLARE_NODE_TYPE_BASE)
121
125
 
@@ -210,7 +214,8 @@ class Inherit<Factory, kNamedOnlyBreakableStatement>
210
214
  INHERIT(NamedOnlyBreakableStatement);
211
215
 
212
216
  template<typename Factory>
213
- class NamedOnlyBreakableStatement : public NamedOnlyBreakableStatementBase<Factory> {
217
+ class NamedOnlyBreakableStatement
218
+ : public NamedOnlyBreakableStatementBase<Factory> {
214
219
  public:
215
220
  DECLARE_NODE_TYPE(NamedOnlyBreakableStatement)
216
221
  };
@@ -223,7 +228,8 @@ class Inherit<Factory, kAnonymousBreakableStatement>
223
228
  INHERIT(AnonymousBreakableStatement);
224
229
 
225
230
  template<typename Factory>
226
- class AnonymousBreakableStatement : public AnonymousBreakableStatementBase<Factory> {
231
+ class AnonymousBreakableStatement
232
+ : public AnonymousBreakableStatementBase<Factory> {
227
233
  public:
228
234
  DECLARE_NODE_TYPE(AnonymousBreakableStatement)
229
235
  };
@@ -238,20 +244,15 @@ INHERIT(Block);
238
244
  template<typename Factory>
239
245
  class Block : public BlockBase<Factory> {
240
246
  public:
241
- typedef typename SpaceVector<Factory, Statement<Factory>*>::type Statements;
242
- explicit Block(Factory* factory)
243
- : body_(typename Statements::allocator_type(factory)) { }
244
-
245
- void AddStatement(Statement<Factory>* stmt) {
246
- body_.push_back(stmt);
247
- }
248
-
247
+ typedef typename AstNode<Factory>::Statements Statements;
248
+ explicit Block(Statements* body)
249
+ : body_(body) { }
249
250
  inline const Statements& body() const {
250
- return body_;
251
+ return *body_;
251
252
  }
252
253
  DECLARE_DERIVED_NODE_TYPE(Block)
253
254
  private:
254
- Statements body_;
255
+ Statements* body_;
255
256
  };
256
257
 
257
258
  // FunctionStatement
@@ -309,16 +310,11 @@ class VariableStatement : public VariableStatementBase<Factory> {
309
310
  typedef typename SpaceVector<
310
311
  Factory,
311
312
  Declaration<Factory>*>::type Declarations;
312
- VariableStatement(Token::Type type, Factory* factory)
313
+ VariableStatement(Token::Type type, Declarations* decls)
313
314
  : is_const_(type == Token::CONST),
314
- decls_(typename Declarations::allocator_type(factory)) { }
315
-
316
- void AddDeclaration(Declaration<Factory>* decl) {
317
- decls_.push_back(decl);
318
- }
319
-
315
+ decls_(decls) { }
320
316
  inline const Declarations& decls() const {
321
- return decls_;
317
+ return *decls_;
322
318
  }
323
319
  inline bool IsConst() const {
324
320
  return is_const_;
@@ -326,7 +322,7 @@ class VariableStatement : public VariableStatementBase<Factory> {
326
322
  DECLARE_DERIVED_NODE_TYPE(VariableStatement)
327
323
  private:
328
324
  const bool is_const_;
329
- Declarations decls_;
325
+ Declarations* decls_;
330
326
  };
331
327
 
332
328
  // Declaration
@@ -649,16 +645,14 @@ INHERIT(CaseClause);
649
645
  template<typename Factory>
650
646
  class CaseClause : public CaseClauseBase<Factory> {
651
647
  public:
652
- typedef typename SpaceVector<Factory, Statement<Factory>*>::type Statements;
648
+ typedef typename AstNode<Factory>::Statements Statements;
653
649
  explicit CaseClause(bool is_default,
654
- Expression<Factory>* expr, Factory* factory)
650
+ Expression<Factory>* expr,
651
+ Statements* body)
655
652
  : expr_(expr),
656
- body_(typename Statements::allocator_type(factory)),
653
+ body_(body),
657
654
  default_(is_default) {
658
655
  }
659
- void AddStatement(Statement<Factory>* stmt) {
660
- body_.push_back(stmt);
661
- }
662
656
  inline bool IsDefault() const {
663
657
  return default_;
664
658
  }
@@ -666,11 +660,11 @@ class CaseClause : public CaseClauseBase<Factory> {
666
660
  return expr_;
667
661
  }
668
662
  inline const Statements& body() const {
669
- return body_;
663
+ return *body_;
670
664
  }
671
665
  private:
672
666
  Expression<Factory>* expr_;
673
- Statements body_;
667
+ Statements* body_;
674
668
  bool default_;
675
669
  };
676
670
 
@@ -686,20 +680,16 @@ class SwitchStatement : public SwitchStatementBase<Factory> {
686
680
  public:
687
681
  typedef typename SpaceVector<Factory, CaseClause<Factory>*>::type CaseClauses;
688
682
  SwitchStatement(Expression<Factory>* expr,
689
- Factory* factory)
683
+ CaseClauses* clauses)
690
684
  : expr_(expr),
691
- clauses_(typename CaseClauses::allocator_type(factory)) {
692
- }
693
-
694
- void AddCaseClause(CaseClause<Factory>* clause) {
695
- clauses_.push_back(clause);
685
+ clauses_(clauses) {
696
686
  }
697
687
  inline Expression<Factory>* expr() const { return expr_; }
698
- inline const CaseClauses& clauses() const { return clauses_; }
688
+ inline const CaseClauses& clauses() const { return *clauses_; }
699
689
  DECLARE_DERIVED_NODE_TYPE(SwitchStatement)
700
690
  private:
701
691
  Expression<Factory>* expr_;
702
- CaseClauses clauses_;
692
+ CaseClauses* clauses_;
703
693
  };
704
694
 
705
695
  // ThrowStatement
@@ -914,8 +904,7 @@ class StringLiteral : public StringLiteralBase<Factory> {
914
904
  public:
915
905
  typedef typename SpaceUString<Factory>::type value_type;
916
906
  StringLiteral(const std::vector<uc16>& buffer,
917
- Factory* factory)
918
- {
907
+ Factory* factory) {
919
908
  InitializeStringLiteral(buffer, factory);
920
909
  }
921
910
 
@@ -1133,23 +1122,22 @@ class Inherit<Factory, kArrayLiteral>
1133
1122
  };
1134
1123
  INHERIT(ArrayLiteral);
1135
1124
 
1125
+
1126
+ // items is NULL able
1136
1127
  template<typename Factory>
1137
1128
  class ArrayLiteral : public ArrayLiteralBase<Factory> {
1138
1129
  public:
1139
- typedef typename SpaceVector<Factory, Expression<Factory>*>::type Expressions;
1130
+ typedef typename AstNode<Factory>::Expressions Expressions;
1140
1131
 
1141
- explicit ArrayLiteral(Factory* factory)
1142
- : items_(typename Expressions::allocator_type(factory)) {
1143
- }
1144
- inline void AddItem(Expression<Factory>* expr) {
1145
- items_.push_back(expr);
1132
+ explicit ArrayLiteral(Expressions* items)
1133
+ : items_(items) {
1146
1134
  }
1147
1135
  inline const Expressions& items() const {
1148
- return items_;
1136
+ return *items_;
1149
1137
  }
1150
1138
  DECLARE_DERIVED_NODE_TYPE(ArrayLiteral)
1151
1139
  private:
1152
- Expressions items_;
1140
+ Expressions* items_;
1153
1141
  };
1154
1142
 
1155
1143
  // ObjectLiteral
@@ -1171,30 +1159,30 @@ class ObjectLiteral : public ObjectLiteralBase<Factory> {
1171
1159
  Identifier<Factory>*,
1172
1160
  Expression<Factory>*> Property;
1173
1161
  typedef typename SpaceVector<Factory, Property>::type Properties;
1174
- explicit ObjectLiteral(Factory* factory)
1175
- : properties_(typename Properties::allocator_type(factory)) {
1162
+ explicit ObjectLiteral(Properties* properties)
1163
+ : properties_(properties) {
1176
1164
  }
1177
1165
 
1178
- inline void AddDataProperty(Identifier<Factory>* key,
1179
- Expression<Factory>* val) {
1180
- AddPropertyDescriptor(DATA, key, val);
1166
+ static inline void AddDataProperty(Properties* prop,
1167
+ Identifier<Factory>* key,
1168
+ Expression<Factory>* val) {
1169
+ prop->push_back(std::tr1::make_tuple(DATA, key, val));
1181
1170
  }
1182
- inline void AddAccessor(PropertyDescriptorType type,
1183
- Identifier<Factory>* key,
1184
- Expression<Factory>* val) {
1185
- AddPropertyDescriptor(type, key, val);
1171
+
1172
+ static inline void AddAccessor(Properties* prop,
1173
+ PropertyDescriptorType type,
1174
+ Identifier<Factory>* key,
1175
+ Expression<Factory>* val) {
1176
+ prop->push_back(std::tr1::make_tuple(type, key, val));
1186
1177
  }
1178
+
1187
1179
  inline const Properties& properties() const {
1188
- return properties_;
1180
+ return *properties_;
1189
1181
  }
1190
1182
  DECLARE_DERIVED_NODE_TYPE(ObjectLiteral)
1183
+
1191
1184
  private:
1192
- inline void AddPropertyDescriptor(PropertyDescriptorType type,
1193
- Identifier<Factory>* key,
1194
- Expression<Factory>* val) {
1195
- properties_.push_back(std::tr1::make_tuple(type, key, val));
1196
- }
1197
- Properties properties_;
1185
+ Properties* properties_;
1198
1186
  };
1199
1187
 
1200
1188
  // FunctionLiteral
@@ -1207,8 +1195,8 @@ INHERIT(FunctionLiteral);
1207
1195
  template<typename Factory>
1208
1196
  class FunctionLiteral : public FunctionLiteralBase<Factory> {
1209
1197
  public:
1210
- typedef typename SpaceVector<Factory, Statement<Factory>*>::type Statements;
1211
- typedef typename SpaceVector<Factory, Identifier<Factory>*>::type Identifiers;
1198
+ typedef typename AstNode<Factory>::Statements Statements;
1199
+ typedef typename AstNode<Factory>::Identifiers Identifiers;
1212
1200
  enum DeclType {
1213
1201
  DECLARATION,
1214
1202
  STATEMENT,
@@ -1369,19 +1357,18 @@ INHERIT(FunctionCall);
1369
1357
  template<typename Factory>
1370
1358
  class FunctionCall : public FunctionCallBase<Factory> {
1371
1359
  public:
1372
- typedef typename SpaceVector<Factory, Expression<Factory>*>::type Expressions;
1360
+ typedef typename AstNode<Factory>::Expressions Expressions;
1373
1361
  FunctionCall(Expression<Factory>* target,
1374
- Factory* factory)
1362
+ Expressions* args)
1375
1363
  : target_(target),
1376
- args_(typename Expressions::allocator_type(factory)) {
1364
+ args_(args) {
1377
1365
  }
1378
- void AddArgument(Expression<Factory>* expr) { args_.push_back(expr); }
1379
1366
  inline Expression<Factory>* target() const { return target_; }
1380
- inline const Expressions& args() const { return args_; }
1367
+ inline const Expressions& args() const { return *args_; }
1381
1368
  DECLARE_DERIVED_NODE_TYPE(FunctionCall)
1382
1369
  private:
1383
1370
  Expression<Factory>* target_;
1384
- Expressions args_;
1371
+ Expressions* args_;
1385
1372
  };
1386
1373
 
1387
1374
  // ConstructorCall
@@ -1394,19 +1381,18 @@ INHERIT(ConstructorCall);
1394
1381
  template<typename Factory>
1395
1382
  class ConstructorCall : public ConstructorCallBase<Factory> {
1396
1383
  public:
1397
- typedef typename SpaceVector<Factory, Expression<Factory>*>::type Expressions;
1384
+ typedef typename AstNode<Factory>::Expressions Expressions;
1398
1385
  ConstructorCall(Expression<Factory>* target,
1399
- Factory* factory)
1386
+ Expressions* args)
1400
1387
  : target_(target),
1401
- args_(typename Expressions::allocator_type(factory)) {
1388
+ args_(args) {
1402
1389
  }
1403
- void AddArgument(Expression<Factory>* expr) { args_.push_back(expr); }
1404
1390
  inline Expression<Factory>* target() const { return target_; }
1405
- inline const Expressions& args() const { return args_; }
1391
+ inline const Expressions& args() const { return *args_; }
1406
1392
  DECLARE_DERIVED_NODE_TYPE(ConstructorCall)
1407
1393
  private:
1408
1394
  Expression<Factory>* target_;
1409
- Expressions args_;
1395
+ Expressions* args_;
1410
1396
  };
1411
1397
 
1412
1398
  } } } // namespace iv::core::ast
@@ -79,26 +79,25 @@ class BasicAstFactory {
79
79
  FunctionLiteral(type, static_cast<Factory*>(this));
80
80
  }
81
81
 
82
- ArrayLiteral* NewArrayLiteral() {
83
- return new (static_cast<Factory*>(this))
84
- ArrayLiteral(static_cast<Factory*>(this));
82
+ ArrayLiteral* NewArrayLiteral(Expressions* items) {
83
+ return new (static_cast<Factory*>(this)) ArrayLiteral(items);
85
84
  }
86
85
 
87
- ObjectLiteral* NewObjectLiteral() {
88
- return new (static_cast<Factory*>(this))
89
- ObjectLiteral(static_cast<Factory*>(this));
86
+ ObjectLiteral*
87
+ NewObjectLiteral(typename ObjectLiteral::Properties* properties) {
88
+ return new (static_cast<Factory*>(this)) ObjectLiteral(properties);
90
89
  }
91
90
 
92
91
  template<typename T>
93
92
  T** NewPtr() {
94
- return new (static_cast<Factory*>(this)->New(sizeof(T*))) T*(NULL);
93
+ return new (static_cast<Factory*>(this)->New(sizeof(T*))) T*(NULL); // NOLINT
95
94
  }
96
95
 
97
- Identifiers* NewLabels() {
98
- void* place = static_cast<Factory*>(this)->New(sizeof(Identifiers));
99
- return new (place)
100
- Identifiers(
101
- typename Identifiers::allocator_type(static_cast<Factory*>(this)));
96
+ template<typename T>
97
+ typename SpaceVector<Factory, T>::type* NewVector() {
98
+ typedef typename SpaceVector<Factory, T>::type Vector;
99
+ return new (static_cast<Factory*>(this)->New(sizeof(Vector)))
100
+ Vector(typename Vector::allocator_type(static_cast<Factory*>(this)));
102
101
  }
103
102
 
104
103
  NullLiteral* NewNullLiteral() {
@@ -137,13 +136,14 @@ class BasicAstFactory {
137
136
  return new (static_cast<Factory*>(this)) FunctionDeclaration(func);
138
137
  }
139
138
 
140
- Block* NewBlock() {
141
- return new (static_cast<Factory*>(this)) Block(static_cast<Factory*>(this));
139
+ Block* NewBlock(Statements* body) {
140
+ return new (static_cast<Factory*>(this)) Block(body);
142
141
  }
143
142
 
144
- VariableStatement* NewVariableStatement(Token::Type token) {
143
+ VariableStatement* NewVariableStatement(Token::Type token,
144
+ Declarations* decls) {
145
145
  return new (static_cast<Factory*>(this))
146
- VariableStatement(token, static_cast<Factory*>(this));
146
+ VariableStatement(token, decls);
147
147
  }
148
148
 
149
149
  Declaration* NewDeclaration(Identifier* name, Expression* expr) {
@@ -207,14 +207,13 @@ class BasicAstFactory {
207
207
  return new (static_cast<Factory*>(this)) WithStatement(expr, stmt);
208
208
  }
209
209
 
210
- SwitchStatement* NewSwitchStatement(Expression* expr) {
211
- return new (static_cast<Factory*>(this))
212
- SwitchStatement(expr, static_cast<Factory*>(this));
210
+ SwitchStatement* NewSwitchStatement(Expression* expr, CaseClauses* clauses) {
211
+ return new (static_cast<Factory*>(this)) SwitchStatement(expr, clauses);
213
212
  }
214
213
 
215
- CaseClause* NewCaseClause(bool is_default, Expression* expr) {
216
- return new (static_cast<Factory*>(this))
217
- CaseClause(is_default, expr, static_cast<Factory*>(this));
214
+ CaseClause* NewCaseClause(bool is_default,
215
+ Expression* expr, Statements* body) {
216
+ return new (static_cast<Factory*>(this)) CaseClause(is_default, expr, body);
218
217
  }
219
218
 
220
219
  ThrowStatement* NewThrowStatement(Expression* expr) {
@@ -264,14 +263,12 @@ class BasicAstFactory {
264
263
  return new (static_cast<Factory*>(this)) PostfixExpression(op, expr);
265
264
  }
266
265
 
267
- FunctionCall* NewFunctionCall(Expression* expr) {
268
- return new (static_cast<Factory*>(this))
269
- FunctionCall(expr, static_cast<Factory*>(this));
266
+ FunctionCall* NewFunctionCall(Expression* expr, Expressions* args) {
267
+ return new (static_cast<Factory*>(this)) FunctionCall(expr, args);
270
268
  }
271
269
 
272
- ConstructorCall* NewConstructorCall(Expression* target) {
273
- return new (static_cast<Factory*>(this))
274
- ConstructorCall(target, static_cast<Factory*>(this));
270
+ ConstructorCall* NewConstructorCall(Expression* target, Expressions* args) {
271
+ return new (static_cast<Factory*>(this)) ConstructorCall(target, args);
275
272
  }
276
273
 
277
274
  IndexAccess* NewIndexAccess(Expression* expr,
@@ -724,8 +724,8 @@ inline Category GetCategory(uint16_t c) {
724
724
  return static_cast<Category>(kCategoryCache[c]);
725
725
  }
726
726
  const int result =
727
- upper_bound(kCategoryKeys.begin(),
728
- kCategoryKeys.end(), c) - kCategoryKeys.begin() - 1;
727
+ static_cast<int>(upper_bound(kCategoryKeys.begin(),
728
+ kCategoryKeys.end(), c) - kCategoryKeys.begin() - 1);
729
729
  assert(result < static_cast<int>(kCategoryKeys.size()));
730
730
  const int high = kCategoryValues[result * 2];
731
731
  if (c <= high) {
@@ -816,7 +816,7 @@ inline uint16_t ToLowerCase(uint16_t c) {
816
816
  std::tr1::array<uint16_t, 101>::const_iterator it =
817
817
  upper_bound(kLowerCaseKeys.begin(),
818
818
  kLowerCaseKeys.end(), c) - 1;
819
- const int result = it - kLowerCaseKeys.begin();
819
+ const int result = static_cast<int>(it - kLowerCaseKeys.begin());
820
820
  assert(result < 101);
821
821
  if (result >= 0) {
822
822
  bool by2 = false;
@@ -852,7 +852,7 @@ inline uint16_t ToUpperCase(uint16_t c) {
852
852
  std::tr1::array<uint16_t, 113>::const_iterator it =
853
853
  upper_bound(kUpperCaseKeys.begin(),
854
854
  kUpperCaseKeys.end(), c) - 1;
855
- const int result = it - kUpperCaseKeys.begin();
855
+ const int result = static_cast<int>(it - kUpperCaseKeys.begin());
856
856
  assert(result < 113);
857
857
  if (result >= 0) {
858
858
  bool by2 = false;
@@ -390,7 +390,6 @@ class Parser {
390
390
  def_(def) {
391
391
  description_ = full_description(desc);
392
392
  }
393
- ~option_with_value() { }
394
393
 
395
394
  const T& get() const {
396
395
  return def_;
@@ -458,6 +457,81 @@ class Parser {
458
457
  std::string description_;
459
458
  };
460
459
 
460
+ template <class T>
461
+ class option_with_value_list : public option_base {
462
+ public:
463
+ option_with_value_list(const std::string& name,
464
+ char short_name,
465
+ const std::string& desc)
466
+ : name_(name),
467
+ short_name_(short_name),
468
+ has_(false),
469
+ def_() {
470
+ description_ = full_description(desc);
471
+ }
472
+
473
+ const std::vector<T>& get() const {
474
+ return def_;
475
+ }
476
+
477
+ bool has_value() const { return true; }
478
+
479
+ bool set() {
480
+ return false;
481
+ }
482
+
483
+ bool set(const std::string& value) {
484
+ try {
485
+ def_.push_back(read(value));
486
+ has_ = true;
487
+ } catch(const std::exception &e) {
488
+ return false;
489
+ }
490
+ return true;
491
+ }
492
+
493
+ bool has_set() const {
494
+ return has_;
495
+ }
496
+
497
+ bool valid() const {
498
+ return true;
499
+ }
500
+
501
+ bool must() const {
502
+ return false;
503
+ }
504
+
505
+ const std::string& name() const {
506
+ return name_;
507
+ }
508
+
509
+ char short_name() const {
510
+ return short_name_;
511
+ }
512
+
513
+ const std::string& description() const {
514
+ return description_;
515
+ }
516
+
517
+ std::string short_description() const {
518
+ return "--"+name_+"="+detail::readable_typename<T>();
519
+ }
520
+
521
+ protected:
522
+ std::string full_description(const std::string& desc) {
523
+ return desc;
524
+ }
525
+
526
+ virtual T read(const std::string& s) = 0;
527
+
528
+ std::string name_;
529
+ char short_name_;
530
+ bool has_;
531
+ std::vector<T> def_;
532
+ std::string description_;
533
+ };
534
+
461
535
  template <class T, class F>
462
536
  class option_with_value_with_reader : public option_with_value<T> {
463
537
  public:
@@ -479,6 +553,25 @@ class Parser {
479
553
  F reader;
480
554
  };
481
555
 
556
+ template <class T, class F>
557
+ class option_with_value_list_with_reader : public option_with_value_list<T> {
558
+ public:
559
+ option_with_value_list_with_reader(const std::string& name,
560
+ char short_name,
561
+ const std::string& desc,
562
+ F reader)
563
+ : option_with_value_list<T>(name, short_name, desc),
564
+ reader_(reader) {
565
+ }
566
+
567
+ private:
568
+ T read(const std::string& s) {
569
+ return reader_(s);
570
+ }
571
+
572
+ F reader_;
573
+ };
574
+
482
575
  public:
483
576
  typedef std::map<std::string, option_base*> OptionMap;
484
577
  typedef std::vector<option_base*> OptionVector;
@@ -534,6 +627,28 @@ class Parser {
534
627
  ordered_.push_back(ptr);
535
628
  }
536
629
 
630
+ template <class T>
631
+ void AddList(const std::string& key,
632
+ const std::string& name = "",
633
+ char short_name = 0,
634
+ const std::string& desc = "") {
635
+ AddList<T>(key, name, short_name, desc, default_reader<T>());
636
+ }
637
+
638
+ template <class T, class F>
639
+ void AddList(const std::string& key,
640
+ const std::string& name = "",
641
+ char short_name = 0,
642
+ const std::string& desc = "",
643
+ F reader = F()) {
644
+ assert(options_.count(key) == 0);
645
+ option_base* const ptr =
646
+ new option_with_value_list_with_reader<T, F>(
647
+ name, short_name, desc, reader);
648
+ options_[key] = ptr;
649
+ ordered_.push_back(ptr);
650
+ }
651
+
537
652
  void set_footer(const std::string& f) {
538
653
  footer_ = f;
539
654
  }
@@ -549,7 +664,7 @@ class Parser {
549
664
  }
550
665
 
551
666
  template <class T>
552
- const T& get(const std::string& key) const {
667
+ const T& Get(const std::string& key) const {
553
668
  const OptionMap::const_iterator it = options_.find(key);
554
669
  assert(it != options_.end());
555
670
  const option_with_value<T> *p = dynamic_cast< //NOLINT
@@ -558,6 +673,16 @@ class Parser {
558
673
  return p->get();
559
674
  }
560
675
 
676
+ template<typename T>
677
+ const std::vector<T>& GetList(const std::string& key) const {
678
+ const OptionMap::const_iterator it = options_.find(key);
679
+ assert(it != options_.end());
680
+ const option_with_value_list<T> *p = dynamic_cast< //NOLINT
681
+ const option_with_value_list<T>*>(it->second);
682
+ assert(p != NULL);
683
+ return p->get();
684
+ }
685
+
561
686
  const std::vector<std::string>& rest() const {
562
687
  return others_;
563
688
  }
@@ -8,7 +8,6 @@
8
8
  #include <tr1/cstdint>
9
9
  #include <tr1/cmath>
10
10
  #include "character.h"
11
- #include "dtoa.h"
12
11
  #include "ustringpiece.h"
13
12
  #include "none.h"
14
13
  namespace iv {
@@ -18,6 +17,7 @@ template<typename T>
18
17
  class Conversions {
19
18
  public:
20
19
  static const double kNaN;
20
+ static const double kInf;
21
21
  static const int kMaxSignificantDigits = 772;
22
22
  static const std::string kInfinity;
23
23
  static const double DoubleToInt32_Two32;
@@ -28,6 +28,9 @@ class Conversions {
28
28
  template<typename T>
29
29
  const double Conversions<T>::kNaN = std::numeric_limits<double>::quiet_NaN();
30
30
 
31
+ template<typename T>
32
+ const double Conversions<T>::kInf = std::numeric_limits<double>::infinity();
33
+
31
34
  template<typename T>
32
35
  const std::string Conversions<T>::kInfinity = "Infinity";
33
36
 
@@ -346,7 +349,8 @@ inline double StringToIntegerWithRadix(Iter it, Iter last,
346
349
  return Conversions::kNaN;
347
350
  }
348
351
 
349
- double result = 0;
352
+ // TODO(Constellation) precision version
353
+ double result = 0.0;
350
354
  const Iter start = it;
351
355
  for (; it != last; ++it) {
352
356
  const int val = Radix36Value(*it);
@@ -371,6 +375,25 @@ inline double StringToIntegerWithRadix(const UStringPiece& range,
371
375
  radix, strip_prefix);
372
376
  }
373
377
 
378
+ template<typename Iter>
379
+ inline double ParseIntegerOverflow(Iter it, Iter last, int radix) {
380
+ double number = 0.0;
381
+ double multiplier = 1.0;
382
+ for (--it, --last; last != it; --last) {
383
+ if (multiplier == Conversions::kInf) {
384
+ if (*last != '0') {
385
+ number = Conversions::kInf;
386
+ break;
387
+ }
388
+ } else {
389
+ const int digit = Radix36Value(*last);
390
+ number += digit * multiplier;
391
+ }
392
+ multiplier *= radix;
393
+ }
394
+ return number;
395
+ }
396
+
374
397
  inline std::size_t StringToHash(const UStringPiece& x) {
375
398
  std::size_t len = x.size();
376
399
  std::size_t step = (len >> 5) + 1;