<commit_before>// $Id: swalker.cc,v 1.30 2001/06/05 05:03:53 chalky Exp $
//
// This file is a part of Synopsis.
// Copyright (C) 2000, 2001 <NAME>
// Copyright (C) 2000, 2001 <NAME>
//
// Synopsis 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// $Log: swalker.cc,v $
// Revision 1.30  2001/06/05 05:03:53  chalky
// Added support for qualified typedefs in storeLink
//
// Revision 1.29  2001/06/05 03:49:33  chalky
// Made my own wrong_type_cast exception. Added template support to qualified
// names (its bad but it doesnt crash). Added vector<string> output op to builder
//
// Revision 1.28  2001/05/25 03:08:49  chalky
// Fixes to compile with 3.0
//
// Revision 1.27  2001/05/23 05:08:47  stefan
// more std C++ issues. It still crashes...
//
// Revision 1.26  2001/05/06 20:15:03  stefan
// fixes to get std compliant; replaced some pass-by-value by pass-by-const-ref; bug fixes;
//
// Revision 1.25  2001/04/17 15:47:26  chalky
// Added declaration name mapper, and changed refmanual to use it instead of the
// old language mapping
//
// Revision 1.24  2001/04/03 23:01:38  chalky
// Small fixes and extra comments
//
// Revision 1.23  2001/03/19 07:53:45  chalky
// Small fixes.
//
// Revision 1.22  2001/03/16 04:42:00  chalky
// SXR parses expressions, handles differences from macro expansions. Some work
// on function call resolution.
//
// Revision 1.21  2001/02/16 06:59:32  chalky
// ScopePage summaries link to source
//
// Revision 1.20  2001/02/16 06:33:35  chalky
// parameterized types, return types, variable types, modifiers, etc.
//
// Revision 1.19  2001/02/16 04:57:50  chalky
// SXR: func parameters, namespaces, comments. Unlink temp file. a class=ref/def
//
// Revision 1.18  2001/02/16 02:29:55  chalky
// Initial work on SXR and HTML integration
//
// Revision 1.17  2001/02/13 05:20:04  chalky
// Made C++ parser mangle functions by formatting their parameter types
//
// Revision 1.16  2001/02/07 14:27:39  chalky
// Enums inside declarations swallow declaration comments.
//
//

// File: swalker.cc
//
// SWalker class

#include <iostream.h>
#include <string>
#include <typeinfo>

#include "ptree.h"
#include "parse.h"

#include "swalker.hh"
#include "strace.hh"
#include "type.hh"
#include "ast.hh"
#include "builder.hh"
#include "decoder.hh"
#include "dumper.hh"
#include "link_map.hh"

using namespace AST;

// ------------------------------------------------------------------
//                 -- CLASS STrace --
// ------------------------------------------------------------------

#ifdef DO_TRACE
// Class variable definitions
int STrace::slevel = 0, STrace::dlevel = 0;
std::ostrstream* STrace::stream = 0;
STrace::list STrace::m_list;
#endif

// ------------------------------------------------------------------
//                 -- CLASS SWalker --
// ------------------------------------------------------------------


// ------------------------------------
// SWalker Constructor
SWalker::SWalker(const std::string &source, Parser* parser, Builder* builder, Program* program)
    : Walker(parser),
      m_parser(parser),
      m_program(program),
      m_builder(builder),
      m_decoder(new Decoder(m_builder)),
      m_declaration(0),
      m_filename_ptr(0),
      m_lineno(0),
      m_source(source),
      m_extract_tails(false),
      m_store_links(false),
      m_storage(0),
      m_store_decl(false),
      m_type_formatter(new TypeFormatter()),
      m_operation(0),
      m_type(0),
      m_scope(0),
      m_postfix_flag(Postfix_Var)
{
}

// The name returned is just the node's text if the node is a leaf. Otherwise,
// the ToString method of Ptree is used, which is rather expensive since it
// creates a temporary write buffer and reifies the node tree into it.
std::string SWalker::getName(Ptree *node) const
{
    // STrace trace("SWalker::getName");
    if (node && node->IsLeaf())
        return std::string(node->GetPosition(), node->GetLength());
    return node->ToString();
}

