Announcement

Collapse
No announcement yet.

Unused code 4

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unused code 4

    This is the type of code I use to strip comments in basic that
    can have quoted text that has the character " ' " in it. I generally
    inline code of this type to save stack overhead but the concept
    is simple enough, just test which is the furthest right, if its a
    quote, the character is in the string, if its not, its a comment.

    Regards,

    [email protected]

    Code:
                  LOCAL qvar as LONG
                  LOCAL cvar as LONG
                  LOCAL src  as LONG
                  LOCAL lnth as LONG
      
                  a$ = "test$ = "+chr$(34)+" 'Basic comments' "+chr$(34)+"   ' comment"
      
                  lnth = len(a$)
                  src = StrPtr(a$)
      
                ' =========================
                  ! mov esi, src
                  ! xor ecx, ecx
                  ! xor edx, edx
                lblx:
                  ! mov al, [esi]
                  ! inc esi
                  ! inc ecx
                  ! cmp al, 34    ; quote
                  ! jne nxtlblx
                  ! mov edx, ecx
                nxtlblx:
                  ! cmp ecx, lnth
                  ! jne lblx
      
                  ! mov qvar, edx
                ' =========================
                  ! mov esi, src
                  ! xor ecx, ecx
                  ! xor edx, edx
                lbly:
                  ! mov al, [esi]
                  ! inc esi
                  ! inc ecx
                  ! cmp al, "'"    ; comment
                  ! jne nxtlbly
                  ! mov edx, ecx
                nxtlbly:
                  ! cmp ecx, lnth
                  ! jne lbly
                  ! mov cvar, edx
                ' =========================
      
                ' ==================================================
                ' if last comment position is > last quote position
                ' then it is a comment and not a part of a string
                ' ==================================================
                  If cvar > qvar Then
                    a$ = rtrim$(left$(a$,cvar-1))
                  End If
      
                  MessageBox hWin,ByCopy a$,ByCopy str$(qvar)+" "+str$(cvar), _
                             %MB_OK or %MB_ICONINFORMATION
    ------------------
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

  • #2
    Thanks Steve. I'm saving it for future optimization of code - I'm sure
    it will come in handy one day (your tips always seem to do, one way or
    another..

    David, unless an #IF meta statement has been used to exclude code, all
    code in include files are compiled, so yes - you have "bloated" your
    final compilation with several KB's. Typical sample is COMMCTRL.INC,
    where we can exclude/include the controls we need.

    Optimal thing to do is to copy and paste the needed declarations and
    code only. I know some people do that, but I usually don't care,
    because we are usually talking about a few KB's extra here, if even
    that. It is interesting to include win32api.inc in check though.
    Think more code than we realize becomes included there..

    Eddy, it should handle underscores in function names properly. Probably
    something else. Care to post a small example of how it looks? The
    declaration is enough for me to test it here and find out what's wrong.

    This prog is still a baby and needs a lot more testing, which is why it
    hasn't been "officially" released yet. It works well enough for me
    though and probably can help others, but as always with tools like these,
    take extreme care before you delete anything - uncomment and test first!


    ------------------

    Comment


    • #3
      originally posted by borje hagsten:
      eddy, it should handle underscores in function names properly. probably
      something else. care to post a small example of how it looks? the
      declaration is enough for me to test it here and find out what's wrong.
      borje,
      i think you misunderstood me.
      it's not the underscores that cause the error, it's the single quotes (') in the
      checkbox text that is the problem. pbcodec thinks that it is the beginning of a comment while
      it is actually text...
      Code:
      declare callback function cbf_st_funnycheck
      ...
      control add checkbox , hsettings&,  %st_funnycheck, "enable 'smart remarks'",10, 190, 100, 15, call cbf_st_funnycheck
      ...
      here you can find my complete code (zipped i'm afraid..): http://www.powerbasic.com/support/pb...ad.php?t=23072
      kind regards
      eddy

      ------------------
      [email protected]
      Eddy

      Comment


      • #4
        Borje, how does it handle "nested" DIM statements with embedded variables and arrays?

        Try it with this (exagerated/non-compilable) DIM statement:
        Code:
        DIM lance3(1:2,2:3,3:4,abc$(1):abc%(2)) AS GLOBAL ASCIZ * 10, a&(1:B!(1)) AS STATIC LONG, xx&, yy%(10)
        I'm working on it... nearly done (with luck!)

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Okay, found and fixed small bug - had forgot to strip away eventual
          trailing type declaration characters (%&$, etc.) in sub/function names.

          Now fixed and new file uploaded: http://www.tolken99.com/pb/pbcodec.zip

          Hm, have to check that out tonight, Eddy. I probably have forgot to
          consider it. Lance, kind of extreme, but I get the point. Must handle
          it too. I'll be back..

          One thing to remember with these kinds of tools - they can only act
          as guidance. There's so many ways to do things, I don't think one
          ever can cover them all. Sometimes even a compiler can be fooled, so..


          ------------------

          Comment


          • #6
            Borje,
            Not sure what the problem is. Maybe because most of my functions are
            declared on multi-lines??

            James

            Code:
            FUNCTION _
              MyFunc ( _
                BYVAL abc    AS LONG, _
                      def    AS STRING _
              )AS LONG
            
            
            --- TOTAL REFERENCE COUNTS ---
            (format is: Count, Name, [declared in file])
            
            FUNCTIONS:
              -1  =                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
               2  fReadFromClipboard                 [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
              -1  _                                  [RDT80126.BAS]
            ------------------

            Comment


            • #7
              Eddy, problem with single quotes within double has been solved. Was
              just a matter of moving the part where I STRDELETE text within DQ's
              up before it cuts uncommented part off in line extraction code. New
              file uploaded..

              Lance, if it won't even compile, I definitely can't cover it. Enough
              many ways to write code as it is. Just look at the latest problem, with
              underscores right after FUNCTION _. Will have a closer look at it, though.

              JC, I'll have a look at this later on tonight. Interesting to see all the
              ways one can write code..


              ------------------

              Comment


              • #8
                Would it be difficult, or useful, to list DECLARED, but missing or
                deleted, SUBs and FUNCTIONS?

                Both Checkit and PBCodeC are already in my tool box. Really neat
                utilities.

                Bruce Warner

                ------------------

                Comment


                • #9
                  JC, problem fixed - new file uploaded that considers wrapped function
                  names, like in your example. Still a bit left to do there, because it
                  won't recognize ev. EXPORT statement in such cases, but when I get
                  more time, I'll fix that part too.

                  Bruce, I actually have code to that here already. Hm, didn't I post
                  sample to source code once? Probably need to be adjusted, but I'll
                  see what I can do later on.


                  ------------------

                  Comment


                  • #10
                    Would it be difficult, or useful, to list DECLARED, but missing or
                    deleted, SUBs and FUNCTIONS?
                    Only if they are not DECLAREd with a "LIB" statement....

                    But if there ain't no LIB statement, it don';t compile anyway...

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Michael, err, um... No. It will still compile if you declare a function (without a LIB clause) and have no such sub/function in your code.

                      That is exactly how you declare API functions that will be run-time linked (LoadLibrary, GetProcAddress, etc). GetProcAddress is called with a string parameter, so a code checker would not see that particular reference unless an actual CALL DWORD is used.

                      ...try it for yourself!


                      Borje, I realize that my example DIM was drastic, but nested DIM's are possible, and could even include UDT members as dimension parameters, etc.

                      The DIM statement is so flexible that parsing it perfectly is actually quite difficult!

                      I really have to take my hat of to Bob and his team for the parsing engine in these compilers!

                      ------------------
                      Lance
                      PowerBASIC Support
                      mailto:[email protected][email protected]</A>
                      Lance
                      mailto:[email protected]

                      Comment


                      • #12
                        New file uploaded. Did some cosmetic changes to report, to make it
                        cleaner and also fixed so the prog can handle wrapped sub/function
                        names properly, with respect to eventual export statements (ok now, JC).

                        Will look at nested declares later on, but have to leave this for now,
                        because I have to make a living too (they say..)

                        Hm, yes Lance - and considering PB's parser is written in highly
                        optimized asm, I feel like lifting my whole head off in respect
                        for their brilliant work..


                        ------------------

                        Comment


                        • #13

                          CheckIt Updated (07/26/2001)

                          Latest Additions and fixes are:

                          * Added Enhance Reporting to Include Reference Counts

                          * Fixed DIM xxx AS GLOBAL yyy bug

                          * Added Optional Report File Output

                          * Optimized Processing back to 2 passes instead of 3 and it still finds
                          Globals that are declared in INCLUDE files just fine.

                          CheckIt.Zip is at http://www.summitcn.com/downloads/checkit.zip


                          Scott


                          ------------------
                          Scott Slater
                          Summit Computer Networks, Inc.
                          www.summitcn.com

                          Comment


                          • #14
                            Nice interface, Scott - I like it. An idea I will use in my version later
                            on is possibility to mark which includes to scan. Maybe we don't want to
                            know about win32api.inc and some others (they take a lot of time to scan
                            and we probably use them "as is" anyway). I've excluded those automatically
                            now, but will make it optional later on.

                            And, a couple of tips. I recompiled, using the latest COMMCTRL excludes
                            and size went down from 67 to 55 KB. Also found a small thing: on line 382
                            you should use %PBM_SETRANGE, not TBM.. (TBM_.. is for trackbar)

                            Here is latest excludes as I used them, but if you haven't done it before,
                            I suggest you download the latest include files from the file section.
                            Code:
                            %NOANIMATE       = 1
                            %NOBUTTON        = 1
                            %NOCOMBO         = 1
                            %NODATETIMEPICK  = 1
                            %NODRAGLIST      = 1
                            %NOEDIT          = 1
                            %NOFLATSBAPIS    = 1
                            %NOHEADER        = 1
                            %NOHOTKEY        = 1
                            %NOIMAGELIST     = 1
                            %NOIPADDRESS     = 1
                            %NOLIST          = 1
                            %NOLISTVIEW      = 1
                            %NOMONTHCAL      = 1
                            %NONATIVEFONTCTL = 1
                            %NOPAGESCROLLER  = 1
                            '%NOPROGRESS      = 1
                            %NOREBAR         = 1
                            %NOSTATUSBAR     = 1
                            %NOTABCONTROL    = 1
                            %NOTOOLBAR       = 1
                            %NOTOOLTIPS      = 1
                            %NOTRACKBAR      = 1
                            %NOTREEVIEW      = 1
                            %NOUPDOWN        = 1

                            ------------------

                            Comment


                            • #15
                              Wow, that did shrink the code a good bit. Thanks for the advice.



                              Scott


                              ------------------
                              Scott Slater
                              Summit Computer Networks, Inc.
                              www.summitcn.com

                              Comment


                              • #16
                                Couldn't keep my hands off it. Found another silly thing in a couple of
                                files - duplicate names for arrays and variables. Following is allowed,
                                but may cause a lot of confusion in code so I added check for it and
                                additional notice to check them out carefully to report:
                                Code:
                                GLOBAL abc   AS LONG
                                GLOBAL abc() AS LONG  '(or String, Single  - anything works..)
                                Proper way would be to consider them by the way they have been declared,
                                but that'll will have to wait. Have not taken care of similar things with
                                local declares yet - will do that later on.

                                New file uploaded to http://www.tolken99.com/pb/pbcodec.zip


                                ------------------

                                Comment


                                • #17
                                  New file uploaded again. Added scanning for "Declared but non-existing
                                  Subs/Function(s)" and "Existing but non-declared Subs/Functions". This
                                  works fine, until it encounters routines that has been declared but
                                  exist in a DLL. Will fix that later - still quite useful as it is.

                                  Also did some trimming. Speed is good now, almost PBcompiler speed.
                                  I get about 250-300 throusand lines/minute in a 266MHz machine here,
                                  so a million lines per minute in a GHz machine should be possible.

                                  Report is cleaned up and gives a lot of good info. As always with
                                  software of this type, take care. Use the report as guidance to look
                                  for unused variables and code.

                                  PBcodec does not handle conditional statements, yet, and no guaratees
                                  for absolute correctness, since there's so many ways to write code.
                                  It handles most things though and for me, it does a wonderful job of
                                  finding redundant variables and code..


                                  ------------------

                                  Comment


                                  • #18
                                    thread closed. please see http://www.powerbasic.com/support/pb...ead.php?t=4111


                                    ------------------
                                    lance
                                    powerbasic support
                                    mailto:[email protected][email protected]</a>
                                    Lance
                                    mailto:[email protected]

                                    Comment

                                    Working...
                                    X