[829] | 1 | #include "stdafx.h"
|
---|
| 2 | #include <jenga/include/jenga.h>
|
---|
| 3 | #include <abdev/ab_common/include/ab_common.h>
|
---|
| 4 |
|
---|
| 5 | using namespace ActiveBasic::Common::Lexical;
|
---|
| 6 |
|
---|
| 7 | const NamespaceSupporter *Symbol::namespaceSupporter = NULL;
|
---|
| 8 |
|
---|
| 9 | char const *calcNames[256] = {
|
---|
| 10 | 0,
|
---|
| 11 | };
|
---|
| 12 | void InitCalcNames()
|
---|
| 13 | {
|
---|
| 14 | if( calcNames[CALC_XOR] )
|
---|
| 15 | {
|
---|
| 16 | return;
|
---|
| 17 | }
|
---|
| 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 | const NamespaceScopes &symbolNS = symbol.GetNamespaceScopes();
|
---|
| 126 | if( IsEqualSymbol( symbolNS, symbol.GetName() ) )
|
---|
| 127 | {
|
---|
| 128 | return true;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | if( !symbolNS.empty() )
|
---|
| 132 | {
|
---|
| 133 | // 静的メンバを考慮
|
---|
| 134 | //name == className + '.' + memberNameならIsSameAreaNamespaceで名前空間が一致するか調べる。
|
---|
| 135 | std::string const& className = symbolNS.back();
|
---|
| 136 | std::string const& memberName = symbol.GetName();
|
---|
| 137 | std::size_t classNameSize = className.size();
|
---|
| 138 | if( name.size() != classNameSize + 1 + memberName.size() ){
|
---|
| 139 | return false;
|
---|
| 140 | }
|
---|
| 141 | if( std::equal( className.begin(), className.end(), name.begin() )
|
---|
| 142 | && name[classNameSize] == '.'
|
---|
| 143 | && std::equal( memberName.begin(), memberName.end(), name.begin() + (classNameSize + 1) ) )
|
---|
| 144 | {
|
---|
| 145 | return namespaceSupporter->IsSameAreaNamespace( GetNamespaceScopes(),
|
---|
| 146 | NamespaceScopes( symbolNS.begin(), symbolNS.end() - 1 ) );
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 | return false;
|
---|
| 150 | }
|
---|