token.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1993-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <cassert>
00028 
00029 #include "error.h"
00030 #include "oct-obj.h"
00031 #include "symtab.h"
00032 #include "token.h"
00033 #include "utils.h"
00034 
00035 token::token (int l, int c)
00036 {
00037   line_num = l;
00038   column_num = c;
00039   type_tag = generic_token;
00040 }
00041 
00042 token::token (const std::string& s, int l, int c)
00043 {
00044   line_num = l;
00045   column_num = c;
00046   type_tag = string_token;
00047   str = new std::string (s);
00048 }
00049 
00050 token::token (double d, const std::string& s, int l, int c)
00051 {
00052   line_num = l;
00053   column_num = c;
00054   type_tag = double_token;
00055   num = d;
00056   orig_text = s;
00057 }
00058 
00059 token::token (end_tok_type t, int l, int c)
00060 {
00061   line_num = l;
00062   column_num = c;
00063   type_tag = ettype_token;
00064   et = t;
00065 }
00066 
00067 token::token (symbol_table::symbol_record *s, int l, int c)
00068 {
00069   line_num = l;
00070   column_num = c;
00071   type_tag = sym_rec_token;
00072   sr = s;
00073 }
00074 
00075 token::token (symbol_table::symbol_record *cls,
00076               symbol_table::symbol_record *pkg, int l, int c)
00077 {
00078   line_num = l;
00079   column_num = c;
00080   type_tag = meta_rec_token;
00081   mc.cr = cls;
00082   mc.pr = pkg;
00083 }
00084 
00085 token::token (symbol_table::symbol_record *mth,
00086               symbol_table::symbol_record *cls,
00087               symbol_table::symbol_record *pkg, int l, int c)
00088 {
00089   line_num = l;
00090   column_num = c;
00091   type_tag = scls_rec_token;
00092   sc.mr = mth;
00093   sc.cr = cls;
00094   sc.pr = pkg;
00095 }
00096 
00097 token::~token (void)
00098 {
00099   if (type_tag == string_token)
00100     delete str;
00101 }
00102 
00103 std::string
00104 token::text (void)
00105 {
00106   assert (type_tag == string_token);
00107   return *str;
00108 }
00109 
00110 double
00111 token::number (void)
00112 {
00113   assert (type_tag == double_token);
00114   return num;
00115 }
00116 
00117 token::end_tok_type
00118 token::ettype (void)
00119 {
00120   assert (type_tag == ettype_token);
00121   return et;
00122 }
00123 
00124 symbol_table::symbol_record *
00125 token::sym_rec (void)
00126 {
00127   assert (type_tag == sym_rec_token);
00128   return sr;
00129 }
00130 
00131 symbol_table::symbol_record *
00132 token::method_rec (void)
00133 {
00134   assert (type_tag == scls_rec_token);
00135   return sc.mr;
00136 }
00137 
00138 symbol_table::symbol_record *
00139 token::class_rec (void)
00140 {
00141   assert (type_tag == scls_rec_token);
00142   return sc.cr;
00143 }
00144 
00145 symbol_table::symbol_record *
00146 token::package_rec (void)
00147 {
00148   assert (type_tag == scls_rec_token);
00149   return sc.pr;
00150 }
00151 
00152 symbol_table::symbol_record *
00153 token::meta_class_rec (void)
00154 {
00155   assert (type_tag == meta_rec_token);
00156   return mc.cr;
00157 }
00158 
00159 symbol_table::symbol_record *
00160 token::meta_package_rec (void)
00161 {
00162   assert (type_tag == meta_rec_token);
00163   return mc.pr;
00164 }
00165 
00166 std::string
00167 token::text_rep (void)
00168 {
00169   return orig_text;
00170 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines