++ed by:
Jean-Damien Durand

NAME

MarpaX::Languages::C::AST::Scope - Scope management when translating a C source to an AST

VERSION

version 0.29

SYNOPSIS

    use strict;
    use warnings FATAL => 'all';
    use MarpaX::Languages::C::AST::Scope;

    my $cAstScopeObject = MarpaX::Languages::C::AST::Scope->new();
    $cAstScopeObject->parseEnterScope();
    $cAstScopeObject->parseEnterTypedef("myTypedef");
    $cAstScopeObject->parseEnterEnum("myEnum");
    $cAstScopeObject->parseObscureTypedef("myVariable");
    foreach (qw/myTypedef myEnum myVariable/) {
      if ($cAstScopeObject->parseIsTypedef($_)) {
        print "\"$_\" is a typedef\n";
      } elsif ($cAstScopeObject->parseIsEnum($_)) {
        print "\"$_\" is an enum\n";
      }
    }
    $cAstScopeObject->parseExitScope();

DESCRIPTION

This modules manages the scopes when translation a C source into an AST tree. This module started after reading the article:

Resolving Typedefs in a Multipass C Compiler from Journal of C Languages Translation, Volume 2, Number 4, written by W.M. McKeeman. A online version may be accessed at http://www.cs.dartmouth.edu/~mckeeman/references/JCLT/ResolvingTypedefsInAMultipassCCompiler.pdf.

Please note that this module is logging via Log::Any.

SUBROUTINES/METHODS

new

Instance a new object. Takes no parameter.

typedefPerScope($self)

Returns the list of known typedefs per scope. At the end of processing a source code, only scope 0 still exist. The output is a reference to an array, file-level scope being at index 0. At each indice, there is a reference to a hash with typedef name as a key, value is useless.

enumAnyScope($self)

Returns the list of known enums. Enums has no scope level: as soon as the parser sees an enum, it available at any level. The output is a reference to a hash with enumeration name as a key, value is useless.

parseEnterScope($self)

Say we enter a scope.

parseDelay($self, [$value])

Returns/Set current delay flag.

parseScopeLevel($self)

Returns current scope level, starting at number 0.

parseEnterScopeCallback($self, $ref, @args)

Callback method when entering a scope.

parseExitScopeCallback($self, $ref, @args)

Callback method when leaving a scope (not the delayed operation, the real leave).

parseExitScope($self, [$now])

Say we want to leave current scope. The operation is delayed unless $now flag is true.

parseReenterScope($self)

Reenter previous scope.

condExitScope($self)

Leave current scope if delay flag is set and not yet done.

doExitScope($self)

Leave current scope.

parseEnterTypedef($self, $token, $data)

Declare a new typedef with name $token, that will be visible until current scope is left. $data is an optional user-data area, defaulting to 1 if not specified.

parseEnterEnum($self, $token)

Declare a new enum with name $token, that will be visible at any scope from now on. $data is an optional user-data area, defaulting to 1 if not specified.

parseObscureTypedef($self, $token)

Obscures a typedef named $token.

parseIsTypedef($self, $token)

Return a true value if $token is a typedef.

parseIsEnum($self, $token)

Return a true value if $token is an enum.

AUTHOR

Jean-Damien Durand <jeandamiendurand@free.fr>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Jean-Damien Durand.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.




Hosting generously
sponsored by Bytemark