source: dev/trunk/ab5.0/abdev/ab_common/src/Lexical/Symbol.cpp@ 779

Last change on this file since 779 was 752, checked in by イグトランス (egtra), 16 years ago

IsEqualSymbolをさらに高速化

File size: 3.6 KB
Line 
1#include "stdafx.h"
2
3using namespace ActiveBasic::Common::Lexical;
4
5const NamespaceSupporter *Symbol::namespaceSupporter = NULL;
6
7char const *calcNames[256] = {
8 0,
9};
10void InitCalcNames()
11{
12 if( calcNames[CALC_XOR] )
13 {
14 return;
15 }
16 calcNames[CALC_XOR] = "xor";
17 calcNames[CALC_OR] = "or";
18 calcNames[CALC_AND] = "and";
19 calcNames[CALC_NOT] = "Not";
20 calcNames[CALC_PE] = "<=";
21 calcNames[CALC_QE] = ">=";
22 calcNames[CALC_NOTEQUAL] = "<>";
23 calcNames[CALC_EQUAL] = "=(compare)";
24 calcNames[CALC_P] = "<";
25 calcNames[CALC_Q] = ">";
26 calcNames[CALC_SHL] = "<<";
27 calcNames[CALC_SHR] = ">>";
28 calcNames[CALC_ADDITION] = "+";
29 calcNames[CALC_SUBTRACTION] = "-";
30 calcNames[CALC_STRPLUS] = "&";
31 calcNames[CALC_MOD] = "mod";
32 calcNames[CALC_PRODUCT] = "*";
33 calcNames[CALC_QUOTIENT] = "/";
34 calcNames[CALC_INTQUOTIENT] = "\\";
35 calcNames[CALC_AS] = "As";
36 calcNames[CALC_BYVAL] = "ByVal";
37 calcNames[CALC_MINUSMARK] = "-(mark)";
38 calcNames[CALC_POWER] = "^";
39 calcNames[CALC_SUBSITUATION] = "=";
40 calcNames[CALC_ARRAY_GET] = "[]";
41 calcNames[CALC_ARRAY_SET] = "[]=";
42}
43void GetCalcName(int idCalc,char *name){
44 InitCalcNames();
45
46 if( calcNames[idCalc] == NULL )
47 {
48 throw;
49 }
50
51 lstrcpy( name, calcNames[idCalc] );
52}
53
54std::string ActiveBasic::Common::Lexical::Operator_CalcMarkStringToNaturalString( const std::string &name )
55{
56 if( name[0] == 1 && name[1] == ESC_OPERATOR )
57 {
58 BYTE calcId = name[2];
59 char temporary[255], calcName[255];
60 GetCalcName( calcId, calcName );
61 temporary[0] = name[0];
62 temporary[1] = name[1];
63 lstrcpy( temporary+2, calcName );
64 return temporary;
65 }
66 return name;
67}
68
69BYTE ToCalcId( const char *name )
70{
71 InitCalcNames();
72
73 for( int i=0; i<255; i++ )
74 {
75 if( calcNames[i] )
76 {
77 if( lstrcmp( name, calcNames[i] ) == 0 )
78 {
79 return i;
80 }
81 }
82 }
83
84 throw;
85}
86
87std::string ActiveBasic::Common::Lexical::Operator_NaturalStringToCalcMarkString( const std::string &name )
88{
89 if( name[0] == 1 && name[1] == ESC_OPERATOR )
90 {
91 BYTE calcId = ToCalcId( name.c_str()+2 );
92 char temporary[255];
93 temporary[0] = name[0];
94 temporary[1] = name[1];
95 temporary[2] = calcId;
96 temporary[3] = 0;
97 return temporary;
98 }
99 return name;
100}
101
102std::string Symbol::GetFullName() const
103{
104 if( namespaceScopes.size() )
105 {
106 return namespaceScopes.ToString() + '.' + name;
107 }
108
109 return name;
110}
111
112bool Symbol::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const std::string &name ) const
113{
114 if( GetName() != name ){
115 return false;
116 }
117
118 _ASSERTE( namespaceSupporter );
119 return namespaceSupporter->IsSameAreaNamespace( GetNamespaceScopes(), namespaceScopes );
120}
121bool Symbol::IsEqualSymbol( const Symbol &symbol ) const
122{
123 const NamespaceScopes &symbolNS = symbol.GetNamespaceScopes();
124 if( IsEqualSymbol( symbolNS, symbol.GetName() ) )
125 {
126 return true;
127 }
128
129 if( !symbolNS.empty() )
130 {
131 // 静的メンバを考慮
132 //name == className + '.' + memberNameならIsSameAreaNamespaceで名前空間が一致するか調べる。
133 std::string const& className = symbolNS.back();
134 std::string const& memberName = symbol.GetName();
135 std::size_t classNameSize = className.size();
136 if( name.size() != classNameSize + 1 + memberName.size() ){
137 return false;
138 }
139 if( std::equal( className.begin(), className.end(), name.begin() )
140 && name[classNameSize] == '.'
141 && std::equal( memberName.begin(), memberName.end(), name.begin() + (classNameSize + 1) ) )
142 {
143 return namespaceSupporter->IsSameAreaNamespace( GetNamespaceScopes(),
144 NamespaceScopes( symbolNS.begin(), symbolNS.end() - 1 ) );
145 }
146 }
147 return false;
148}
Note: See TracBrowser for help on using the repository browser.