Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
tracep.h
Go to the documentation of this file.
1 /* *************************************************************************************
2  Copyright (c) 2021, Lowell D. Thomas
3  All rights reserved.
4 
5  This file is part of APG Version 7.0.
6  APG Version 7.0 may be used under the terms of the BSD 2-Clause License.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 * *************************************************************************************/
34 
35 #ifndef LIB_TRACEP_H_
36 #define LIB_TRACEP_H_
37 
38 #ifdef APG_TRACE
39 
40 #include <stdio.h>
41 
42 // apgex handles display of header and footer explicitly
47 
50 #define TRACE_HEADER_APGEX 2
51 
54 #define TRACE_HEADER_TRACE 3
55 
60 typedef struct {
67  const opcode* spOpcode;
68 } trace_record;
69 
73 typedef struct{
84  abool bPppt;
86 } trace_config;
87 
91 typedef struct{
92  void* vpMem;
94  void* vpLog;
95  parser* spParserCtx;
96  char* cpFileName;
97  void* vpVecFileName;
98  FILE* spOut;
99  FILE* spOpenFile;
107  char* cpBuf;
111 } trace;
112 
116 void vTraceApgexSeparator(void* vpCtx, aint uiLastIndex);
118 void vTraceApgexType(void* vpCtx, aint uiType);
119 void vTraceApgexHeader(void* vpCtx);
120 void vTraceApgexFooter(void* vpCtx);
122 
127 void vTraceBegin(void* vpCtx);
129 void vTraceEnd(void* vpCtx);
130 void vTraceDown(void* vpCtx, const opcode* spOp, aint uiOffset);
131 void vTraceUp(void* vpCtx, const opcode* spOp, aint uiState, aint uiOffset, aint uiPhraseLength);
132 void vDisplayRecord(trace* spCtx, trace_record* spRec, abool bIsMatchedPppt);
133 void vDisplayHeader(trace* spCtx);
134 void vDisplaySeparator(trace* spCtx, aint uiLastIndex);
135 void vDisplayFooter(trace* spCtx);
136 void vSetDefaultConfig(trace* spTrace);
138 
139 #endif /* APG_TRACE */
140 
141 #endif /* LIB_TRACEP_H_ */
trace_config::bAllRules
abool bAllRules
If true, all rule nodes will be displayed.
Definition: tracep.h:81
vTraceApgexSeparator
void vTraceApgexSeparator(void *vpCtx, aint uiLastIndex)
Only called by apgex.
Definition: trace.c:225
trace::spParserCtx
parser * spParserCtx
Pointer back to the parent parser's context.
Definition: tracep.h:95
trace::iTraceDepthMax
int iTraceDepthMax
The maximum (possibly partial) traced node depth.
Definition: tracep.h:105
trace::spOut
FILE * spOut
Pointer to the open output file.
Definition: tracep.h:98
trace_record::uiThisRecord
aint uiThisRecord
The record index of the current record.
Definition: tracep.h:63
trace_record::uiPhraseLength
aint uiPhraseLength
The phrase length of a successful match.
Definition: tracep.h:65
trace_config
Configuration defining the subset of nodes to display information for.
Definition: tracep.h:73
vSetDefaultConfig
void vSetDefaultConfig(trace *spTrace)
Sets the default trace configuration on construction.
Definition: trace-config.c:56
trace_record::spOpcode
const opcode * spOpcode
Pointer to the opcode for the current node.
Definition: tracep.h:67
vDisplayFooter
void vDisplayFooter(trace *spCtx)
Display the trace footer.
Definition: trace-out.c:141
trace::spOpenFile
FILE * spOpenFile
Pointer to any other open file.
Definition: tracep.h:99
trace::uiBufSize
aint uiBufSize
Size of the scratch buffer.
Definition: tracep.h:109
trace_config::bpUdts
abool * bpUdts
An array of true/false indicators for each UDT in the SABNF grammar.
Definition: tracep.h:75
trace::uiThisRecord
aint uiThisRecord
Index of the current trace record.
Definition: tracep.h:101
trace_config::uiMaxRecords
aint uiMaxRecords
Maximun number of records to display.
Definition: tracep.h:80
trace::vpLookaroundStack
void * vpLookaroundStack
Pointer to a stack require to keep track of when tracing in look around mode.
Definition: tracep.h:100
trace_config::bpOps
abool * bpOps
An array of true/false indicators for each opcode in the SABNF grammar.
Definition: tracep.h:76
trace::sConfig
trace_config sConfig
Pointer to the trace configuration.
Definition: tracep.h:110
trace_record::uiState
aint uiState
The parser's state for this node (ID_ACTIVE, ID_MATCH, etc.)
Definition: tracep.h:66
trace::iTraceDepthMin
int iTraceDepthMin
The minimum (possibly partial) traced node depth.
Definition: tracep.h:106
vDisplayHeader
void vDisplayHeader(trace *spCtx)
Display the trace header.
Definition: trace-out.c:98
vTraceUp
void vTraceUp(void *vpCtx, const opcode *spOp, aint uiState, aint uiOffset, aint uiPhraseLength)
Called by the parser following upward traversal of a parse tree node.
Definition: trace.c:285
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
trace_config::uiOutputType
aint uiOutputType
Output type identifier (TRACE_ASCII or TRACE_HTML)
Definition: tracep.h:77
trace_record::iTraceDepth
int iTraceDepth
The partial parse tree depth (a subset possibly restricted by the configuration.)
Definition: tracep.h:62
vTraceApgexFooter
void vTraceApgexFooter(void *vpCtx)
Only called by apgex.
Definition: trace.c:211
trace_record::uiTreeDepth
aint uiTreeDepth
The actual parse tree depth.
Definition: tracep.h:61
trace::uiTreeDepth
aint uiTreeDepth
The current full parse tree depth.
Definition: tracep.h:102
vTraceBegin
void vTraceBegin(void *vpCtx)
Called by the parser to start the trace.
Definition: trace.c:237
vTraceDown
void vTraceDown(void *vpCtx, const opcode *spOp, aint uiOffset)
Called by the parser prior to downward traversal of a parse tree node.
Definition: trace.c:266
trace_config::bAllOps
abool bAllOps
If true, all UDT nodes will be displayed.
Definition: tracep.h:82
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
trace::vpMem
void * vpMem
Pointer to the memory context to use for all memory allocation.1.
Definition: tracep.h:92
vDisplaySeparator
void vDisplaySeparator(trace *spCtx, aint uiLastIndex)
Display a separator between trace outputs (apgex only)
Definition: trace-out.c:129
vTraceEnd
void vTraceEnd(void *vpCtx)
Called by the parser to end the trace.
Definition: trace.c:251
trace_config::uiHeaderType
aint uiHeaderType
Indicates whether the trace is being done by apgex.
Definition: tracep.h:78
vDisplayRecord
void vDisplayRecord(trace *spCtx, trace_record *spRec, abool bIsMatchedPppt)
Display one trace record.
Definition: trace-out.c:110
trace_record
The information recorded & displayed by the trace object for each node visited.
Definition: tracep.h:60
trace::cpFileName
char * cpFileName
Name of the file to display the trace records to.
Definition: tracep.h:96
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
trace_config::bpRules
abool * bpRules
An array of true/false indicators for each rule in the SABNF grammar.
Definition: tracep.h:74
trace::iTraceDepth
int iTraceDepth
The current (possibly partial) traced node depth.
Definition: tracep.h:104
vTraceApgexHeader
void vTraceApgexHeader(void *vpCtx)
Only called by apgex.
Definition: trace.c:199
trace::uiTreeDepthMax
aint uiTreeDepthMax
The maximum full parse tree depth achieved.
Definition: tracep.h:103
trace::vpVecFileName
void * vpVecFileName
Vector to allocate and re-allocate the memory for the file name.
Definition: tracep.h:97
trace
The trace object context. Maintains the trace object's state.
Definition: tracep.h:91
trace_config::uiFirstRecord
aint uiFirstRecord
Number of the first record to display.
Definition: tracep.h:79
trace_record::uiOffset
aint uiOffset
The offset into the input string for the first character of the sub-phrase being matched.
Definition: tracep.h:64
trace_config::bCountOnly
abool bCountOnly
If true, trace will only count the number of records that would have been displayed.
Definition: tracep.h:83
vTraceApgexType
void vTraceApgexType(void *vpCtx, aint uiType)
Called only by apgex. Sets the display type for apgex tracing.
Definition: trace-config.c:116
trace::vpLog
void * vpLog
Pointer to a message log object for reporting configuration errors.
Definition: tracep.h:94
trace::spException
exception * spException
Pointer to the exception to use to report fatal errors back to the parser's catch block.
Definition: tracep.h:93
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.