Doxygen
Loading...
Searching...
No Matches
CCodeParser Class Reference

#include <src/code.h>

Inheritance diagram for CCodeParser:
Collaboration diagram for CCodeParser:

Classes

struct  Private

Public Member Functions

 CCodeParser ()
 ~CCodeParser () override
void parseCode (OutputCodeList &codeOutIntf, const QCString &scopeName, const QCString &input, SrcLangExt lang, bool stripCodeComments, const CodeParserOptions &options) override
 Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.
void resetCodeParserState () override
 Resets the state of the code parser.
void setInsideCodeLine (bool inp)
bool insideCodeLine () const

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 29 of file code.h.

Constructor & Destructor Documentation

◆ CCodeParser()

CCodeParser::CCodeParser ( )

Definition at line 4053 of file code.l.

4053 : p(std::make_unique<CCodeParser::Private>())
4054{
4055 codeYYlex_init_extra(&p->state,&p->yyscanner);
4056#ifdef FLEX_DEBUG
4057 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4058#endif
4060}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4067
std::unique_ptr< Private > p
Definition code.h:47
@ Lex_code
Definition debug.h:52
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132

References Debug::isFlagSet(), Debug::Lex_code, and p.

◆ ~CCodeParser()

CCodeParser::~CCodeParser ( )
override

Definition at line 4062 of file code.l.

4063{
4064 codeYYlex_destroy(p->yyscanner);
4065}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4085 of file code.l.

4086{
4087 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4088 return yyextra->insideCodeLine;
4089}

References p.

◆ parseCode()

void CCodeParser::parseCode ( OutputCodeList & codeOutList,
const QCString & scopeName,
const QCString & input,
SrcLangExt lang,
bool stripCodeComments,
const CodeParserOptions & options )
overridevirtual

Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.

Parameters
[in]codeOutListinterface for writing the result.
[in]scopeNameName of scope to which the code belongs.
[in]inputActual code in the form of a string
[in]langThe programming language of the code fragment.
[in]stripCodeCommentssignals whether or not for the code block the doxygen comments should be stripped.
[in]optionsAdditional options to configure the parser.

Implements CodeParserInterface.

Definition at line 4091 of file code.l.

