xref: /trunk/main/idlc/inc/idlc/astinterface.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _IDLC_ASTINTERFACE_HXX_
28 #define _IDLC_ASTINTERFACE_HXX_
29 
30 #include <idlc/asttype.hxx>
31 #include <idlc/astscope.hxx>
32 #include "idlc/inheritedinterface.hxx"
33 
34 #include <map>
35 #include <vector>
36 
37 class AstInterface : public AstType
38 				   , public AstScope
39 {
40 public:
41     typedef std::vector< InheritedInterface > InheritedInterfaces;
42 
43     typedef std::vector< AstInterface const * > DoubleInterfaceDeclarations;
44 
45     struct DoubleMemberDeclaration {
46         AstDeclaration const * first;
47         AstDeclaration const * second;
48     };
49 
50     typedef std::vector< DoubleMemberDeclaration > DoubleMemberDeclarations;
51 
52     struct DoubleDeclarations {
53         DoubleInterfaceDeclarations interfaces;
54         DoubleMemberDeclarations members;
55     };
56 
57 	AstInterface(
58         const ::rtl::OString& name, AstInterface const * pInherits,
59         AstScope* pScope);
60 	virtual ~AstInterface();
61 
62     InheritedInterfaces const & getAllInheritedInterfaces() const
63     { return m_inheritedInterfaces; }
64 
65     bool hasMandatoryInheritedInterfaces() const
66     { return m_mandatoryInterfaces > 0; }
67 
68 	void setForwarded(sal_Bool bForwarded)
69 		{ m_bForwarded = bForwarded; }
70 	sal_Bool isForwarded()
71 		{ return m_bForwarded; }
72 	void setForwardedInSameFile(sal_Bool bForwarded)
73 		{ m_bForwardedInSameFile = bForwarded; }
74 	sal_Bool isForwardedInSameFile()
75 		{ return m_bForwardedInSameFile; }
76 
77     void setDefined() { m_bIsDefined = true; }
78 	sal_Bool isDefined() const
79 		{ return m_bIsDefined; }
80 
81     bool usesSingleInheritance() const { return m_bSingleInheritance; }
82 
83     DoubleDeclarations checkInheritedInterfaceClashes(
84         AstInterface const * ifc, bool optional) const;
85 
86     void addInheritedInterface(
87         AstType const * ifc, bool optional,
88         rtl::OUString const & documentation);
89 
90     DoubleMemberDeclarations checkMemberClashes(
91         AstDeclaration const * member) const;
92 
93     void addMember(AstDeclaration /*TODO: const*/ * member);
94 
95     void forwardDefined(AstInterface const & def);
96 
97 	virtual sal_Bool dump(RegistryKey& rKey);
98 
99 private:
100     enum InterfaceKind {
101         INTERFACE_INDIRECT_OPTIONAL, INTERFACE_DIRECT_OPTIONAL,
102         INTERFACE_INDIRECT_MANDATORY, INTERFACE_DIRECT_MANDATORY };
103 
104     struct VisibleMember {
105         explicit VisibleMember(AstDeclaration const * theMandatory = 0):
106             mandatory(theMandatory) {}
107 
108         typedef std::map< rtl::OString, AstDeclaration const * > Optionals;
109 
110         AstDeclaration const * mandatory;
111         Optionals optionals;
112     };
113 
114     typedef std::map< rtl::OString, InterfaceKind > VisibleInterfaces;
115     typedef std::map< rtl::OString, VisibleMember > VisibleMembers;
116 
117     void checkInheritedInterfaceClashes(
118         DoubleDeclarations & doubleDeclarations,
119         std::set< rtl::OString > & seenInterfaces, AstInterface const * ifc,
120         bool optional, bool direct, bool mainOptional) const;
121 
122     void checkMemberClashes(
123         DoubleMemberDeclarations & doubleMembers, AstDeclaration const * member,
124         bool checkOptional) const;
125 
126     void addVisibleInterface(
127         AstInterface const * ifc, bool direct, bool optional);
128 
129     void addOptionalVisibleMembers(AstInterface const * ifc);
130 
131     bool increment(sal_uInt16 * counter, char const * sort) const;
132 
133     InheritedInterfaces m_inheritedInterfaces;
134     InheritedInterfaces::size_type m_mandatoryInterfaces;
135 	sal_Bool	m_bIsDefined;
136 	sal_Bool	m_bForwarded;
137 	sal_Bool	m_bForwardedInSameFile;
138     bool m_bSingleInheritance;
139     VisibleInterfaces m_visibleInterfaces;
140     VisibleMembers m_visibleMembers;
141 };
142 
143 #endif // _IDLC_ASTINTERFACE_HXX_
144