Quellcode durchsuchen

Refs #3304. Ported ListOfMatchExpression, but there may be an issue with the constructor.

Spencer Rathbun vor 12 Jahren
Ursprung
Commit
049d21b8c6
2 geänderte Dateien mit 55 neuen und 141 gelöschten Zeilen
  1. 1 0
      lib/pipeline/matcher/CLUDGES
  2. 54 141
      lib/pipeline/matcher/ListOfMatchExpression.js

+ 1 - 0
lib/pipeline/matcher/CLUDGES

@@ -10,5 +10,6 @@ Status objects are now generic objects having a 'code' property that is a string
 debugString takes one argument 'level', as does debugAddSpace. Debug statements are printed to console.debug()
 
 
+verify is a macro function that throws an exception if the input is falsey, with the current file and lineno, so there is no need for the function itself
 
 

+ 54 - 141
lib/pipeline/matcher/ListOfMatchExpression.js

@@ -1,184 +1,97 @@
-"use strict"
-
-
+"use strict";
 
 // Autogenerated by cport.py on 2013-09-17 14:37
-var ListOfMatchExpression = module.exports = function (){
-
+var ListOfMatchExpression = module.exports = function (/*type*/){
+	this._expressions = [];
 }, klass = ListOfMatchExpression, base =  Object  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
-
 // File: expression_tree.h lines: 56-56
-//         std::vector< MatchExpression* > _expressions;
-
 proto._expressions = undefined;
 
-
-// File: expression_tree.h lines: 56-56
-//         std::vector< MatchExpression* > _expressions;
-
-proto._expressions = undefined;
-
-
-
-
-
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
- * @method ListOfMatchExpression
- * @param
  *
- */
-proto.ListOfMatchExpression = function ListOfMatchExpression( /*  MatchType type  */ ){
-// File: expression_tree.h lines: 33-32
-//         ListOfMatchExpression( MatchType type ) : MatchExpression( type ){}
-
-
-
-
-}
-
-
-/**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
+ * Print the debug info from each expression in the list
  * @method _debugList
- * @param
+ * @param level
  *
  */
-proto._debugList = function _debugList( /*  StringBuilder& debug, int level  */ ){
-
-// File: expression_tree.cpp lines: 40-42
-//     void ListOfMatchExpression::_debugList( StringBuilder& debug, int level ) const {
-//         for ( unsigned i = 0; i < _expressions.size(); i++ )
-//             _expressions[i]->debugString( debug, level + 1 );
-//     }
-
-
-
-}
-
+proto._debugList = function _debugList(level){
+	// File: expression_tree.cpp lines: 40-42
+	for (var i = 0; i < this._expressions.length; i++ )
+		this._expressions[i].debugString(level + 1); // debug only takes level now
+};
 
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
+ *
+ * Append a new expression to our list
  * @method add
- * @param
+ * @param Expression
  *
  */
-proto.add = function add( /*  MatchExpression* e  */ ){
-
-// File: expression_tree.cpp lines: 34-36
-//     void ListOfMatchExpression::add( MatchExpression* e ) {
-//         verify( e );
-//         _expressions.push_back( e );
-//     }
-
-
-
-}
-
+proto.add = function add(Expression){
+	// File: expression_tree.cpp lines: 34-36
+	// verify(expression)
+	if(!Expression)
+		throw new Error(Expression + " failed verify on ListOfMatchExpression:34");
+	this._expressions.push(Expression);
+};
 
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
+ *
+ * Empty us out
  * @method clearAndRelease
- * @param
  *
  */
-proto.clearAndRelease = function clearAndRelease( /*  */ ){
-// File: expression_tree.h lines: 45-44
-//         void clearAndRelease() { _expressions.clear(); }
-
-
-
-
-}
-
+proto.clearAndRelease = function clearAndRelease(){
+	// File: expression_tree.h lines: 45-44
+	this._expressions = []; // empty the expressions
+};
 
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
+ *
+ * Check if the input list is considered the same as this one
  * @method equivalent
- * @param
+ * @param other
  *
  */
-proto.equivalent = function equivalent( /*  const MatchExpression* other  */ ){
+proto.equivalent = function equivalent(other){
+	// File: expression_tree.cpp lines: 45-59
+	if (matchType() != other.matchType())
+		return false;
 
-// File: expression_tree.cpp lines: 45-59
-//     bool ListOfMatchExpression::equivalent( const MatchExpression* other ) const {
-//         if ( matchType() != other->matchType() )
-//             return false;
-// 
-//         const ListOfMatchExpression* realOther = static_cast<const ListOfMatchExpression*>( other );
-// 
-//         if ( _expressions.size() != realOther->_expressions.size() )
-//             return false;
-// 
-//         // TOOD: order doesn't matter
-//         for ( unsigned i = 0; i < _expressions.size(); i++ )
-//             if ( !_expressions[i]->equivalent( realOther->_expressions[i] ) )
-//                 return false;
-// 
-//         return true;
-//     }
+	var realOther = new ListOfMatchExpression(other);
 
+	if (this._expressions.length != realOther._expressions.length)
+		return false;
 
+	// TODO: order doesn't matter
+	for (var i = 0; i < this._expressions.length; i++ )
+		if (!this._expressions[i].equivalent(realOther._expressions[i]))
+			return false;
 
-}
-
+	return true;
+};
 
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
+ *
+ * Get an item from the expressions
  * @method getChild
  * @param
  *
  */
-proto.getChild = function getChild( /*  size_t i  */ ){
-// File: expression_tree.h lines: 48-47
-//         virtual const MatchExpression* getChild( size_t i ) const { return _expressions[i]; }
-
-
-
-
-}
-
+proto.getChild = function getChild(i){
+	// File: expression_tree.h lines: 48-47
+	return this._expressions[i];
+};
 
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
- * @method numChildren
- * @param
  *
- */
-proto.numChildren = function numChildren( /*  */ ){
-// File: expression_tree.h lines: 47-46
-//         virtual size_t numChildren() const { return _expressions.size(); }
-
-
-
-
-}
-
-
-/**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
- * @method ~ListOfMatchExpression
+ * Get the length of the list
+ * @method numChildren
  * @param
  *
  */
-proto.~ListOfMatchExpression = function ~ListOfMatchExpression( /*  */ ){
-
-// File: expression_tree.cpp lines: 28-31
-//     ListOfMatchExpression::~ListOfMatchExpression() {
-//         for ( unsigned i = 0; i < _expressions.size(); i++ )
-//             delete _expressions[i];
-//         _expressions.clear();
-//     }
-
-
-
-}
+proto.numChildren = function numChildren(){
+	// File: expression_tree.h lines: 47-46
+	return this._expressions.length;
+};