@@ -508,29 +508,33 @@ sub Q {
508508}
509509
510510
511- # fetch_para(): private helper method for process_file ().
511+ # fetch_para(): private helper method for Node::cpp_scope::parse ().
512512#
513- # Read in all the lines associated with the next XSUB, or associated with
514- # the next contiguous block of file-scoped XS or CPP directives.
513+ # Read in all the lines associated with the next XSUB, BOOT or TYPEMAP,
514+ # or associated with the next contiguous block of file-scoped XS or
515+ # C-preprocessor directives. The caller relies on the paragraph
516+ # demarcation to indicate the end of the XSUB, TYPEMAP or BOOT. For other
517+ # types of line, it doesn't matter how they are split.
515518#
516- # More precisely, read lines (and their line numbers) up to (but not
519+ # More precisely, it reads lines (and their line numbers) up to (but not
517520# including) the start of the next XSUB or similar, into:
518521#
519522# @{ $self->{line} }
520523# @{ $self->{line_no} }
521524#
522- # It assumes that $self->{lastline} contains the next line to process,
523- # and that further lines can be read from $self->{in_fh} as necessary.
525+ # It skips lines which contain POD or XS comments.
526+ #
527+ # It assumes that, on entry, $self->{lastline} contains the next line to
528+ # process, and that further lines can be read from $self->{in_fh} as
529+ # necessary. On return, it leaves the first unprocessed line in
530+ # $self->{lastline}: typically the first line of the next XSUB. At EOF,
531+ # lastline will be left undef and fetch_para() returns false.
524532#
525533# Multiple lines which are read in that end in '\' are concatenated
526534# together into a single line, whose line number is set to
527535# their first line. The two characters '\' and '\n' are kept in the
528536# concatenated string.
529537#
530- # On return, it leaves the first unprocessed line in $self->{lastline}:
531- # typically the first line of the next XSUB. At EOF, lastline will be
532- # left undef.
533- #
534538# In general, it stops just before the first line which matches /^\S/ and
535539# which was preceded by a blank line. This line is often the start of the
536540# next XSUB (but there is no guarantee of that).
@@ -540,9 +544,9 @@ sub Q {
540544# | ....
541545# | stuff
542546# | [blank line]
543- # |PROTOTYPES: ENABLED
547+ # |PROTOTYPES: ENABLE
544548# |#define FOO 1
545- # |SCOPE: ENABLE
549+ # |PHASER DISCOMBOBULARISE
546550# |#define BAR 1
547551# | [blank line]
548552# |int
@@ -560,42 +564,40 @@ sub Q {
560564# keywords, and just blindly reads in lines until it finds a suitable
561565# place to break. It generally relies on the caller to handle most of the
562566# syntax and semantics and error reporting. For example, the block of four
563- # lines above from 'PROTOTYPES' onwards isn't valid XS, but is blindly
567+ # lines above from 'PROTOTYPES: ' onwards isn't valid XS, but is blindly
564568# returned by fetch_para().
565569#
566570# It often returns zero lines - the caller will have to handle this.
567571#
568- # There are a few exceptions where certain lines starting in column 1
569- # *are* interpreted by this function (and conversely where /\\$/ *isn't*
570- # processed):
572+ # The following items are handled specially by fetch_para().
571573#
572574# POD: Discard all lines between /^='/../^=cut/, then continue.
573575#
574- # MODULE: If this appears as the first line, it is processed and
575- # discarded, then line reading continues.
576- #
577- # TYPEMAP: Process a 'heredoc' typemap, discard all processed lines,
578- # then continue.
576+ # #comment Discard any line starting with /^\s*#/ which doesn't look
577+ # like a C preprocessor directive,
579578#
580- # /^\s*#/ Discard such lines unless they look like a CPP directive,
581- # on the assumption that they are code comments. Then, in
582- # particular:
579+ # TYPEDEF: Return the typemap 'heredoc' lines as a paragraph, but with
580+ # the final line (e.g. "EOF") missing. Line continuations,
581+ # i.e. '\' aren't processed.
583582#
584- # #if etc: For anything which is part of a CPP conditional: if it
585- # is external to the current chunk of code (e.g. an #endif
586- # which isn't matched by an earlier #if/ifdef/ifndef within
587- # the current chunk) then processing stops before that line.
583+ # BOOT: BOOT is NOT handled specially; the normal rules for ending
584+ # a paragraph will determine where the BOOT code ends.
588585#
589- # Nested if/elsif/else's etc within the chunk are passed
590- # through and processing continues. An #if/ifdef/ifdef on the
591- # first line is treated as external and is returned as a
592- # single line.
586+ # #if etc: C preprocessor conditional directives are analysed to
587+ # determine whether they are internal or external to the
588+ # current paragraph. This allows XSUBs and similar to be
589+ # closely cuddled by #if/#endif etc without needing to be
590+ # separated by a blank line. Typically, any such directives
591+ # immediately preceding an XSUB will be returned as one-line
592+ # paragraphs.
593593#
594- # It is assumed the caller will handle any processing or
595- # nesting of external conditionals.
594+ # Note that this CPP-line analysis is completely independent
595+ # of a similar analysis done in Node::cpp_scope::parse(),
596+ # which is concerned with splitting the tree into separate
597+ # sections where multiple XSUBs with the same name can appear.
596598#
597599# CPP directives (like #define) which aren't concerned with
598- # conditions are just passed through.
600+ # conditions are just passed through without any analysis .
599601#
600602# It removes any trailing blank lines from the list of returned lines.
601603
0 commit comments