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