From d1be4f4946b33f1c538b5881d20c07ef7a349102 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Mon, 9 Sep 2019 16:16:36 +0200
Subject: [PATCH] remove duplicates from stoch_simul symbol_list. closes
 dynare#1519

---
 src/ComputingTasks.cc |  2 ++
 src/ComputingTasks.hh |  2 +-
 src/SymbolList.cc     | 15 ++++++++++++++-
 src/SymbolList.hh     |  6 +++++-
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc
index 4b1e4226..6238649c 100644
--- a/src/ComputingTasks.cc
+++ b/src/ComputingTasks.cc
@@ -645,6 +645,8 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
            << endl;
       exit(EXIT_FAILURE);
     }
+
+  symbol_list.removeDuplicates("stoch_simul", warnings);
 }
 
 void
diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh
index 1568272d..4961ccc8 100644
--- a/src/ComputingTasks.hh
+++ b/src/ComputingTasks.hh
@@ -124,7 +124,7 @@ public:
 class StochSimulStatement : public Statement
 {
 private:
-  const SymbolList symbol_list;
+  SymbolList symbol_list;
   const OptionsList options_list;
 public:
   StochSimulStatement(SymbolList symbol_list_arg,
diff --git a/src/SymbolList.cc b/src/SymbolList.cc
index 1d290984..f8dab968 100644
--- a/src/SymbolList.cc
+++ b/src/SymbolList.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2003-2018 Dynare Team
+ * Copyright © 2003-2019 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -70,3 +70,16 @@ SymbolList::getSymbols() const
 {
   return symbols;
 }
+
+void
+SymbolList::removeDuplicates(const string &dynare_command, WarningConsolidation &warnings)
+{
+  vector<string> unique_symbols;
+  for (auto & it : symbols)
+    if (find(unique_symbols.begin(), unique_symbols.end(), it) == unique_symbols.end())
+      unique_symbols.push_back(it);
+    else
+      warnings << "WARNING: In " << dynare_command << ": " << it
+               << " found more than once in symbol list. Removing all but first occurence." << endl;
+  symbols = unique_symbols;
+}
diff --git a/src/SymbolList.hh b/src/SymbolList.hh
index 622f9914..afdf6080 100644
--- a/src/SymbolList.hh
+++ b/src/SymbolList.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2003-2017 Dynare Team
+ * Copyright © 2003-2019 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -24,6 +24,8 @@
 #include <vector>
 #include <ostream>
 
+#include "WarningConsolidation.hh"
+
 using namespace std;
 
 //! Used to store a list of symbols
@@ -36,6 +38,8 @@ private:
 public:
   //! Adds a symbol to the list
   void addSymbol(const string &symbol);
+  //! Removed duplicate symbols
+  void removeDuplicates(const string &dynare_command, WarningConsolidation &warnings);
   //! Output content in Matlab format
   /*! Creates a string array for Matlab, stored in variable "varname" */
   void writeOutput(const string &varname, ostream &output) const;
-- 
GitLab