Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Detect undeclared attributes at compile time and complain about them.…
… Possible now that we register them with the compile timemeta-object. Also, pass any declared type along to the PAST::Var node, though it's not used yet.
  • Loading branch information
jnthn committed Apr 26, 2011
1 parent 1a79be7 commit eafc258
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/NQP/Actions.pm
Expand Up @@ -435,12 +435,32 @@ class NQP::Actions is HLL::Actions {
);
}
elsif $<twigil>[0] eq '!' {
# Construct PAST.
my $name := ~@name.pop;
$past := PAST::Var.new(
:name(~@name.pop), :scope('attribute'),
:name($name), :scope('attribute'),
:viviself( vivitype( $<sigil> ) ),
PAST::Var.new( :name('self') ),
PAST::Var.new( :name('$?CLASS') )
);

# Make sure the attribute exists.
# XXX Can't check for knowhow yet.
unless $*IN_DECL || $*PKGDECL eq 'knowhow' {
my $attr;
for $*PACKAGE.HOW.attributes($*PACKAGE, :local(1)) {
if $_.name eq $name {
$attr := $_;
last;
}
}
if pir::defined($attr) {
$past.type($attr.type);
}
else {
$/.CURSOR.panic("Attribute '$name' not declared");
}
}
}
elsif is_package(~@name[0]) {
$past := lexical_package_lookup(@name, $/);
Expand Down
9 changes: 8 additions & 1 deletion src/NQP/Grammar.pm
Expand Up @@ -98,6 +98,8 @@ grammar NQP::Grammar is HLL::Grammar {
## Top-level rules

token comp_unit {
:my $*IN_DECL := '';

:my $*HAS_YOU_ARE_HERE := 0;
:my $*MAIN_SUB;
<.newpad>
Expand Down Expand Up @@ -394,7 +396,12 @@ grammar NQP::Grammar is HLL::Grammar {
| <routine_declarator>
}

rule variable_declarator { <typename>? <variable> }
rule variable_declarator {
<typename>?
:my $*IN_DECL := 'variable';
<variable>
{ $*IN_DECL := 0; }
}

proto token routine_declarator { <...> }
token routine_declarator:sym<sub> { <sym> <routine_def> }
Expand Down

0 comments on commit eafc258

Please sign in to comment.