[195] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | #include <Compiler.h>
|
---|
| 4 |
|
---|
| 5 | class NamespaceSupporter
|
---|
| 6 | {
|
---|
| 7 | // Importsされた名前空間
|
---|
| 8 | NamespaceScopesCollection importedNamespaces;
|
---|
| 9 |
|
---|
| 10 | // 現在の名前空間
|
---|
| 11 | NamespaceScopes livingNamespaceScopes;
|
---|
| 12 |
|
---|
| 13 | public:
|
---|
| 14 | NamespaceScopesCollection &GetImportedNamespaces()
|
---|
| 15 | {
|
---|
| 16 | return importedNamespaces;
|
---|
| 17 | }
|
---|
| 18 | void SetImportedNamespaces( const NamespaceScopesCollection &namespaces )
|
---|
| 19 | {
|
---|
| 20 | this->importedNamespaces = namespaces;
|
---|
| 21 | }
|
---|
| 22 | bool ImportsNamespace( const std::string &namespaceStr )
|
---|
| 23 | {
|
---|
| 24 | NamespaceScopes namespaceScopes( namespaceStr );
|
---|
| 25 | if( !compiler.GetMeta().GetNamespaces().IsExist( namespaceScopes ) ){
|
---|
| 26 | return false;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | this->importedNamespaces.push_back( namespaceScopes );
|
---|
| 30 |
|
---|
| 31 | return true;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | NamespaceScopes &GetLivingNamespaceScopes()
|
---|
| 35 | {
|
---|
| 36 | return livingNamespaceScopes;
|
---|
| 37 | }
|
---|
| 38 | bool IsLiving( const NamespaceScopes &namespaceScopes ) const
|
---|
| 39 | {
|
---|
| 40 | return NamespaceScopes::IsBelong( namespaceScopes, livingNamespaceScopes );
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | // 包括しているかをチェック
|
---|
| 45 | // 例:
|
---|
| 46 | // this = "Discoversoft.ActiveBasic"
|
---|
| 47 | // living = "Discoversoft.ActiveBasic"
|
---|
| 48 | // entryName = "ActiveBasic"
|
---|
| 49 | // この場合、living は entryName を包括している。
|
---|
| 50 | bool IsCoverd( const NamespaceScopes &namespaceScopes, const string &entryName ) const
|
---|
| 51 | {
|
---|
| 52 | if( namespaceScopes.IsEqual( entryName ) ){
|
---|
| 53 | return true;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | string thisStr = namespaceScopes.ToString();
|
---|
| 57 |
|
---|
| 58 | NamespaceScopes tempLivingNamespaceScopes = livingNamespaceScopes;
|
---|
| 59 |
|
---|
| 60 | while( tempLivingNamespaceScopes.size() ){
|
---|
| 61 | NamespaceScopes tempNamespaceScopes = tempLivingNamespaceScopes;
|
---|
| 62 |
|
---|
| 63 | string tempStr = tempNamespaceScopes.ToString() + "." + entryName;
|
---|
| 64 | if( thisStr == tempStr ){
|
---|
| 65 | return true;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | tempLivingNamespaceScopes.pop_back();
|
---|
| 69 | }
|
---|
| 70 | return false;
|
---|
| 71 | }
|
---|
| 72 | bool IsCoverd( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ) const
|
---|
| 73 | {
|
---|
| 74 | return IsCoverd( baseNamespaceScopes, entryNamespaceScopes.ToString() );
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | // 指定された名前空間が同一エリアと見なされるかどうかをチェック
|
---|
| 79 | bool IsSameAreaNamespace( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ){
|
---|
| 80 | if( entryNamespaceScopes.size() ){
|
---|
| 81 | if( IsCoverd( baseNamespaceScopes, entryNamespaceScopes ) ){
|
---|
| 82 | // 包括しているときは同一と見なす
|
---|
| 83 | return true;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | else{
|
---|
| 87 | if( baseNamespaceScopes.size() ){
|
---|
| 88 | // 名前空間の判断が必要なとき
|
---|
| 89 | if( this->importedNamespaces.IsImported( baseNamespaceScopes )
|
---|
| 90 | || IsLiving( baseNamespaceScopes ) ){
|
---|
| 91 | // Using指定があるとき
|
---|
| 92 | // または
|
---|
| 93 | // 指定された名前空間が現在の名前空間スコープと同一のとき
|
---|
| 94 | return true;
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | else{
|
---|
| 98 | return true;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | return false;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | static bool CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection );
|
---|
| 106 | };
|
---|
| 107 | extern NamespaceSupporter namespaceSupporter;
|
---|