Skip to content
Snippets Groups Projects
Select Git revision
  • bf99443ecfb19144b60d44e1ecd1e99a9b901e06
  • master default protected
  • julia protected
  • 6.x protected
  • python-codegen
  • llvm-15
  • 5.x protected
  • 4.6 protected
  • uop
  • rework_pac
  • aux_vars_fix
  • julia-7.0.0
  • julia-6.4.0
  • julia-6.3.0
  • julia-6.2.0
15 results

SymbolTable.cc

Blame
  • SymbolTable.cc 6.04 KiB
    /*
     * Copyright (C) 2003-2009 Dynare Team
     *
     * This file is part of Dynare.
     *
     * Dynare is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * Dynare is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
     */
    
    #include <algorithm>
    #include <sstream>
    
    #include "SymbolTable.hh"
    
    SymbolTable::SymbolTable() : frozen(false), size(0)
    {
    }
    
    void
    SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name) throw (AlreadyDeclaredException, FrozenException)
    {
      if (frozen)
        throw FrozenException();
    
      if (exists(name))
        {
          if (type_table[getID(name)] == type)
            throw AlreadyDeclaredException(name, true);
          else
            throw AlreadyDeclaredException(name, false);
        }
    
      int id = size++;
    
      symbol_table[name] = id;
      type_table.push_back(type);
      name_table.push_back(name);
      tex_name_table.push_back(tex_name);
    }
    
    void
    SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException)
    {
      // Construct "tex_name" by prepending an antislash to all underscores in "name"
      string tex_name = name;
      size_t pos = 0;
      while((pos = tex_name.find('_', pos)) != string::npos)
        {
          tex_name.insert(pos, "\\");
          pos += 2;
        }
      addSymbol(name, type, tex_name);
    }
    
    void
    SymbolTable::freeze() throw (FrozenException)
    {
      if (frozen)
        throw FrozenException();