1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include <s2_luidl/pe_selem.hxx>
24 
25 // NOT FULLY DECLARED SERVICES
26 #include <ary/idl/i_gate.hxx>
27 #include <ary/idl/i_struct.hxx>
28 #include <ary/idl/i_structelem.hxx>
29 #include <ary/idl/ip_ce.hxx>
30 #include <ary/doc/d_oldidldocu.hxx>
31 #include <s2_luidl/pe_type2.hxx>
32 #include <s2_luidl/tk_ident.hxx>
33 #include <s2_luidl/tk_punct.hxx>
34 
35 
36 namespace csi
37 {
38 namespace uidl
39 {
40 
41 namespace
42 {
43     const String  C_sNone;
44 }
45 
PE_StructElement(RStructElement & o_rResult,const RStruct & i_rCurStruct,const String & i_rCurStructTemplateParam)46 PE_StructElement::PE_StructElement( RStructElement &	o_rResult,
47 									const RStruct &		i_rCurStruct,
48 							        const String &      i_rCurStructTemplateParam )
49 	:	eState(e_none),
50 		pResult(&o_rResult),
51 		pCurStruct(&i_rCurStruct),
52 		bIsExceptionElement(false),
53 		pPE_Type(0),
54 		nType(0),
55 		sName(),
56 		pCurStructTemplateParam(&i_rCurStructTemplateParam)
57 {
58 	pPE_Type = new PE_Type(nType);
59 }
60 
PE_StructElement(RStructElement & o_rResult,const RStruct & i_rCurExc)61 PE_StructElement::PE_StructElement( RStructElement &	o_rResult,
62 							        const RStruct &		i_rCurExc )
63 	:	eState(e_none),
64 		pResult(&o_rResult),
65 		pCurStruct(&i_rCurExc),
66 		bIsExceptionElement(true),
67 		pPE_Type(0),
68 		nType(0),
69 		sName(),
70 		pCurStructTemplateParam(&C_sNone)
71 {
72 	pPE_Type = new PE_Type(nType);
73 }
74 
75 void
EstablishContacts(UnoIDL_PE * io_pParentPE,ary::Repository & io_rRepository,TokenProcessing_Result & o_rResult)76 PE_StructElement::EstablishContacts( UnoIDL_PE *				io_pParentPE,
77 									 ary::Repository &		io_rRepository,
78 							         TokenProcessing_Result & 	o_rResult )
79 {
80 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
81 	pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
82 }
83 
~PE_StructElement()84 PE_StructElement::~PE_StructElement()
85 {
86 }
87 
88 void
ProcessToken(const Token & i_rToken)89 PE_StructElement::ProcessToken( const Token & i_rToken )
90 {
91 	i_rToken.Trigger(*this);
92 }
93 
94 void
Process_Default()95 PE_StructElement::Process_Default()
96 {
97 	if (eState == expect_type)
98 	{
99 		SetResult( not_done, push_sure, pPE_Type.Ptr() );
100 		eState = expect_name;
101 	}
102 	else {
103 		csv_assert(false);
104     }
105 }
106 
107 void
Process_Identifier(const TokIdentifier & i_rToken)108 PE_StructElement::Process_Identifier( const TokIdentifier & i_rToken )
109 {
110     csv_assert(*i_rToken.Text() != 0);
111 
112 	if (eState == expect_type)
113 	{
114 	    if ( *pCurStructTemplateParam == i_rToken.Text() )
115 	    {
116             nType = lhf_FindTemplateParamType();
117        		SetResult( done, stay );
118         	eState = expect_name;
119 	    }
120 	    else    // No template parameter type existing, or not matching:
121 	    {
122        		SetResult( not_done, push_sure, pPE_Type.Ptr() );
123         	eState = expect_name;
124 	    }
125 	}
126 	else if (eState == expect_name)
127 	{
128 		sName = i_rToken.Text();
129 		SetResult( done, stay );
130         eState = expect_finish;
131 	}
132 	else {
133 		csv_assert(false);
134     }
135 }
136 
137 void
Process_Punctuation(const TokPunctuation &)138 PE_StructElement::Process_Punctuation( const TokPunctuation &)
139 {
140     csv_assert(eState == expect_finish);
141 
142 	SetResult( done, pop_success );
143 }
144 
145 void
InitData()146 PE_StructElement::InitData()
147 {
148 	eState = expect_type;
149 
150 	nType = 0;
151 	sName = "";
152 }
153 
154 void
TransferData()155 PE_StructElement::TransferData()
156 {
157 	csv_assert(pResult != 0 AND pCurStruct != 0);
158 
159     ary::idl::StructElement *
160         pCe = 0;
161     if (bIsExceptionElement)
162     {
163         pCe = & Gate().Ces().Store_ExceptionMember(
164                                             *pCurStruct,
165                                             sName,
166                                             nType );
167     }
168     else
169     {
170         pCe = & Gate().Ces().Store_StructMember(
171                                             *pCurStruct,
172                                             sName,
173                                             nType );
174     }
175 	*pResult = pCe->CeId();
176 	PassDocuAt(*pCe);
177 
178 	eState = e_none;
179 }
180 
181 UnoIDL_PE &
MyPE()182 PE_StructElement::MyPE()
183 {
184 	return *this;
185 }
186 
187 ary::idl::Type_id
lhf_FindTemplateParamType() const188 PE_StructElement::lhf_FindTemplateParamType() const
189 {
190     const ary::idl::CodeEntity &
191         rCe = Gate().Ces().Find_Ce(*pCurStruct);
192     const ary::idl::Struct &
193         rStruct = static_cast< const ary::idl::Struct& >(rCe);
194     return rStruct.TemplateParameterType();
195 }
196 
197 
198 }   // namespace uidl
199 }   // namespace csi
200