Update ooo320-m1
[ooovba.git] / autodoc / source / parser_i / idoc / docu_pe2.cxx
blob79d3bc41ba3dbaa3184a9deb6c1395badf85d627
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docu_pe2.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include <s2_dsapi/docu_pe2.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <ary/doc/d_oldidldocu.hxx>
37 #include <ary_i/d_token.hxx>
38 #include <parser/parserinfo.hxx>
39 #include <adc_cl.hxx>
40 #include <adc_msg.hxx>
41 #include <../parser/inc/x_docu.hxx>
42 #include <s2_dsapi/dsapitok.hxx>
43 #include <s2_dsapi/tk_atag2.hxx>
44 #include <s2_dsapi/tk_html.hxx>
45 #include <s2_dsapi/tk_docw2.hxx>
46 #include <s2_dsapi/tk_xml.hxx>
49 #ifdef UNX
50 #define strnicmp strncasecmp
51 #endif
54 namespace csi
56 namespace dsapi
60 const char * AtTagTitle(
61 const Tok_AtTag & i_rToken );
64 SapiDocu_PE::SapiDocu_PE(ParserInfo & io_rPositionInfo)
65 : pDocu(0),
66 eState(e_none),
67 pPositionInfo(&io_rPositionInfo),
68 fCurTokenAddFunction(&SapiDocu_PE::AddDocuToken2Void),
69 pCurAtTag(0),
70 sCurDimAttribute(),
71 sCurAtSeeType_byXML(200)
75 SapiDocu_PE::~SapiDocu_PE()
79 void
80 SapiDocu_PE::ProcessToken( DYN csi::dsapi::Token & let_drToken )
82 if (IsComplete())
84 pDocu = 0;
85 eState = e_none;
88 if ( eState == e_none )
90 pDocu = new ary::doc::OldIdlDocu;
91 eState = st_short;
92 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Short;
95 csv_assert(pDocu);
97 let_drToken.Trigger(*this);
98 delete &let_drToken;
101 void
102 SapiDocu_PE::Process_AtTag( const Tok_AtTag & i_rToken )
104 if (NOT pCurAtTag)
106 eState = st_attags;
107 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
109 else
111 csv_assert(eState == st_attags);
112 pDocu->AddAtTag(*pCurAtTag.Release());
115 if (i_rToken.Id() == Tok_AtTag::param)
117 pCurAtTag = new DT_ParameterAtTag;
118 fCurTokenAddFunction = &SapiDocu_PE::SetCurParameterAtTagName;
120 else if (i_rToken.Id() == Tok_AtTag::see)
122 pCurAtTag = new DT_SeeAlsoAtTag;
123 fCurTokenAddFunction = &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText;
125 else if (i_rToken.Id() == Tok_AtTag::deprecated)
127 pDocu->SetDeprecated();
128 pCurAtTag = new DT_StdAtTag(""); // Dummy that will not be used.
129 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Deprecated;
131 else if (i_rToken.Id() == Tok_AtTag::since)
133 pCurAtTag = new DT_SinceAtTag;
134 fCurTokenAddFunction = &SapiDocu_PE::SetCurSinceAtTagVersion;
136 else
138 pCurAtTag = new DT_StdAtTag( AtTagTitle(i_rToken) );
139 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
143 void
144 SapiDocu_PE::Process_HtmlTag( const Tok_HtmlTag & i_rToken )
146 if (eState == st_short AND i_rToken.IsParagraphStarter())
148 eState = st_description;
149 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Description;
152 // Workaround special for some errors in API docu:
153 if ( strnicmp("<true",i_rToken.Text(),5 ) == 0 )
155 if ( strcmp("<TRUE/>",i_rToken.Text()) != 0 )
156 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
157 pPositionInfo->CurFile(),
158 pPositionInfo->CurLine() );
159 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>true</b>") );
160 return;
162 else if ( strnicmp("<false",i_rToken.Text(),6 ) == 0 )
164 if ( strcmp("<FALSE/>",i_rToken.Text()) != 0 )
165 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
166 pPositionInfo->CurFile(),
167 pPositionInfo->CurLine() );
168 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>false</b>") );
169 return;
171 else if ( strnicmp("<NULL",i_rToken.Text(),5 ) == 0 )
173 if ( strcmp("<NULL/>",i_rToken.Text()) != 0 )
174 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
175 pPositionInfo->CurFile(),
176 pPositionInfo->CurLine() );
177 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>null</b>") );
178 return;
180 else if ( strnicmp("<void",i_rToken.Text(),5 ) == 0 )
182 if ( strcmp("<void/>",i_rToken.Text()) != 0 )
183 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
184 pPositionInfo->CurFile(),
185 pPositionInfo->CurLine() );
186 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>void</b>") );
187 return;
190 (this->*fCurTokenAddFunction)( *new DT_Style(i_rToken.Text(),false) );
193 void
194 SapiDocu_PE::Process_XmlConst( const Tok_XmlConst & i_rToken )
196 (this->*fCurTokenAddFunction)(*new DT_MupConst(i_rToken.Text()));
199 void
200 SapiDocu_PE::Process_XmlLink_BeginTag( const Tok_XmlLink_BeginTag & i_rToken )
202 switch (i_rToken.Id())
204 case Tok_XmlLink_Tag::e_const:
205 (this->*fCurTokenAddFunction)(*new DT_Style("<b>",false));
206 break;
207 case Tok_XmlLink_Tag::member:
208 (this->*fCurTokenAddFunction)(*new DT_MupMember(i_rToken.Scope()));
209 break;
210 case Tok_XmlLink_Tag::type:
211 (this->*fCurTokenAddFunction)(*new DT_MupType(i_rToken.Scope()));
212 break;
213 default:
214 // Do nothing.
218 if ( i_rToken.Dim().length() > 0 )
219 sCurDimAttribute = i_rToken.Dim();
220 else
221 sCurDimAttribute.clear();
224 void
225 SapiDocu_PE::Process_XmlLink_EndTag( const Tok_XmlLink_EndTag & i_rToken )
227 switch (i_rToken.Id())
229 case Tok_XmlLink_Tag::e_const:
230 (this->*fCurTokenAddFunction)(*new DT_Style("</b>",false));
231 break;
232 case Tok_XmlLink_Tag::member:
233 (this->*fCurTokenAddFunction)(*new DT_MupMember(true));
234 break;
235 case Tok_XmlLink_Tag::type:
236 (this->*fCurTokenAddFunction)(*new DT_MupType(true));
237 break;
238 default:
239 // Do nothing.
242 if ( sCurDimAttribute.length() > 0 )
244 (this->*fCurTokenAddFunction)( *new DT_TextToken(sCurDimAttribute.c_str()) );
245 sCurDimAttribute.clear();
249 void
250 SapiDocu_PE::Process_XmlFormat_BeginTag( const Tok_XmlFormat_BeginTag & i_rToken )
252 switch (i_rToken.Id())
254 case Tok_XmlFormat_Tag::code:
255 (this->*fCurTokenAddFunction)(*new DT_Style("<code>",false));
256 break;
257 case Tok_XmlFormat_Tag::listing:
258 (this->*fCurTokenAddFunction)(*new DT_Style("<pre>",true));
259 break;
260 case Tok_XmlFormat_Tag::atom:
261 (this->*fCurTokenAddFunction)(*new DT_Style("<code>",true));
262 break;
263 default:
264 // Do nothing.
267 if ( i_rToken.Dim().length() > 0 )
268 sCurDimAttribute = i_rToken.Dim();
269 else
270 sCurDimAttribute.clear();
273 void
274 SapiDocu_PE::Process_XmlFormat_EndTag( const Tok_XmlFormat_EndTag & i_rToken )
276 switch (i_rToken.Id())
278 case Tok_XmlFormat_Tag::code:
279 (this->*fCurTokenAddFunction)(*new DT_Style("</code>",false));
280 break;
281 case Tok_XmlFormat_Tag::listing:
282 (this->*fCurTokenAddFunction)(*new DT_Style("</pre>",true));
283 break;
284 case Tok_XmlFormat_Tag::atom:
285 (this->*fCurTokenAddFunction)(*new DT_Style("</code>",true));
286 break;
287 default:
288 // Do nothing.
291 if ( sCurDimAttribute.length() > 0 )
293 (this->*fCurTokenAddFunction)( *new DT_TextToken(sCurDimAttribute.c_str()) );
294 sCurDimAttribute.clear();
298 void
299 SapiDocu_PE::Process_Word( const Tok_Word & i_rToken )
301 (this->*fCurTokenAddFunction)(*new DT_TextToken(i_rToken.Text()));
304 void
305 SapiDocu_PE::Process_Comma()
307 csv_assert(1==7);
308 // (this->*fCurTokenAddFunction)(*new DT_Comma(i_rToken.Text()));
311 void
312 SapiDocu_PE::Process_DocuEnd()
314 eState = st_complete;
315 if (pCurAtTag)
316 pDocu->AddAtTag(*pCurAtTag.Release());
317 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Void;
320 void
321 SapiDocu_PE::Process_EOL()
323 (this->*fCurTokenAddFunction)(*new DT_EOL);
326 void
327 SapiDocu_PE::Process_White()
329 (this->*fCurTokenAddFunction)(*new DT_White);
332 DYN ary::doc::OldIdlDocu *
333 SapiDocu_PE::ReleaseJustParsedDocu()
335 if (IsComplete())
337 eState = e_none;
338 return pDocu.Release();
340 return 0;
344 bool
345 SapiDocu_PE::IsComplete() const
347 return eState == st_complete;
350 void
351 SapiDocu_PE::AddDocuToken2Void( DYN ary::inf::DocuToken & let_drNewToken )
353 delete &let_drNewToken;
356 void
357 SapiDocu_PE::AddDocuToken2Short( DYN ary::inf::DocuToken & let_drNewToken )
359 csv_assert(pDocu);
360 pDocu->AddToken2Short(let_drNewToken);
363 void
364 SapiDocu_PE::AddDocuToken2Description( DYN ary::inf::DocuToken & let_drNewToken )
366 csv_assert(pDocu);
367 pDocu->AddToken2Description(let_drNewToken);
370 void
371 SapiDocu_PE::AddDocuToken2Deprecated( DYN ary::inf::DocuToken & let_drNewToken )
373 csv_assert(pDocu);
374 pDocu->AddToken2DeprecatedText(let_drNewToken);
377 void
378 SapiDocu_PE::AddDocuToken2CurAtTag( DYN ary::inf::DocuToken & let_drNewToken )
380 csv_assert(pCurAtTag);
381 pCurAtTag->AddToken(let_drNewToken);
384 void
385 SapiDocu_PE::SetCurParameterAtTagName( DYN ary::inf::DocuToken & let_drNewToken )
387 if (let_drNewToken.IsWhiteOnly())
389 delete &let_drNewToken;
390 return;
393 csv_assert(pCurAtTag);
394 DT_TextToken * dpText = dynamic_cast< DT_TextToken* >(&let_drNewToken);
395 if (dpText != 0)
396 pCurAtTag->SetName(dpText->GetText());
397 else
398 pCurAtTag->SetName("parameter ?");
399 delete &let_drNewToken;
400 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
403 void
404 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText( DYN ary::inf::DocuToken & let_drNewToken )
406 csv_assert(pCurAtTag);
408 if (let_drNewToken.IsWhiteOnly())
410 delete &let_drNewToken;
411 return;
414 DT_TextToken * pText = dynamic_cast< DT_TextToken* >(&let_drNewToken);
415 if (pText != 0)
416 pCurAtTag->SetName(pText->GetText());
417 else
419 DT_MupType *
420 pTypeBegin = dynamic_cast< DT_MupType* >(&let_drNewToken);
421 DT_MupMember *
422 pMemberBegin = dynamic_cast< DT_MupMember* >(&let_drNewToken);
423 if (pTypeBegin != 0 OR pMemberBegin != 0)
425 sCurAtSeeType_byXML.reset();
427 sCurAtSeeType_byXML
428 << ( pTypeBegin != 0
429 ? pTypeBegin->Scope()
430 : pMemberBegin->Scope() );
432 if (sCurAtSeeType_byXML.tellp() > 0)
434 sCurAtSeeType_byXML
435 << "::";
437 delete &let_drNewToken;
438 fCurTokenAddFunction = &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2;
439 return;
441 else
443 pCurAtTag->SetName("? (no identifier found)");
446 delete &let_drNewToken;
447 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
450 void
451 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2( DYN ary::inf::DocuToken & let_drNewToken )
453 csv_assert(pCurAtTag);
455 if (let_drNewToken.IsWhiteOnly())
457 delete &let_drNewToken;
458 return;
461 DT_TextToken *
462 pText = dynamic_cast< DT_TextToken* >(&let_drNewToken);
463 if (pText != 0)
465 sCurAtSeeType_byXML
466 << pText->GetText();
467 pCurAtTag->SetName(sCurAtSeeType_byXML.c_str());
469 else
471 pCurAtTag->SetName("? (no identifier found)");
473 sCurAtSeeType_byXML.reset();
474 delete &let_drNewToken;
475 fCurTokenAddFunction = &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3;
478 void
479 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3( DYN ary::inf::DocuToken & let_drNewToken )
481 csv_assert(pCurAtTag);
483 if (let_drNewToken.IsWhiteOnly())
485 delete &let_drNewToken;
486 return;
489 /// Could emit warning, but don't because this parser is obsolete.
490 // Tok_XmlLink_BeginTag *
491 // pLinkEnd = dynamic_cast< Tok_XmlLink_EndTag* >(&let_drNewToken);
492 // if (pLinkEnd == 0)
493 // {
494 // warn_aboutMissingClosingTag();
495 // }
497 delete &let_drNewToken;
498 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
503 void
504 SapiDocu_PE::SetCurSinceAtTagVersion( DYN ary::inf::DocuToken & let_drNewToken )
506 csv_assert(pCurAtTag);
508 DT_TextToken * pToken = dynamic_cast< DT_TextToken* >(&let_drNewToken);
509 if (pToken == 0)
511 delete &let_drNewToken;
512 return;
515 const String
516 sVersion(pToken->GetText());
517 const char
518 cFirst = *sVersion.begin();
519 const char
520 cCiphersend = '9' + 1;
521 const autodoc::CommandLine &
522 rCommandLine = autodoc::CommandLine::Get_();
525 if ( rCommandLine.DoesTransform_SinceTag())
527 // The @since version number shall be interpreted,
529 if ( NOT csv::in_range('0', cFirst, cCiphersend) )
531 // But this is a non-number-part, so we wait for
532 // the next one.
533 delete &let_drNewToken;
534 return;
536 else if (rCommandLine.DisplayOf_SinceTagValue(sVersion).empty())
538 // This is the numbered part, but we don't know it.
539 delete &let_drNewToken;
541 StreamLock
542 sl(200);
543 sl()
544 << "Since-value '"
545 << sVersion
546 << "' not found in translation table.";
547 throw X_Docu("since", sl().c_str());
551 // Either since tags are not specially interpreted, or
552 // we got a known one.
553 pCurAtTag->AddToken(let_drNewToken);
554 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2SinceAtTag;
557 void
558 SapiDocu_PE::AddDocuToken2SinceAtTag( DYN ary::inf::DocuToken & let_drNewToken )
560 csv_assert(pCurAtTag);
561 String &
562 sValue = pCurAtTag->Access_Text().Access_TextOfFirstToken();
563 StreamLock
564 sHelp(1000);
566 DT_TextToken *
567 pToken = dynamic_cast< DT_TextToken* >(&let_drNewToken);
568 if (pToken != 0)
570 sValue = sHelp() << sValue << pToken->GetText() << c_str;
572 else if (dynamic_cast< DT_White* >(&let_drNewToken) != 0)
574 sValue = sHelp() << sValue << " " << c_str;
576 delete &let_drNewToken;
579 const char *
580 AtTagTitle( const Tok_AtTag & i_rToken )
582 switch (i_rToken.Id())
584 case Tok_AtTag::author: return "";
585 case Tok_AtTag::see: return "See also";
586 case Tok_AtTag::param: return "Parameters";
587 case Tok_AtTag::e_return: return "Returns";
588 case Tok_AtTag::e_throw: return "Throws";
589 case Tok_AtTag::example: return "Example";
590 case Tok_AtTag::deprecated: return "Deprecated";
591 case Tok_AtTag::suspicious: return "";
592 case Tok_AtTag::missing: return "";
593 case Tok_AtTag::incomplete: return "";
594 case Tok_AtTag::version: return "";
595 case Tok_AtTag::guarantees: return "Guarantees";
596 case Tok_AtTag::exception: return "Exception";
597 case Tok_AtTag::since: return "Since version";
598 default:
599 // See below.
602 return i_rToken.Text();
607 } // namespace dsapi
608 } // namespace csi