[101] | 1 | #include "../common.h"
|
---|
| 2 |
|
---|
| 3 |
|
---|
[105] | 4 | NamespaceScopes::NamespaceScopes( const string &namespaceStr ){
|
---|
[101] | 5 | int i = 0;
|
---|
[105] | 6 | while( i < (int)namespaceStr.size() ){
|
---|
[101] | 7 | char temporary[VN_SIZE];
|
---|
| 8 | for( int i2=0; ; i2++, i++ ){
|
---|
| 9 | if( namespaceStr[i] == '.' || namespaceStr[i] == '\0' ){
|
---|
| 10 | temporary[i2] = 0;
|
---|
| 11 | break;
|
---|
| 12 | }
|
---|
| 13 | temporary[i2] = namespaceStr[i];
|
---|
| 14 | }
|
---|
| 15 | push_back( temporary );
|
---|
| 16 |
|
---|
| 17 | if( namespaceStr[i] == '.' ){
|
---|
| 18 | i++;
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
[107] | 23 | bool NamespaceScopes::IsImported() const
|
---|
| 24 | {
|
---|
| 25 | BOOST_FOREACH( const NamespaceScopes &namespaceScopes, Smoothie::Meta::importedNamespaces ){
|
---|
| 26 | if( this->IsEqual( namespaceScopes ) ){
|
---|
| 27 | return true;
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | return false;
|
---|
| 31 | }
|
---|
[101] | 32 | bool NamespaceScopes::IsLiving() const
|
---|
| 33 | {
|
---|
| 34 | if( IsBelong( *this, Smoothie::Lexical::liveingNamespaceScopes ) ){
|
---|
| 35 | return true;
|
---|
| 36 | }
|
---|
| 37 | return false;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | // 包括しているかをチェック
|
---|
| 41 | // 例:
|
---|
| 42 | // this = "Discoversoft.ActiveBasic"
|
---|
| 43 | // living = "Discoversoft.ActiveBasic"
|
---|
| 44 | // name = "ActiveBasic"
|
---|
| 45 | // この場合、living は name を包括している。
|
---|
| 46 | bool NamespaceScopes::IsCoverd( const string &name ) const
|
---|
| 47 | {
|
---|
| 48 | if( IsEqual( name ) ){
|
---|
| 49 | return true;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | string thisStr = ToString();
|
---|
| 53 |
|
---|
| 54 | NamespaceScopes tempLivingNamespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
|
---|
| 55 |
|
---|
| 56 | while( tempLivingNamespaceScopes.size() ){
|
---|
| 57 | NamespaceScopes tempNamespaceScopes = tempLivingNamespaceScopes;
|
---|
| 58 |
|
---|
| 59 | string tempStr = tempNamespaceScopes.ToString() + "." + name;
|
---|
| 60 | if( thisStr == tempStr ){
|
---|
| 61 | return true;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | tempLivingNamespaceScopes.pop_back();
|
---|
| 65 | }
|
---|
| 66 | return false;
|
---|
| 67 | }
|
---|
| 68 | bool NamespaceScopes::IsCoverd( const NamespaceScopes &namespaceScopes ) const
|
---|
| 69 | {
|
---|
| 70 | return IsCoverd( namespaceScopes.ToString() );
|
---|
| 71 | }
|
---|
[105] | 72 |
|
---|
| 73 |
|
---|
| 74 | void NamespaceScopesCollection::SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const
|
---|
| 75 | {
|
---|
| 76 | NamespaceScopes namespaceScopes( fullName );
|
---|
| 77 | bool hasSimpleName = false;
|
---|
| 78 | while( namespaceScopes.size() > 0 ){
|
---|
| 79 | if( IsExist( namespaceScopes ) ){
|
---|
| 80 | break;
|
---|
| 81 | }
|
---|
| 82 | namespaceScopes.pop_back();
|
---|
| 83 |
|
---|
| 84 | hasSimpleName = true;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | lstrcpy( namespaceStr, namespaceScopes.ToString().c_str() );
|
---|
| 88 |
|
---|
| 89 | bool hasNamespace = false;
|
---|
| 90 | if( namespaceStr[0] ){
|
---|
| 91 | hasNamespace = true;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | int dotLength = 0;
|
---|
| 95 | if( hasSimpleName && hasNamespace ){
|
---|
| 96 | dotLength = 1;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | lstrcpy( simpleName, fullName + lstrlen( namespaceStr ) + dotLength );
|
---|
| 100 | }
|
---|
[107] | 101 | void NamespaceScopesCollection::Imports( const string &namespaceStr ){
|
---|
| 102 | NamespaceScopes namespaceScopes( namespaceStr );
|
---|
| 103 | if( !Smoothie::Meta::namespaceScopesCollection.IsExist( namespaceScopes ) ){
|
---|
| 104 | SetError(64,namespaceStr.c_str(),cp );
|
---|
| 105 | return;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | this->push_back( namespaceScopes );
|
---|
| 109 | }
|
---|
[105] | 110 | bool NamespaceScopesCollection::CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection )
|
---|
| 111 | {
|
---|
| 112 | int i, i2;
|
---|
| 113 | char temporary[VN_SIZE];
|
---|
| 114 |
|
---|
| 115 | bool isSuccessful = true;
|
---|
| 116 |
|
---|
| 117 | // 名前空間管理
|
---|
| 118 | NamespaceScopes namespaceScopes;
|
---|
| 119 |
|
---|
| 120 | for(i=0;;i++){
|
---|
| 121 | if(source[i]=='\0') break;
|
---|
| 122 |
|
---|
| 123 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
| 124 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 125 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 126 | temporary[i2]=0;
|
---|
| 127 | break;
|
---|
| 128 | }
|
---|
| 129 | temporary[i2]=source[i];
|
---|
| 130 | }
|
---|
| 131 | namespaceScopes.push_back( temporary );
|
---|
| 132 |
|
---|
| 133 | if( !namespaceScopesCollection.IsExist( namespaceScopes ) ){
|
---|
| 134 | namespaceScopesCollection.push_back( namespaceScopes );
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | continue;
|
---|
| 138 | }
|
---|
| 139 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 140 | if( namespaceScopes.size() <= 0 ){
|
---|
| 141 | SetError(12, "End Namespace", i );
|
---|
| 142 | isSuccessful = false;
|
---|
| 143 | }
|
---|
| 144 | else{
|
---|
| 145 | namespaceScopes.pop_back();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | i += 2;
|
---|
| 149 | continue;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | if( namespaceScopes.size() > 0 ){
|
---|
| 154 | SetError(63,NULL,-1);
|
---|
| 155 | isSuccessful = false;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | return isSuccessful;
|
---|
| 159 | }
|
---|