source: dev/trunk/abdev/BasicCompiler_Common/include/NamespaceSupporter.h@ 198

Last change on this file since 198 was 198, checked in by dai_9181, 17 years ago
File size: 3.0 KB
Line 
1#pragma once
2
3#include <Compiler.h>
4
5class NamespaceSupporter
6{
7 // Importsされた名前空間
8 NamespaceScopesCollection importedNamespaces;
9
10 // 現在の名前空間
11 NamespaceScopes livingNamespaceScopes;
12
13public:
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 void SetLivingNamespaceScopes( const NamespaceScopes &namespaceScopes )
39 {
40 this->livingNamespaceScopes = namespaceScopes;
41 }
42 bool IsLiving( const NamespaceScopes &namespaceScopes ) const
43 {
44 return NamespaceScopes::IsBelong( namespaceScopes, livingNamespaceScopes );
45 }
46
47
48 // 包括しているかをチェック
49 // 例:
50 // this = "Discoversoft.ActiveBasic"
51 // living = "Discoversoft.ActiveBasic"
52 // entryName = "ActiveBasic"
53 // この場合、living は entryName を包括している。
54 bool IsCoverd( const NamespaceScopes &namespaceScopes, const string &entryName ) const
55 {
56 if( namespaceScopes.IsEqual( entryName ) ){
57 return true;
58 }
59
60 string thisStr = namespaceScopes.ToString();
61
62 NamespaceScopes tempLivingNamespaceScopes = livingNamespaceScopes;
63
64 while( tempLivingNamespaceScopes.size() ){
65 NamespaceScopes tempNamespaceScopes = tempLivingNamespaceScopes;
66
67 string tempStr = tempNamespaceScopes.ToString() + "." + entryName;
68 if( thisStr == tempStr ){
69 return true;
70 }
71
72 tempLivingNamespaceScopes.pop_back();
73 }
74 return false;
75 }
76 bool IsCoverd( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ) const
77 {
78 return IsCoverd( baseNamespaceScopes, entryNamespaceScopes.ToString() );
79 }
80
81
82 // 指定された名前空間が同一エリアと見なされるかどうかをチェック
83 bool IsSameAreaNamespace( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ){
84 if( entryNamespaceScopes.size() ){
85 if( IsCoverd( baseNamespaceScopes, entryNamespaceScopes ) ){
86 // 包括しているときは同一と見なす
87 return true;
88 }
89 }
90 else{
91 if( baseNamespaceScopes.size() ){
92 // 名前空間の判断が必要なとき
93 if( this->importedNamespaces.IsImported( baseNamespaceScopes )
94 || IsLiving( baseNamespaceScopes ) ){
95 // Using指定があるとき
96 // または
97 // 指定された名前空間が現在の名前空間スコープと同一のとき
98 return true;
99 }
100 }
101 else{
102 return true;
103 }
104 }
105
106 return false;
107 }
108
109 static bool CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection );
110};
111extern NamespaceSupporter namespaceSupporter;
Note: See TracBrowser for help on using the repository browser.