ListOfMatchExpression.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "use strict";
  2. var MatchExpression = require('./MatchExpression');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var ListOfMatchExpression = module.exports = function ListOfMatchExpression(matchType){
  5. base.call(this);
  6. this._expressions = [];
  7. this._matchType = matchType;
  8. }, klass = ListOfMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  9. // File: expression_tree.h lines: 56-56
  10. proto._expressions = undefined;
  11. /**
  12. *
  13. * Print the debug info from each expression in the list
  14. * @method _debugList
  15. * @param level
  16. *
  17. */
  18. proto._debugList = function _debugList(level){
  19. // File: expression_tree.cpp lines: 40-42
  20. for (var i = 0; i < this._expressions.length; i++ )
  21. this._expressions[i].debugString(level + 1); // debug only takes level now
  22. };
  23. /**
  24. *
  25. * Append a new expression to our list
  26. * @method add
  27. * @param Expression
  28. *
  29. */
  30. proto.add = function add( exp ){
  31. // File: expression_tree.cpp lines: 34-36
  32. // verify(expression)
  33. if(!exp)
  34. throw new Error(exp + " failed verify on ListOfMatchExpression:34");
  35. if(this._expressions) {
  36. this._expressions.push(exp);
  37. } else {
  38. this._expressions = [exp];
  39. }
  40. };
  41. /**
  42. *
  43. * Empty us out
  44. * @method clearAndRelease
  45. *
  46. */
  47. proto.clearAndRelease = function clearAndRelease(){
  48. // File: expression_tree.h lines: 45-44
  49. this._expressions = []; // empty the expressions
  50. };
  51. /**
  52. *
  53. * Check if the input list is considered the same as this one
  54. * @method equivalent
  55. * @param other
  56. *
  57. */
  58. proto.equivalent = function equivalent(other){
  59. // File: expression_tree.cpp lines: 45-59
  60. if (this._matchType != other._matchType)
  61. return false;
  62. var realOther = new ListOfMatchExpression(other);
  63. if (this._expressions.length != realOther._expressions.length)
  64. return false;
  65. // TODO: order doesn't matter
  66. for (var i = 0; i < this._expressions.length; i++ )
  67. if (!this._expressions[i].equivalent(realOther._expressions[i]))
  68. return false;
  69. return true;
  70. };
  71. /**
  72. *
  73. * Get an item from the expressions
  74. * @method getChild
  75. * @param
  76. *
  77. */
  78. proto.getChild = function getChild(i){
  79. // File: expression_tree.h lines: 48-47
  80. return this._expressions[i];
  81. };
  82. /**
  83. *
  84. * Get the length of the list
  85. * @method numChildren
  86. * @param
  87. *
  88. */
  89. proto.numChildren = function numChildren(){
  90. // File: expression_tree.h lines: 47-46
  91. return this._expressions.length;
  92. };