Author: [EMAIL PROTECTED]
Date: Fri Nov 14 11:43:21 2008
New Revision: 761

Modified:
    branches/experimental/regexp2000/src/jsregexp.cc
    branches/experimental/regexp2000/src/jsregexp.h

Log:
Generate code for choice nodes.
Review URL: http://codereview.chromium.org/10947

Modified: branches/experimental/regexp2000/src/jsregexp.cc
==============================================================================
--- branches/experimental/regexp2000/src/jsregexp.cc    (original)
+++ branches/experimental/regexp2000/src/jsregexp.cc    Fri Nov 14 11:43:21  
2008
@@ -867,8 +867,8 @@


  bool RegExpNode::GoTo(RegExpCompiler* compiler) {
-  if (label.is_bound()) {
-    compiler->macro_assembler()->GoTo(&label);
+  if (label_.is_bound()) {
+    compiler->macro_assembler()->GoTo(&label_);
      return true;
    } else {
      return Emit(compiler);
@@ -876,8 +876,8 @@
  }


-void RegExpNode::EmitAddress(RegExpCompiler* compiler) {
-  compiler->macro_assembler()->EmitOrLink(&label);
+Label* RegExpNode::label() {
+  return &label_;
  }


@@ -959,9 +959,50 @@
  // Emit code.


+void ChoiceNode::GenerateGuard(RegExpCompiler* compiler,
+                               Guard *guard,
+                               Label* on_failure) {
+
+}
+
+
  bool ChoiceNode::Emit(RegExpCompiler* compiler) {
-  // TODO(erikcorry): Implement this.
-  return false;
+  int choice_count = alternatives_->length();
+  RegExpMacroAssembler* macro_assembler = compiler->macro_assembler();
+  // For now we just call all choices one after the other.  The idea  
ultimately
+  // is to use the Dispatch table to try only the relevant ones.
+  for (int i = 0; i < choice_count; i++) {
+    GuardedAlternative alternative = (*alternatives_)[i];
+    Label after;
+    Label* next_alternative;
+    if (i < choice_count - 1) {
+      next_alternative = &after;
+    } else {
+      next_alternative = on_failure_->label();
+    }
+    ZoneList<Guard*>* guards = alternative.guards();
+    if (guards != NULL) {
+      int guard_count = guards->length();
+      for (int j = 0; j < guard_count; j++) {
+        GenerateGuard(compiler, (*guards)[i], next_alternative);
+      }
+    }
+    macro_assembler->PushBacktrack(next_alternative);
+    if (!alternative.node()->Emit(compiler)) {
+      after.Unuse();
+      if (next_alternative != &after) {
+        next_alternative->Unuse();
+      }
+      return false;
+    }
+    if (i < choice_count - 1) {
+      macro_assembler->Bind(&after);
+    } else {
+      after.Unuse();
+    }
+  }
+  compiler->AddWork(on_failure_);
+  return true;
  }



Modified: branches/experimental/regexp2000/src/jsregexp.h
==============================================================================
--- branches/experimental/regexp2000/src/jsregexp.h     (original)
+++ branches/experimental/regexp2000/src/jsregexp.h     Fri Nov 14 11:43:21 2008
@@ -421,7 +421,7 @@
    // Until the implementation is complete we will return true for success  
and
    // false for failure.
    bool GoTo(RegExpCompiler* compiler);
-  void EmitAddress(RegExpCompiler* compiler);
+  Label* label();

    // Until the implementation is complete we will return true for success  
and
    // false for failure.
@@ -429,7 +429,7 @@
    NodeInfo* info() { return &info_; }
    virtual bool IsBacktrack() { return false; }
   private:
-  Label label;
+  Label label_;
    NodeInfo info_;
  };

@@ -610,6 +610,9 @@
    bool being_calculated() { return being_calculated_; }
    void set_being_calculated(bool b) { being_calculated_ = b; }
   private:
+  void GenerateGuard(RegExpCompiler* compiler,
+                     Guard *guard,
+                     Label* on_failure);
    RegExpNode* on_failure_;
    ZoneList<GuardedAlternative>* alternatives_;
    DispatchTable table_;

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to