Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Scope.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 //#include <stdio.h>
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 
00028 #include "Token.h"
00029 #include "Scope.h"
00030 #include "dp.h"
00031 #include "SimpleParser.h"
00032 
00033 
00034 
00035 Scope::Scope()
00036 :Sequence()
00037 {
00038 }
00039 
00040 
00041 Scope::Scope(token_v &tok)
00042 :Sequence(tok)
00043 {
00044 }
00045 
00046 
00047 Scope::~Scope()
00048 {
00049         while (m_sts.size())
00050         {
00051                 sequence_v::iterator it = m_sts.begin();
00052                 Sequence *s = *it;
00053                 delete s;
00054                 m_sts.erase(it);
00055         }
00056 }
00057 
00058 
00059 void Scope::Display()
00060 {
00061         if (IsExtern())
00062                 return;
00063         if (config["-xml"] == "true")
00064         {
00065                 if (Trail())
00066                 {
00067                         printf("<scope filename=\"%s\" line=\"%d\" value=\"%s\" trail=\"%s\">\n",
00068                                 GetFile().c_str(),
00069                                 GetLine(),
00070                                 GetExpr().c_str(),
00071                                 GetTrail().c_str());
00072                 }
00073                 else
00074                         printf("<scope filename=\"%s\" line=\"%d\" value=\"%s\">\n",
00075                                 GetFile().c_str(),
00076                                 GetLine(),
00077                                 GetExpr().c_str());
00078                 for (sequence_v::iterator it = m_sts.begin(); it != m_sts.end(); it++)
00079                 {
00080                         Sequence *s = *it;
00081                         s -> Display();
00082                 }
00083                 printf("</scope>\n");
00084                 return;
00085         }
00086         if (config["-dot"] == "true")
00087                 return;
00088         if (GetParent()) // root Scope has parent NULL
00089         {
00090                 Tab();
00091                 printf("%s\n",GetExpr().c_str());
00092                 Tab();
00093                 printf("{\n");
00094         }
00095         for (sequence_v::iterator it = m_sts.begin(); it != m_sts.end(); it++)
00096         {
00097                 Sequence *s = *it;
00098                 s -> Display();
00099         }
00100         if (GetParent())
00101         {
00102                 Tab();
00103                 printf("}");
00104                 if (Trail())
00105                 {
00106                         printf(" %s",GetTrail().c_str());
00107 /*
00108                         for (token_v::iterator it = m_trail.begin(); it != m_trail.end(); it++)
00109                         {
00110                                 Token *t = *it;
00111                                 printf(" %s",t -> GetVal().c_str());
00112                         }
00113 //                      printf(";");
00114 */
00115                 }
00116                 printf(" // %s\n",GetExpr().c_str());
00117         }
00118 }
00119 
00120 
00121 bool Scope::Trail()
00122 {
00123         Token *t = GetFirstToken();
00124         if (!t)
00125                 return false;
00126         switch (t -> GetCode())
00127         {
00128         case Typedef:
00129         case Class:
00130         case Struct:
00131         case Enum:
00132                 return true;
00133         default:
00134                 break;
00135         }
00136         return false;
00137 }
00138 
00139 
00140 void Scope::AddTrail(token_v &tok)
00141 {
00142         m_trail = tok;
00143 }
00144 
00145 
00146 std::string Scope::GetTrail()
00147 {
00148         std::string tmp;
00149         for (token_v::iterator it = m_trail.begin(); it != m_trail.end(); it++)
00150         {
00151                 Token *t = *it;
00152                 std::string str = t -> GetVal();
00153 //              if (tmp.size() && (isalpha(str[0]) || str[0] == '<') )
00154 //                      tmp += " ";
00155                 tmp += str;
00156         }
00157         if (config["-xml"] == "true")
00158                 xmlsafestr(tmp);
00159         return tmp;
00160 }
00161 
00162 

Generated for My SDL C++ Gui by doxygen 1.3.6