GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-decl.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "defun.h"
28 #include "error.h"
29 #include "pt-cmd.h"
30 #include "ov.h"
31 #include "oct-lvalue.h"
32 #include "pt-bp.h"
33 #include "pt-decl.h"
34 #include "pt-exp.h"
35 #include "pt-id.h"
36 #include "pt-walk.h"
37 #include "utils.h"
38 #include "variables.h"
39 
40 // Declarations (global, static, etc.).
41 
43 {
44  delete id;
45  delete expr;
46 }
47 
48 bool
50 {
51  bool retval = false;
52 
53  if (id && expr)
54  {
55  octave_lvalue ult = id->lvalue ();
56 
57  octave_value init_val = expr->rvalue1 ();
58 
59  ult.assign (octave_value::op_asn_eq, init_val);
60 
61  retval = true;
62  }
63 
64  return retval;
65 }
66 
70 {
71  return new tree_decl_elt (id ? id->dup (scope, context) : 0,
72  expr ? expr->dup (scope, context) : 0);
73 }
74 
75 void
77 {
78  tw.visit_decl_elt (*this);
79 }
80 
81 // Initializer lists for declaration statements.
82 
86 {
87  tree_decl_init_list *new_dil = new tree_decl_init_list ();
88 
89  for (const_iterator p = begin (); p != end (); p++)
90  {
91  const tree_decl_elt *elt = *p;
92 
93  new_dil->append (elt ? elt->dup (scope, context) : 0);
94  }
95 
96  return new_dil;
97 }
98 
99 void
101 {
102  tw.visit_decl_init_list (*this);
103 }
104 
105 // Base class for declaration commands (global, static).
106 
108 {
109  delete init_list;
110 }
111 
112 // Global.
113 
114 tree_command *
117 {
118  return
119  new tree_global_command (init_list ? init_list->dup (scope, context) : 0,
120  line (), column ());
121 }
122 
123 void
125 {
126  tw.visit_global_command (*this);
127 }
128 
129 // Static.
130 
131 tree_command *
134 {
135  return
136  new tree_persistent_command (init_list ? init_list->dup (scope, context)
137  : 0,
138  line (), column ());
139 }
140 
141 void
143 {
144  tw.visit_persistent_command (*this);
145 }
tree_decl_init_list(void)
Definition: pt-decl.h:118
tree_decl_elt * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-decl.cc:68
tree_identifier * id
Definition: pt-decl.h:101
tree_decl_init_list * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-decl.cc:84
virtual tree_expression * dup(symbol_table::scope_id, symbol_table::context_id context) const =0
tree_expression * expr
Definition: pt-decl.h:104
tree_identifier * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-id.cc:134
virtual void visit_global_command(tree_global_command &)=0
virtual void visit_persistent_command(tree_persistent_command &)=0
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
tree_command * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-decl.cc:115
tree_persistent_command(int l=-1, int c=-1)
Definition: pt-decl.h:221
tree_global_command(int l=-1, int c=-1)
Definition: pt-decl.h:190
void accept(tree_walker &tw)
Definition: pt-decl.cc:124
octave_value retval
Definition: data.cc:6294
void accept(tree_walker &tw)
Definition: pt-decl.cc:142
void accept(tree_walker &tw)
Definition: pt-decl.cc:100
virtual int line(void) const
Definition: pt.h:49
tree_decl_init_list * init_list
Definition: pt-decl.h:172
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:54
std::list< tree_decl_elt * >::const_iterator const_iterator
Definition: base-list.h:41
void assign(octave_value::assign_op, const octave_value &)
Definition: oct-lvalue.cc:33
virtual void visit_decl_init_list(tree_decl_init_list &)=0
p
Definition: lu.cc:138
void accept(tree_walker &tw)
Definition: pt-decl.cc:76
~tree_decl_command(void)
Definition: pt-decl.cc:107
tree_decl_elt(tree_identifier *i=0, tree_expression *e=0)
Definition: pt-decl.h:48
void append(const elt_type &s)
Definition: base-list.h:110
bool eval(void)
Definition: pt-decl.cc:49
virtual int column(void) const
Definition: pt.h:51
tree_command * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-decl.cc:132
~tree_decl_elt(void)
Definition: pt-decl.cc:42
virtual void visit_decl_elt(tree_decl_elt &)=0