// Returns the column number of 'find', by counting backwards until a newline
// is encountered, or 'start' (the start of the buffer). The returned column
// number is mapped by the link_map.<commit_msg>Added global g_swalker var<commit_after>// $Id: swalker.cc,v 1.31 2001/06/05 05:47:02 chalky Exp $
//
// This file is a part of Synopsis.
// Copyright (C) 2000, 2001 <NAME>
// Copyright (C) 2000, 2001 <NAME>
//
// Synopsis 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// $Log: swalker.cc,v $
// Revision 1.31  2001/06/05 05:47:02  chalky
// Added global g_swalker var
//
// Revision 1.30  2001/06/05 05:03:53  chalky
// Added support for qualified typedefs in storeLink
//
// Revision 1.29  2001/06/05 03:49:33  chalky
// Made my own wrong_type_cast exception. Added template support to qualified
// names (its bad but it doesnt crash). Added vector<string> output op to builder
//
// Revision 1.28  2001/05/25 03:08:49  chalky
// Fixes to compile with 3.0
//
// Revision 1.27  2001/05/23 05:08:47  stefan
// more std C++ issues. It still crashes...
//
// Revision 1.26  2001/05/06 20:15:03  stefan
// fixes to get std compliant; replaced some pass-by-value by pass-by-const-ref; bug fixes;
//
// Revision 1.25  2001/04/17 15:47:26  chalky
// Added declaration name mapper, and changed refmanual to use it instead of the
// old language mapping
//
// Revision 1.24  2001/04/03 23:01:38  chalky
// Small fixes and extra comments
//
// Revision 1.23  2001/03/19 07:53:45  chalky
// Small fixes.
//
// Revision 1.22  2001/03/16 04:42:00  chalky
// SXR parses expressions, handles differences from macro expansions. Some work
// on function call resolution.
//
// Revision 1.21  2001/02/16 06:59:32  chalky
// ScopePage summaries link to source
//
// Revision 1.20  2001/02/16 06:33:35  chalky
// parameterized types, return types, variable types, modifiers, etc.
//
// Revision 1.19  2001/02/16 04:57:50  chalky
// SXR: func parameters, namespaces, comments. Unlink temp file. a class=ref/def
//
// Revision 1.18  2001/02/16 02:29:55  chalky
// Initial work on SXR and HTML integration
//
// Revision 1.17  2001/02/13 05:20:04  chalky
// Made C++ parser mangle functions by formatting their parameter types
//
// Revision 1.16  2001/02/07 14:27:39  chalky
// Enums inside declarations swallow declaration comments.
//
//

// File: swalker.cc
//
// SWalker class

#include <iostream.h>
#include <string>
#include <typeinfo>

#include "ptree.h"
#include "parse.h"

#include "swalker.hh"
#include "strace.hh"
#include "type.hh"
#include "ast.hh"
#include "builder.hh"
#include "decoder.hh"
#include "dumper.hh"
#include "link_map.hh"

using namespace AST;

// ------------------------------------------------------------------
//                 -- CLASS STrace --
// ------------------------------------------------------------------

#ifdef DO_TRACE
// Class variable definitions
int STrace::slevel = 0, STrace::dlevel = 0;
std::ostrstream* STrace::stream = 0;
STrace::list STrace::m_list;
#endif

// ------------------------------------------------------------------
//                 -- CLASS SWalker --
// ------------------------------------------------------------------

// Global SWalker object - this is never used, but is intended for your use
// when debugging in case the stack is smashed and you have to way to get at
// any useful objects
SWalker* g_swalker;

// ------------------------------------
// SWalker Constructor
SWalker::SWalker(const std::string &source, Parser* parser, Builder* builder, Program* program)
    : Walker(parser),
      m_parser(parser),
      m_program(program),
      m_builder(builder),
      m_decoder(new Decoder(m_builder)),
      m_declaration(0),
      m_filename_ptr(0),
      m_lineno(0),
      m_source(source),
      m_extract_tails(false),
      m_store_links(false),
      m_storage(0),
      m_store_decl(false),
      m_type_formatter(new TypeFormatter()),
      m_operation(0),
      m_type(0),
      m_scope(0),
      m_postfix_flag(Postfix_Var)
{
    g_swalker = this;
}

// The name returned is just the node's text if the node is a leaf. Otherwise,
// the ToString method of Ptree is used, which is rather expensive since it
// creates a temporary write buffer and reifies the node tree into it.
std::string SWalker::getName(Ptree *node) const
{
    // STrace trace("SWalker::getName");
    if (node && node->IsLeaf())
        return std::string(node->GetPosition(), node->GetLength());
    return node->ToString();
}

// Returns the column number of 'find', by counting backwards until a newline
// is encountered, or 'start' (the start of the buffer). The returned column
// number is mapped by the link_map.
{'fraction_non_alphanumeric': 0.17546505781799898, 'fraction_numerical': 0.06505781799899447, 'mean_word_length': 2.4166952937135004, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2745378', 'n_tokens_mistral': 3528, 'n_tokens_neox': 3044, 'n_words': 1085}