4093{
4094 yyscan_t yyscanner = p->yyscanner;
4095 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4096 DBG_CTX((stderr,"***parseCode() exBlock=%d exName=%s fd=%p scopeName=%s searchCtx=%s\n",
4097 options.isExample(),qPrint(options.exampleName()),(void*)options.fileDef(),
4098 qPrint(scopeName),options.searchCtx()?qPrint(options.searchCtx()->name()):"<none>"));
4099
4100 if (s.isEmpty()) return;
4101
4102 DebugLex debugLex(Debug::Lex_code, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()) :
4103 !options.exampleName().isEmpty() ? qPrint(options.exampleName()) : nullptr);
4104
4105 od.stripCodeComments(stripCodeComments);
4106 yyextra->code = &od;
4107 yyextra->inputString = s.data();
4108 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
4109 yyextra->absFileName = options.fileDef() ? options.fileDef()->absFilePath():"";
4110 yyextra->inputPosition = 0;
4111 codeYYrestart(nullptr,yyscanner);
4112 yyextra->currentFontClass = nullptr;
4113 yyextra->searchCtx = options.searchCtx();
4114 yyextra->collectXRefs = options.collectXRefs();
4115 yyextra->inFunctionTryBlock = FALSE;
4116 yyextra->symbolResolver.setFileScope(options.fileDef());
4117 yyextra->foldStack.clear();
4118 yyextra->insideSpecialComment = false;
4119 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
4120 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
4121 yyextra->curlyCount = 0;
4122 yyextra->bodyCurlyCount = 0;
4123 yyextra->bracketCount = 0;
4124 yyextra->sharpCount = 0;
4125 yyextra->insideTemplate = FALSE;
4126 yyextra->theCallContext.clear();
4127 while (!yyextra->scopeStack.empty()) yyextra->scopeStack.pop();
4128 yyextra->scopeName = scopeName;
4129 DBG_CTX((stderr,"parseCCode %s\n",qPrint(scopeName)));
4130 yyextra->exampleBlock = options.isExample();
4131 yyextra->exampleName = options.exampleName();
4132 yyextra->sourceFileDef = options.fileDef();
4133 yyextra->lineNumbers = options.fileDef() && options.showLineNumbers();
4134 if (options.fileDef()==nullptr)
4135 {
4136 // create a dummy filedef for the example
4137 yyextra->exampleFileDef = createFileDef(QCString(),(!options.exampleName().isEmpty()?options.exampleName():"generated"));
4138 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
4139 }
4140 yyextra->lang = lang;
4141 yyextra->insideObjC = lang==SrcLangExt::ObjC;
4142 if (yyextra->sourceFileDef)
4143 {
4144 setCurrentDoc(yyscanner,"l00001");
4145 }
4146 yyextra->currentDefinition = options.searchCtx() ? options.searchCtx() : getResolvedNamespace(scopeName);
4147 yyextra->currentMemberDef = nullptr;
4148 yyextra->searchingForBody = options.isExample();
4149 yyextra->insideBody = FALSE;
4150 yyextra->bracketCount = 0;
4151 if (!yyextra->exampleName.isEmpty())
4152 {
4153 yyextra->exampleFile = convertNameToFile(yyextra->exampleName+"-example",FALSE,TRUE);
4154 DBG_CTX((stderr,"yyextra->exampleFile=%s\n",qPrint(yyextra->exampleFile)));
4155 }
4156 yyextra->includeCodeFragment = options.inlineFragment();
4157 DBG_CTX((stderr,"** exBlock=%d exName=%s include=%d\n",options.isExample(),qPrint(options.exampleName()),options.inlineFragment()));
4158 if (!yyextra->insideCodeLine)
4159 {
4160 startCodeLine(yyscanner);
4161 }
4162 yyextra->type.clear();
4163 yyextra->name.clear();
4164 yyextra->args.clear();
4165 yyextra->parmName.clear();
4166 yyextra->parmType.clear();
4167 if (options.memberDef()) setParameterList(yyscanner,options.memberDef());
4168 BEGIN( Body );
4169 codeYYlex(yyscanner);
4170 yyextra->lexInit=TRUE;
4171 if (yyextra->insideCodeLine)
4172 {
4173 endCodeLine(yyscanner);
4174 }
4175 if (Config_getBool(HTML_CODE_FOLDING))
4176 {
4177 while (!yyextra->foldStack.empty())
4178 {
4179 yyextra->code->endFold();
4180 yyextra->foldStack.pop_back();
4181 }
4182 }
4183 if (yyextra->exampleFileDef)
4184 {
4185 // delete the temporary file definition used for this example
4186 yyextra->exampleFileDef.reset();
4187 yyextra->sourceFileDef=nullptr;
4188 }
4189 // write the tooltips
4190 yyextra->tooltipManager.writeTooltips(od);
4191}
virtual const QCString & name() const =0
virtual QCString absFilePath() const =0
virtual QCString fileName() const =0
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
static void endCodeLine(yyscan_t yyscanner)
Definition code.l:2489
#define DBG_CTX(x)
Definition code.l:73
static void startCodeLine(yyscan_t yyscanner)
Definition code.l:2420
static int countLines(yyscan_t yyscanner)
Definition code.l:3473
yyguts_t * yyscan_t
Definition code.l:24
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
Definition code.l:2288
static void setParameterList(yyscan_t yyscanner, const MemberDef *md)
Definition code.l:2634
#define Config_getBool(name)
Definition config.h:33
std::unique_ptr< FileDef > createFileDef(const QCString &p, const QCString &n, const QCString &ref, const QCString &dn)
Definition filedef.cpp:269
NamespaceDef * getResolvedNamespace(const QCString &name)
const char * qPrint(const char *s)
Definition qcstring.h:687
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
bool isExample() const
Definition parserintf.h:81
const Definition * searchCtx() const
Definition parserintf.h:89
const FileDef * fileDef() const
Definition parserintf.h:83
int endLine() const
Definition parserintf.h:85
const MemberDef * memberDef() const
Definition parserintf.h:87
bool showLineNumbers() const
Definition parserintf.h:88
bool inlineFragment() const
Definition parserintf.h:86
QCString exampleName() const
Definition parserintf.h:82
int startLine() const
Definition parserintf.h:84
bool collectXRefs() const
Definition parserintf.h:90
QCString convertNameToFile(const QCString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:3485

References FileDef::absFilePath(), CodeParserOptions::collectXRefs(), Config_getBool, convertNameToFile(), countLines(), createFileDef(), QCString::data(), DBG_CTX, endCodeLine(), CodeParserOptions::endLine(), CodeParserOptions::exampleName(), FALSE, CodeParserOptions::fileDef(), FileDef::fileName(), getResolvedNamespace(), CodeParserOptions::inlineFragment(), QCString::isEmpty(), CodeParserOptions::isExample(), Debug::Lex_code, CodeParserOptions::memberDef(), Definition::name(), p, qPrint(), CodeParserOptions::searchCtx(), setCurrentDoc(), setParameterList(), CodeParserOptions::showLineNumbers(), startCodeLine(), CodeParserOptions::startLine(), OutputCodeList::stripCodeComments(), and TRUE.

◆ resetCodeParserState()

void CCodeParser::resetCodeParserState ( )
overridevirtual

Resets the state of the code parser.

Since multiple code fragments can together form a single example, an explicit function is used to reset the code parser state.

See also
parseCode()

Implements CodeParserInterface.

Definition at line 4067 of file code.l.

4068{
4069 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4070 DBG_CTX((stderr,"***CodeParser::reset()\n"));
4071 yyextra->theVarContext.clear();
4072 while (!yyextra->scopeNameLengthStack.empty()) yyextra->scopeNameLengthStack.pop_back();
4073 yyextra->codeClassMap.clear();
4074 yyextra->curClassBases.clear();
4075 yyextra->anchorCount = 0;
4076 yyextra->insideCodeLine = false;
4077}

References p.

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4079 of file code.l.

4080{
4081 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4082 yyextra->insideCodeLine = inp;
4083}

References p.

Member Data Documentation

◆ p

std::unique_ptr<Private> CCodeParser::p
private

The documentation for this class was generated from the following files: