[system] / trunk / pg / lib / Parser / Context / Variables.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/Parser/Context/Variables.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2686 Revision 2687
17 'Complex' => $Value::Type{complex}, 17 'Complex' => $Value::Type{complex},
18 'Point2D' => Value::Type('Point',2,$Value::Type{number}), 18 'Point2D' => Value::Type('Point',2,$Value::Type{number}),
19 'Point3D' => Value::Type('Point',3,$Value::Type{number}), 19 'Point3D' => Value::Type('Point',3,$Value::Type{number}),
20 'Vector2D' => Value::Type('Vector',2,$Value::Type{number}), 20 'Vector2D' => Value::Type('Vector',2,$Value::Type{number}),
21 'Vector3D' => Value::Type('Vector',3,$Value::Type{number}), 21 'Vector3D' => Value::Type('Vector',3,$Value::Type{number}),
22 'Parameter' => $Value::Type{number},
22); 23);
23 24
24sub init { 25sub init {
25 my $self = shift; 26 my $self = shift;
26 $self->{dataName} = 'variables'; 27 $self->{dataName} = 'variables';
44# Otherwise if it is a Value object use its type, 45# Otherwise if it is a Value object use its type,
45# Otherwise, if it is a signed number, use the Real type 46# Otherwise, if it is a signed number, use the Real type
46# Otherwise report an error 47# Otherwise report an error
47# 48#
48sub create { 49sub create {
49 my $self = shift; my $value = shift; 50 my $self = shift; my $value = shift; my @extra;
50 return $value if ref($value) eq 'HASH'; 51 return $value if ref($value) eq 'HASH';
51 if (defined($type{$value})) { 52 if (defined($type{$value})) {
53 @extra = (parameter => 1) if $value eq 'Parameter';
52 $value = $type{$value}; 54 $value = $type{$value};
53 } elsif (Value::isValue($value)) { 55 } elsif (Value::isValue($value)) {
54 $value = $value->typeRef; 56 $value = $value->typeRef;
55 } elsif ($value =~ m/$self->{context}{pattern}{signedNumber}/) { 57 } elsif ($value =~ m/$self->{context}{pattern}{signedNumber}/) {
56 $value = $type{'Real'}; 58 $value = $type{'Real'};
57 } else { 59 } else {
58 Value::Error("Unrecognized variable type '$value'"); 60 Value::Error("Unrecognized variable type '$value'");
59 } 61 }
60 return {type => $value}; 62 return {type => $value, @extra};
61} 63}
62 64
63# 65#
64# Return a variable's type 66# Return a variable's type
65# 67#
66sub type { 68sub type {
67 my $self = shift; my $x = shift; 69 my $self = shift; my $x = shift;
68 return $self->{context}{variables}{$x}{type}; 70 return $self->{context}{variables}{$x}{type};
69} 71}
70 72
73#
74# Get the names of all variables
75#
76sub variables {
77 my $self = shift; my @names;
78 foreach my $x ($self->SUPER::names)
79 {push(@names,$x) unless $self->{context}{variables}{$x}{parameter}}
80 return @names;
81}
82
83#
84# Get the names of all parameters
85#
86sub parameters {
87 my $self = shift; my @names;
88 foreach my $x ($self->SUPER::names)
89 {push(@names,$x) if $self->{context}{variables}{$x}{parameter}}
90 return @names;
91}
92
71######################################################################### 93#########################################################################
72 94
731; 951;
74 96

Legend:
Removed from v.2686  
changed lines
  Added in v.2687

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9