GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-decl.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "defun.h"
31#include "error.h"
32#include "pt-cmd.h"
33#include "ov.h"
34#include "oct-lvalue.h"
35#include "pt-bp.h"
36#include "pt-decl.h"
37#include "pt-exp.h"
38#include "pt-id.h"
39#include "pt-walk.h"
40#include "utils.h"
41#include "variables.h"
42
43namespace octave
44{
45 // Declarations (global, static, etc.).
46
48 : type (unknown), m_id (i), m_expr (e)
49 {
50 if (! m_id)
51 error ("tree_decl_elt: invalid ID");
52 }
53
55 {
56 delete m_id;
57 delete m_expr;
58 }
59
62 {
63 return new tree_decl_elt (m_id->dup (scope),
64 m_expr ? m_expr->dup (scope) : nullptr);
65 }
66
67 // Initializer lists for declaration statements.
68
69 // Declaration commands (global, static).
70
72 tree_decl_init_list *t, int l, int c)
73 : tree_command (l, c), m_cmd_name (n), m_init_list (t)
74 {
75 if (t)
76 {
77 if (m_cmd_name == "global")
78 mark_global ();
79 else if (m_cmd_name == "persistent")
81 else
82 error ("tree_decl_command: unknown decl type: %s",
83 m_cmd_name.c_str ());
84 }
85 }
86
88 {
89 delete m_init_list;
90 }
91}
std::string m_cmd_name
Definition: pt-decl.h:213
void mark_persistent(void)
Definition: pt-decl.h:195
tree_decl_init_list * m_init_list
Definition: pt-decl.h:216
tree_decl_command(const std::string &n, int l=-1, int c=-1)
Definition: pt-decl.h:175
void mark_global(void)
Definition: pt-decl.h:189
tree_expression * m_expr
Definition: pt-decl.h:109
tree_identifier * m_id
Definition: pt-decl.h:106
tree_decl_elt(tree_identifier *i, tree_expression *e=nullptr)
Definition: pt-decl.cc:47
tree_decl_elt * dup(symbol_scope &scope) const
Definition: pt-decl.cc:61
virtual tree_expression * dup(symbol_scope &scope) const =0
tree_identifier * dup(symbol_scope &scope) const
Definition: pt-id.cc:78
void error(const char *fmt,...)
Definition: error.cc:980