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 4042 of file code.l.

4042 : p(std::make_unique<CCodeParser::Private>())
4043{
4044 codeYYlex_init_extra(&p->state,&p->yyscanner);
4045#ifdef FLEX_DEBUG
4046 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4047#endif
4049}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4056
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 4051 of file code.l.

4052{
4053 codeYYlex_destroy(p->yyscanner);
4054}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4074 of file code.l.

4075{
4076 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4077 return yyextra->insideCodeLine;
4078}

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 4080 of file code.l.

4082{
4083 yyscan_t yyscanner = p->yyscanner;
4084 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4085 DBG_CTX((stderr,"***parseCode() exBlock=%d exName=%s fd=%p scopeName=%s searchCtx=%s\n",
4086 options.isExample(),qPrint(options.exampleName()),(void*)options.fileDef(),
4087 qPrint(scopeName),options.searchCtx()?qPrint(options.searchCtx()->name()):"<none>"));
4088
4089 if (s.isEmpty()) return;
4090
4091 DebugLex debugLex(Debug::Lex_code, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()) :
4092 !options.exampleName().isEmpty() ? qPrint(options.exampleName()) : nullptr);
4093
4094 od.stripCodeComments(stripCodeComments);
4095 yyextra->code = &od;
4096 yyextra->inputString = s.data();
4097 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
4098 yyextra->absFileName = options.fileDef() ? options.fileDef()->absFilePath():"";
4099 yyextra->inputPosition = 0;
4100 codeYYrestart(nullptr,yyscanner);
4101 yyextra->currentFontClass = nullptr;
4102 yyextra->searchCtx = options.searchCtx();
4103 yyextra->collectXRefs = options.collectXRefs();
4104 yyextra->inFunctionTryBlock = FALSE;
4105 yyextra->symbolResolver.setFileScope(options.fileDef());
4106 yyextra->foldStack.clear();
4107 yyextra->insideSpecialComment = false;
4108 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
4109 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
4110 yyextra->curlyCount = 0;
4111 yyextra->bodyCurlyCount = 0;
4112 yyextra->bracketCount = 0;
4113 yyextra->sharpCount = 0;
4114 yyextra->insideTemplate = FALSE;
4115 yyextra->theCallContext.clear();
4116 while (!yyextra->scopeStack.empty()) yyextra->scopeStack.pop();
4117 yyextra->scopeName = scopeName;
4118 DBG_CTX((stderr,"parseCCode %s\n",qPrint(scopeName)));
4119 yyextra->exampleBlock = options.isExample();
4120 yyextra->exampleName = options.exampleName();
4121 yyextra->sourceFileDef = options.fileDef();
4122 yyextra->lineNumbers = options.fileDef() && options.showLineNumbers();
4123 if (options.fileDef()==nullptr)
4124 {
4125 // create a dummy filedef for the example
4126 yyextra->exampleFileDef = createFileDef(QCString(),(!options.exampleName().isEmpty()?options.exampleName():"generated"));
4127 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
4128 }
4129 yyextra->lang = lang;
4130 yyextra->insideObjC = lang==SrcLangExt::ObjC;
4131 if (yyextra->sourceFileDef)
4132 {
4133 setCurrentDoc(yyscanner,"l00001");
4134 }
4135 yyextra->currentDefinition = options.searchCtx() ? options.searchCtx() : getResolvedNamespace(scopeName);
4136 yyextra->currentMemberDef = nullptr;
4137 yyextra->searchingForBody = options.isExample();
4138 yyextra->insideBody = FALSE;
4139 yyextra->bracketCount = 0;
4140 if (!yyextra->exampleName.isEmpty())
4141 {
4142 yyextra->exampleFile = convertNameToFile(yyextra->exampleName+"-example",FALSE,TRUE);
4143 DBG_CTX((stderr,"yyextra->exampleFile=%s\n",qPrint(yyextra->exampleFile)));
4144 }
4145 yyextra->includeCodeFragment = options.inlineFragment();
4146 DBG_CTX((stderr,"** exBlock=%d exName=%s include=%d\n",options.isExample(),qPrint(options.exampleName()),options.inlineFragment()));
4147 if (!yyextra->insideCodeLine)
4148 {
4149 startCodeLine(yyscanner);
4150 }
4151 yyextra->type.clear();
4152 yyextra->name.clear();
4153 yyextra->args.clear();
4154 yyextra->parmName.clear();
4155 yyextra->parmType.clear();
4156 if (options.memberDef()) setParameterList(yyscanner,options.memberDef());
4157 BEGIN( Body );
4158 codeYYlex(yyscanner);
4159 yyextra->lexInit=TRUE;
4160 if (yyextra->insideCodeLine)
4161 {
4162 endCodeLine(yyscanner);
4163 }
4164 if (Config_getBool(HTML_CODE_FOLDING))
4165 {
4166 while (!yyextra->foldStack.empty())
4167 {
4168 yyextra->code->endFold();
4169 yyextra->foldStack.pop_back();
4170 }
4171 }
4172 if (yyextra->exampleFileDef)
4173 {
4174 // delete the temporary file definition used for this example
4175 yyextra->exampleFileDef.reset();
4176 yyextra->sourceFileDef=nullptr;
4177 }
4178 // write the tooltips
4179 yyextra->tooltipManager.writeTooltips(od);
4180}
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:2478
#define DBG_CTX(x)
Definition code.l:73
static void startCodeLine(yyscan_t yyscanner)
Definition code.l:2409
static int countLines(yyscan_t yyscanner)
Definition code.l:3462
yyguts_t * yyscan_t
Definition code.l:24
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
Definition code.l:2277
static void setParameterList(yyscan_t yyscanner, const MemberDef *md)
Definition code.l:2623
#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:268
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:3446

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 4056 of file code.l.

4057{
4058 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4059 DBG_CTX((stderr,"***CodeParser::reset()\n"));
4060 yyextra->theVarContext.clear();
4061 while (!yyextra->scopeNameLengthStack.empty()) yyextra->scopeNameLengthStack.pop_back();
4062 yyextra->codeClassMap.clear();
4063 yyextra->curClassBases.clear();
4064 yyextra->anchorCount = 0;
4065 yyextra->insideCodeLine = false;
4066}

References p.

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4068 of file code.l.

4069{
4070 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4071 yyextra->insideCodeLine = inp;
4072}

References p.

Member Data Documentation

◆ p

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

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