MarpaX::Languages::C::AST::Scope - Scope management when translating a C source to an AST
version 0.47
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();
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.
Instance a new object. Takes no parameter.
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.
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.
Say we enter a scope.
Returns/Set delay flag of the current (i.e. last) scope.
Returns current scope level, starting at number 0.
Callback method when entering a scope.
Callback method when leaving a scope (not the delayed operation, the real leave).
Say we want to leave current scope. The operation is delayed unless $now flag is true.
Reenter previous scope.
Leave current scope if delay flag is set and not yet done.
Leave current scope.
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.
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.
Obscures a typedef named $token.
Return a true value if $token is a typedef.
Return a true value if $token is an enum.
Jean-Damien Durand <jeandamiendurand@free.fr>
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.
To install MarpaX::Languages::C::AST, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MarpaX::Languages::C::AST
CPAN shell
perl -MCPAN -e shell install MarpaX::Languages::C::AST
For more information on module installation, please visit the detailed CPAN module installation guide.