merged tag ooo/OOO330_m14
[LibreOffice.git] / autodoc / source / parser_i / idoc / docu_pe2.cxx
blob084dbbf0660cde6b82a28e66f2f91cb7ba75b9e0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include <precomp.h>
29 #include <s2_dsapi/docu_pe2.hxx>
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/doc/d_oldidldocu.hxx>
34 #include <ary_i/d_token.hxx>
35 #include <parser/parserinfo.hxx>
36 #include <adc_cl.hxx>
37 #include <adc_msg.hxx>
38 #include <../parser/inc/x_docu.hxx>
39 #include <s2_dsapi/dsapitok.hxx>
40 #include <s2_dsapi/tk_atag2.hxx>
41 #include <s2_dsapi/tk_html.hxx>
42 #include <s2_dsapi/tk_docw2.hxx>
43 #include <s2_dsapi/tk_xml.hxx>
46 #ifdef UNX
47 #define strnicmp strncasecmp
48 #endif
51 namespace csi
53 namespace dsapi
57 const char * AtTagTitle(
58 const Tok_AtTag & i_rToken );
61 SapiDocu_PE::SapiDocu_PE(ParserInfo & io_rPositionInfo)
62 : pDocu(0),
63 eState(e_none),
64 pPositionInfo(&io_rPositionInfo),
65 fCurTokenAddFunction(&SapiDocu_PE::AddDocuToken2Void),
66 pCurAtTag(0),
67 sCurDimAttribute(),
68 sCurAtSeeType_byXML(200)
72 SapiDocu_PE::~SapiDocu_PE()
76 void
77 SapiDocu_PE::ProcessToken( DYN csi::dsapi::Token & let_drToken )
79 if (IsComplete())
81 pDocu = 0;
82 eState = e_none;
85 if ( eState == e_none )
87 pDocu = new ary::doc::OldIdlDocu;
88 eState = st_short;
89 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Short;
92 csv_assert(pDocu);
94 let_drToken.Trigger(*this);
95 delete &let_drToken;
98 void
99 SapiDocu_PE::Process_AtTag( const Tok_AtTag & i_rToken )
101 if (NOT pCurAtTag)
103 eState = st_attags;
104 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
106 else
108 csv_assert(eState == st_attags);
109 pDocu->AddAtTag(*pCurAtTag.Release());
112 if (i_rToken.Id() == Tok_AtTag::param)
114 pCurAtTag = new DT_ParameterAtTag;
115 fCurTokenAddFunction = &SapiDocu_PE::SetCurParameterAtTagName;
117 else if (i_rToken.Id() == Tok_AtTag::see)
119 pCurAtTag = new DT_SeeAlsoAtTag;
120 fCurTokenAddFunction = &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText;
122 else if (i_rToken.Id() == Tok_AtTag::deprecated)
124 pDocu->SetDeprecated();
125 pCurAtTag = new DT_StdAtTag(""); // Dummy that will not be used.
126 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Deprecated;
128 else if (i_rToken.Id() == Tok_AtTag::since)
130 pCurAtTag = new DT_SinceAtTag;
131 fCurTokenAddFunction = &SapiDocu_PE::SetCurSinceAtTagVersion;
133 else
135 pCurAtTag = new DT_StdAtTag( AtTagTitle(i_rToken) );
136 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
140 void
141 SapiDocu_PE::Process_HtmlTag( const Tok_HtmlTag & i_rToken )
143 if (eState == st_short AND i_rToken.IsParagraphStarter())
145 eState = st_description;
146 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Description;
149 // Workaround special for some errors in API docu:
150 if ( strnicmp("<true",i_rToken.Text(),5 ) == 0 )
152 if ( strcmp("<TRUE/>",i_rToken.Text()) != 0 )
153 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
154 pPositionInfo->CurFile(),
155 pPositionInfo->CurLine() );
156 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>true</b>") );
157 return;
159 else if ( strnicmp("<false",i_rToken.Text(),6 ) == 0 )
161 if ( strcmp("<FALSE/>",i_rToken.Text()) != 0 )
162 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
163 pPositionInfo->CurFile(),
164 pPositionInfo->CurLine() );
165 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>false</b>") );
166 return;
168 else if ( strnicmp("<NULL",i_rToken.Text(),5 ) == 0 )
170 if ( strcmp("<NULL/>",i_rToken.Text()) != 0 )
171 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
172 pPositionInfo->CurFile(),
173 pPositionInfo->CurLine() );
174 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>null</b>") );
175 return;
177 else if ( strnicmp("<void",i_rToken.Text(),5 ) == 0 )
179 if ( strcmp("<void/>",i_rToken.Text()) != 0 )
180 TheMessages().Out_InvalidConstSymbol( i_rToken.Text(),
181 pPositionInfo->CurFile(),
182 pPositionInfo->CurLine() );
183 (this->*fCurTokenAddFunction)( *new DT_TextToken("<b>void</b>") );
184 return;
187 (this->*fCurTokenAddFunction)( *new DT_Style(i_rToken.Text(),false) );
190 void
191 SapiDocu_PE::Process_XmlConst( const Tok_XmlConst & i_rToken )
193 (this->*fCurTokenAddFunction)(*new DT_MupConst(i_rToken.Text()));
196 void
197 SapiDocu_PE::Process_XmlLink_BeginTag( const Tok_XmlLink_BeginTag & i_rToken )
199 switch (i_rToken.Id())
201 case Tok_XmlLink_Tag::e_const:
202 (this->*fCurTokenAddFunction)(*new DT_Style("<b>",false));
203 break;
204 case Tok_XmlLink_Tag::member:
205 (this->*fCurTokenAddFunction)(*new DT_MupMember(i_rToken.Scope()));
206 break;
207 case Tok_XmlLink_Tag::type:
208 (this->*fCurTokenAddFunction)(*new DT_MupType(i_rToken.Scope()));
209 break;
210 default:
211 // Do nothing.
215 if ( i_rToken.Dim().length() > 0 )
216 sCurDimAttribute = i_rToken.Dim();
217 else
218 sCurDimAttribute.clear();
221 void
222 SapiDocu_PE::Process_XmlLink_EndTag( const Tok_XmlLink_EndTag & i_rToken )
224 switch (i_rToken.Id())
226 case Tok_XmlLink_Tag::e_const:
227 (this->*fCurTokenAddFunction)(*new DT_Style("</b>",false));
228 break;
229 case Tok_XmlLink_Tag::member:
230 (this->*fCurTokenAddFunction)(*new DT_MupMember(true));
231 break;
232 case Tok_XmlLink_Tag::type:
233 (this->*fCurTokenAddFunction)(*new DT_MupType(true));
234 break;
235 default:
236 // Do nothing.
239 if ( sCurDimAttribute.length() > 0 )
241 (this->*fCurTokenAddFunction)( *new DT_TextToken(sCurDimAttribute.c_str()) );
242 sCurDimAttribute.clear();
246 void
247 SapiDocu_PE::Process_XmlFormat_BeginTag( const Tok_XmlFormat_BeginTag & i_rToken )
249 switch (i_rToken.Id())
251 case Tok_XmlFormat_Tag::code:
252 (this->*fCurTokenAddFunction)(*new DT_Style("<code>",false));
253 break;
254 case Tok_XmlFormat_Tag::listing:
255 (this->*fCurTokenAddFunction)(*new DT_Style("<pre>",true));
256 break;
257 case Tok_XmlFormat_Tag::atom:
258 (this->*fCurTokenAddFunction)(*new DT_Style("<code>",true));
259 break;
260 default:
261 // Do nothing.
264 if ( i_rToken.Dim().length() > 0 )
265 sCurDimAttribute = i_rToken.Dim();
266 else
267 sCurDimAttribute.clear();
270 void
271 SapiDocu_PE::Process_XmlFormat_EndTag( const Tok_XmlFormat_EndTag & i_rToken )
273 switch (i_rToken.Id())
275 case Tok_XmlFormat_Tag::code:
276 (this->*fCurTokenAddFunction)(*new DT_Style("</code>",false));
277 break;
278 case Tok_XmlFormat_Tag::listing:
279 (this->*fCurTokenAddFunction)(*new DT_Style("</pre>",true));
280 break;
281 case Tok_XmlFormat_Tag::atom:
282 (this->*fCurTokenAddFunction)(*new DT_Style("</code>",true));
283 break;
284 default:
285 // Do nothing.
288 if ( sCurDimAttribute.length() > 0 )
290 (this->*fCurTokenAddFunction)( *new DT_TextToken(sCurDimAttribute.c_str()) );
291 sCurDimAttribute.clear();
295 void
296 SapiDocu_PE::Process_Word( const Tok_Word & i_rToken )
298 (this->*fCurTokenAddFunction)(*new DT_TextToken(i_rToken.Text()));
301 void
302 SapiDocu_PE::Process_Comma()
304 csv_assert(1==7);
305 // (this->*fCurTokenAddFunction)(*new DT_Comma(i_rToken.Text()));
308 void
309 SapiDocu_PE::Process_DocuEnd()
311 eState = st_complete;
312 if (pCurAtTag)
313 pDocu->AddAtTag(*pCurAtTag.Release());
314 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2Void;
317 void
318 SapiDocu_PE::Process_EOL()
320 (this->*fCurTokenAddFunction)(*new DT_EOL);
323 void
324 SapiDocu_PE::Process_White()
326 (this->*fCurTokenAddFunction)(*new DT_White);
329 DYN ary::doc::OldIdlDocu *
330 SapiDocu_PE::ReleaseJustParsedDocu()
332 if (IsComplete())
334 eState = e_none;
335 return pDocu.Release();
337 return 0;
341 bool
342 SapiDocu_PE::IsComplete() const
344 return eState == st_complete;
347 void
348 SapiDocu_PE::AddDocuToken2Void( DYN ary::inf::DocuToken & let_drNewToken )
350 delete &let_drNewToken;
353 void
354 SapiDocu_PE::AddDocuToken2Short( DYN ary::inf::DocuToken & let_drNewToken )
356 csv_assert(pDocu);
357 pDocu->AddToken2Short(let_drNewToken);
360 void
361 SapiDocu_PE::AddDocuToken2Description( DYN ary::inf::DocuToken & let_drNewToken )
363 csv_assert(pDocu);
364 pDocu->AddToken2Description(let_drNewToken);
367 void
368 SapiDocu_PE::AddDocuToken2Deprecated( DYN ary::inf::DocuToken & let_drNewToken )
370 csv_assert(pDocu);
371 pDocu->AddToken2DeprecatedText(let_drNewToken);
374 void
375 SapiDocu_PE::AddDocuToken2CurAtTag( DYN ary::inf::DocuToken & let_drNewToken )
377 csv_assert(pCurAtTag);
378 pCurAtTag->AddToken(let_drNewToken);
381 void
382 SapiDocu_PE::SetCurParameterAtTagName( DYN ary::inf::DocuToken & let_drNewToken )
384 if (let_drNewToken.IsWhiteOnly())
386 delete &let_drNewToken;
387 return;
390 csv_assert(pCurAtTag);
391 DT_TextToken * dpText = dynamic_cast< DT_TextToken* >(&let_drNewToken);
392 if (dpText != 0)
393 pCurAtTag->SetName(dpText->GetText());
394 else
395 pCurAtTag->SetName("parameter ?");
396 delete &let_drNewToken;
397 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
400 void
401 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText( DYN ary::inf::DocuToken & let_drNewToken )
403 csv_assert(pCurAtTag);
405 if (let_drNewToken.IsWhiteOnly())
407 delete &let_drNewToken;
408 return;
411 DT_TextToken * pText = dynamic_cast< DT_TextToken* >(&let_drNewToken);
412 if (pText != 0)
413 pCurAtTag->SetName(pText->GetText());
414 else
416 DT_MupType *
417 pTypeBegin = dynamic_cast< DT_MupType* >(&let_drNewToken);
418 DT_MupMember *
419 pMemberBegin = dynamic_cast< DT_MupMember* >(&let_drNewToken);
420 if (pTypeBegin != 0 OR pMemberBegin != 0)
422 sCurAtSeeType_byXML.reset();
424 sCurAtSeeType_byXML
425 << ( pTypeBegin != 0
426 ? pTypeBegin->Scope()
427 : pMemberBegin->Scope() );
429 if (sCurAtSeeType_byXML.tellp() > 0)
431 sCurAtSeeType_byXML
432 << "::";
434 delete &let_drNewToken;
435 fCurTokenAddFunction = &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2;
436 return;
438 else
440 pCurAtTag->SetName("? (no identifier found)");
443 delete &let_drNewToken;
444 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
447 void
448 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2( DYN ary::inf::DocuToken & let_drNewToken )
450 csv_assert(pCurAtTag);
452 if (let_drNewToken.IsWhiteOnly())
454 delete &let_drNewToken;
455 return;
458 DT_TextToken *
459 pText = dynamic_cast< DT_TextToken* >(&let_drNewToken);
460 if (pText != 0)
462 sCurAtSeeType_byXML
463 << pText->GetText();
464 pCurAtTag->SetName(sCurAtSeeType_byXML.c_str());
466 else
468 pCurAtTag->SetName("? (no identifier found)");
470 sCurAtSeeType_byXML.reset();
471 delete &let_drNewToken;
472 fCurTokenAddFunction = &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3;
475 void
476 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3( DYN ary::inf::DocuToken & let_drNewToken )
478 csv_assert(pCurAtTag);
480 if (let_drNewToken.IsWhiteOnly())
482 delete &let_drNewToken;
483 return;
486 /// Could emit warning, but don't because this parser is obsolete.
487 // Tok_XmlLink_BeginTag *
488 // pLinkEnd = dynamic_cast< Tok_XmlLink_EndTag* >(&let_drNewToken);
489 // if (pLinkEnd == 0)
490 // {
491 // warn_aboutMissingClosingTag();
492 // }
494 delete &let_drNewToken;
495 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2CurAtTag;
500 void
501 SapiDocu_PE::SetCurSinceAtTagVersion( DYN ary::inf::DocuToken & let_drNewToken )
503 csv_assert(pCurAtTag);
505 DT_TextToken * pToken = dynamic_cast< DT_TextToken* >(&let_drNewToken);
506 if (pToken == 0)
508 delete &let_drNewToken;
509 return;
512 const String
513 sVersion(pToken->GetText());
514 const char
515 cFirst = *sVersion.begin();
516 const char
517 cCiphersend = '9' + 1;
518 const autodoc::CommandLine &
519 rCommandLine = autodoc::CommandLine::Get_();
522 if ( rCommandLine.DoesTransform_SinceTag())
524 // The @since version number shall be interpreted,
526 if ( NOT csv::in_range('0', cFirst, cCiphersend) )
528 // But this is a non-number-part, so we wait for
529 // the next one.
530 delete &let_drNewToken;
531 return;
533 else if (rCommandLine.DisplayOf_SinceTagValue(sVersion).empty())
535 // This is the numbered part, but we don't know it.
536 delete &let_drNewToken;
538 StreamLock
539 sl(200);
540 sl()
541 << "Since-value '"
542 << sVersion
543 << "' not found in translation table.";
544 throw X_Docu("since", sl().c_str());
548 // Either since tags are not specially interpreted, or
549 // we got a known one.
550 pCurAtTag->AddToken(let_drNewToken);
551 fCurTokenAddFunction = &SapiDocu_PE::AddDocuToken2SinceAtTag;
554 void
555 SapiDocu_PE::AddDocuToken2SinceAtTag( DYN ary::inf::DocuToken & let_drNewToken )
557 csv_assert(pCurAtTag);
558 String &
559 sValue = pCurAtTag->Access_Text().Access_TextOfFirstToken();
560 StreamLock
561 sHelp(1000);
563 DT_TextToken *
564 pToken = dynamic_cast< DT_TextToken* >(&let_drNewToken);
565 if (pToken != 0)
567 sValue = sHelp() << sValue << pToken->GetText() << c_str;
569 else if (dynamic_cast< DT_White* >(&let_drNewToken) != 0)
571 sValue = sHelp() << sValue << " " << c_str;
573 delete &let_drNewToken;
576 const char *
577 AtTagTitle( const Tok_AtTag & i_rToken )
579 switch (i_rToken.Id())
581 case Tok_AtTag::author: return "";
582 case Tok_AtTag::see: return "See also";
583 case Tok_AtTag::param: return "Parameters";
584 case Tok_AtTag::e_return: return "Returns";
585 case Tok_AtTag::e_throw: return "Throws";
586 case Tok_AtTag::example: return "Example";
587 case Tok_AtTag::deprecated: return "Deprecated";
588 case Tok_AtTag::suspicious: return "";
589 case Tok_AtTag::missing: return "";
590 case Tok_AtTag::incomplete: return "";
591 case Tok_AtTag::version: return "";
592 case Tok_AtTag::guarantees: return "Guarantees";
593 case Tok_AtTag::exception: return "Exception";
594 case Tok_AtTag::since: return "Since version";
595 default:
596 // See below.
599 return i_rToken.Text();
604 } // namespace dsapi
605 } // namespace csi