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