Package yagdoc :: Module scanner :: Class Scanner
[show private | hide private]
[frames | no frames]

Type Scanner

object --+
         |
        Scanner


Declaration scanner.

Attributes are only available after scan.
Method Summary
  __init__(self)
  add_declaration(self, decl)
Add declaration into the declaration dictionary, attempting to resolve name clashes.
  commit(self)
Process and clear rectification queues.
  scan(self, parser, macros)
Scan parse tree and macro list, build declaration list.
  scan_declaration(self, statement)
Scan one declaration (top-level parse tree item).
  scan_macro(self, macro)
Scan one macro definition declaration (from tokenizer.Tokenizer).
  _fail(self, exception, line, detail)
  _warn_duplicates(self)
Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__
    Tree rectifiers
  split_multifields(self, decl)
Split 'struct_multifield' parse tree items to individual fields.
  split_multivariable(self, decl)
Split 'variable_def' parse tree items declaring multiple variables to individual declarations.
  merge_g_typedef(self, decl)
Merge a typedef with its associated underscorized struct declaration.
  remove_private(self, decl)
Remove private declarations (starting with an underscore).

Instance Variable Summary
dict of Declaration declarations: Dictionary with declarations, indexed by symbol name.
  enum_map: Dictionary mapping enum values to top-level declarations.
list of {ScannerError} errors: Errors encountered.
str source: Equal to parser.Parser.source instance variable.
list of str type_funcs: Names of GType get-type functions.

Method Details

split_multifields(self, decl)

Split 'struct_multifield' parse tree items to individual fields.

Parser produces struct bodies as a list of 'struct_multifield' tokens that are possibly multi-fields and even contain all preceding directives, i.e. the declaration:
   struct {
       /*< public >*/
       int a, *b, c[3];
   }
gives raise to a single 'struct_multifield'. This rectifier splits it into the equivalent of:
   struct {
       /*< public >*/
       int a;
       int *b;
       int c[3];
   }

where each line forms its own item (one 'directive' and three 'struct_field's).

Subtrees, corresponding to e.g. the field type, are not deep-copied, just referenced.
Parameters:
decl - Declaration to rectify (non-conforming declarations are kept intact).
           (type=Declaration)

Note: This rectifier is essential, further processing may fail if not applied.

split_multivariable(self, decl)

Split 'variable_def' parse tree items declaring multiple variables to individual declarations.

Parser produces 'variable_def' declarations that can declare multiple variables at once if the header file does so, i.e. the declaration:
   extern int a, *b, c[3];
gives raise to a single 'variable_def'. This rectifier splits it into the equivalent of:
   extern int a;
   extern int *b;
   extern int c[3];

where each line forms its own top-level 'variable_def'.

Subtrees, corresponding to e.g. the field type, are not deep-copied, just referenced. Subtrees 'variable' are eliminated by merging their contents one level up.
Parameters:
decl - Declaration to rectify (non-conforming declarations are kept intact).
           (type=Declaration)

Note: This rectifier is essential, further processing may fail if not applied.

merge_g_typedef(self, decl)

Merge a typedef with its associated underscorized struct declaration.

Type definition and struct definitions:
   typedef struct _Whatever Whatever;
   struct _Whatever {
       ...
   };
are merged to:
   typedef struct Whatever {
       ...
   };

and the underscorized struct definition is removed. The name of the struct and type must match (i.e. struct name must be type name with an underscore prepended).

Subtrees of the two declarations are just reshuffled, not deep-copied, to form the merged declaration.
Parameters:
decl - Declaration to rectify (non-conforming declarations are kept intact).
           (type=Declaration)

Note: This rectifier is non-essential, it merely implements a coding convention.

remove_private(self, decl)

Remove private declarations (starting with an underscore).

To be applied after merge_g_typedef which makes use of declarations starting with an underscore.
Parameters:
decl - Declaration to check for removal (non-conforming declarations are kept intact).
           (type=Declaration)

Note: This rectifier is non-essential, it merely implements a coding convention.

add_declaration(self, decl)

Add declaration into the declaration dictionary, attempting to resolve name clashes.

If a declaration of the same name is already known Declaration.supersedes is used to determine the winner that will appear in our declaration dictionary. If none takes precedence over the another, the first declared wins but the second is saved in self.duplicates and will likely cause a warning later.
Parameters:
decl - Declaration to add.
           (type=Declaration)

commit(self)

Process and clear rectification queues.

Removal queue is processed before addition, therefore it is possible to replace a declaration with a completely different by placing it into both queues.

Is also goes through duplicates and tries to remove declarations supersedes by others.

scan(self, parser, macros)

Scan parse tree and macro list, build declaration list.
Parameters:
parser - Parser with parse tree to scan.
           (type=parser.Parser)
macros - Macro list from tokenizer.
           (type=list of tokenizer.Macro)

scan_declaration(self, statement)

Scan one declaration (top-level parse tree item).

scan_macro(self, macro)

Scan one macro definition declaration (from tokenizer.Tokenizer).

Instance Variable Details

declarations

Dictionary with declarations, indexed by symbol name.
Type:
dict of Declaration

enum_map

Dictionary mapping enum values to top-level declarations.

errors

Errors encountered.
Type:
list of {ScannerError}

source

Equal to parser.Parser.source instance variable.
Type:
str

type_funcs

Names of GType get-type functions.
Type:
list of str

Generated by Epydoc 2.1 on Fri Oct 5 00:36:53 2007 http://epydoc.sf.net