00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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())
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
00109
00110
00111
00112
00113
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
00154
00155 tmp += str;
00156 }
00157 if (config["-xml"] == "true")
00158 xmlsafestr(tmp);
00159 return tmp;
00160 }
00161
00162