Author Topic: parser test rev 7157 error?  (Read 24506 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: parser test rev 7157 error?
« Reply #30 on: May 30, 2011, 07:09:07 am »
@morten and loaden:
return back to my example code:
http://forums.codeblocks.org/index.php/topic,14733.msg98909.html#msg98909

I also enabled the log:

In the file parserdummy.cpp, line 102
Code

    ParserTest pt;
    pt.Clear();
    ParserTrace(_T("-----------I-n-t-e-r-i-m--L-o-g-----------"));
    pt.Start(filename);
    // TODO: The following lines cause a crash in
    ParserTrace(_T("--------------T-r-e-e--L-o-g--------------"));
    pt.PrintTree();
    ParserTrace(_T("--------------L-i-s-t--L-o-g--------------"));
    pt.PrintList();

it works fine.
But you can see the log:
Quote
--------------M-a-i-n--L-o-g--------------

000001. ParserDummy() : Parser() : Instantiation of Parser object.
000002. InitTokenizer() : m_Filename='test.h', m_FileSize=60.
000003. Init() : m_Filename='test.h'
000004. Parse() : Parsing 'test.h'
000005. DoParse() : Loop:m_Str='', token='int'
000006. DoParse() : Loop:m_Str='int ', token='aaaaa'
000007. DoAddToken() : Created token='aaaaa', file_idx=1, line=2, ticket=
000008. GetActualTokenType() : Searching within m_Str='int'
000009. GetActualTokenType() : Compensated m_Str='int'
000010. GetActualTokenType() : Found 'int'
000011. DoAddToken() : Prepending ''
000012. DoAddToken() : Added/updated token 'aaaaa' (0), kind 'variable', type 'int', actual 'int'. Parent is  (-1)
000013. DoParse() : Loop:m_Str='', token='float'
000014. DoParse() : Loop:m_Str='float ', token='bbbbb'
000015. DoAddToken() : Created token='bbbbb', file_idx=1, line=3, ticket=
000016. GetActualTokenType() : Searching within m_Str='float'
000017. GetActualTokenType() : Compensated m_Str='float'
000018. GetActualTokenType() : Found 'float'
000019. DoAddToken() : Prepending ''
000020. DoAddToken() : Added/updated token 'bbbbb' (1), kind 'variable', type 'float', actual 'float'. Parent is  (-1)
000021. DoParse() : Loop:m_Str='', token='#'
000022. HandleIncludes() : Found include file 'a.h'
000023. ParserDummy() : GetFullFileName() : Querying full file name for source 'test.h', target 'a.h' (isGlobal=true).
000024. HandleIncludes() : Adding include file 'a.h'
000025. ParserDummy() : DoParseFile() : Parse file request for file name 'a.h' (isGlobal=true)
000026. ParserDummy() : Parse() : Parsing file 'a.h' (isLocal=false).
000027. ParserDummy() : Parse() : Creating new parser thread for 'a.h'
000028. -----------I-n-t-e-r-i-m--L-o-g-----------
000029. ParserDummy() : Parser() : Instantiation of Parser object.
000030. InitTokenizer() : m_Filename='a.h', m_FileSize=29.
000031. Init() : m_Filename='a.h'
000032. Parse() : Parsing 'a.h'
000033. DoParse() : Loop:m_Str='', token='int'
000034. DoParse() : Loop:m_Str='int ', token='in_a_h'
000035. DoAddToken() : Created token='in_a_h', file_idx=1, line=1, ticket=
000036. GetActualTokenType() : Searching within m_Str='int'
000037. GetActualTokenType() : Compensated m_Str='int'
000038. GetActualTokenType() : Found 'int'
000039. DoAddToken() : Prepending ''
000040. DoAddToken() : Added/updated token 'in_a_h' (0), kind 'variable', type 'int', actual 'int'. Parent is  (-1)
000041. DoParse() : Loop:m_Str='', token='#'
000042. HandleIncludes() : Found include file 'b.h'
000043. ParserDummy() : GetFullFileName() : Querying full file name for source 'a.h', target 'b.h' (isGlobal=true).
000044. HandleIncludes() : Adding include file 'b.h'
000045. ParserDummy() : DoParseFile() : Parse file request for file name 'b.h' (isGlobal=true)
000046. ParserDummy() : Parse() : Parsing file 'b.h' (isLocal=false).
000047. ParserDummy() : Parse() : Creating new parser thread for 'b.h'
000048. -----------I-n-t-e-r-i-m--L-o-g-----------
000049. ParserDummy() : Parser() : Instantiation of Parser object.
000050. InitTokenizer() : m_Filename='b.h', m_FileSize=13.
000051. Init() : m_Filename='b.h'
000052. Parse() : Parsing 'b.h'
000053. DoParse() : Loop:m_Str='', token='int'
000054. DoParse() : Loop:m_Str='int ', token='in_b_h'
000055. DoAddToken() : Created token='in_b_h', file_idx=1, line=1, ticket=
000056. GetActualTokenType() : Searching within m_Str='int'
000057. GetActualTokenType() : Compensated m_Str='int'
000058. GetActualTokenType() : Found 'int'
000059. DoAddToken() : Prepending ''
000060. DoAddToken() : Added/updated token 'in_b_h' (0), kind 'variable', type 'int', actual 'int'. Parent is  (-1)
000061. ParserDummy() : ~Parser() : Destruction of Parser object.
000062. --------------T-r-e-e--L-o-g--------------
000063. int in_b_h   [1,0]
000064. --------------L-i-s-t--L-o-g--------------
000065. variable int in_b_h   [1,0]
000066. ParserDummy() : ~Parser() : Destruction of Parser object.
000067. --------------T-r-e-e--L-o-g--------------
000068. int in_a_h   [1,0]
000069. --------------L-i-s-t--L-o-g--------------
000070. variable int in_a_h   [1,0]
000071. DoParse() : Loop:m_Str='', token='#'
000072. HandleIncludes() : Found include file 'b.h'
000073. ParserDummy() : GetFullFileName() : Querying full file name for source 'test.h', target 'b.h' (isGlobal=true).
000074. HandleIncludes() : Adding include file 'b.h'
000075. ParserDummy() : DoParseFile() : Parse file request for file name 'b.h' (isGlobal=true)
000076. ParserDummy() : Parse() : Parsing file 'b.h' (isLocal=false).
000077. ParserDummy() : Parse() : File 'b.h' has already been parsed
000078. ParserDummy() : ~Parser() : Destruction of Parser object.


--------------T-r-e-e--L-o-g--------------

000079. int aaaaa   [2,0]
000080. float bbbbb   [3,0]


--------------L-i-s-t--L-o-g--------------

000081. variable int aaaaa   [2,0]
000082. variable float bbbbb   [3,0]


Which means: the whole parsing stage will have Three TokensTree instants to be allocated and then destroyed. This is not necessory, I think One TokensTree is enough.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.