Mercurial > octave-nkf
comparison src/symtab.h @ 7901:3e4c9b69069d
call stack changes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 08 Jul 2008 12:00:32 -0400 |
parents | 8447a5024650 |
children | 5bf4e2c13ed8 |
comparison
equal
deleted
inserted
replaced
7900:5b077861d168 | 7901:3e4c9b69069d |
---|---|
857 | 857 |
858 static scope_id global_scope (void) { return xglobal_scope; } | 858 static scope_id global_scope (void) { return xglobal_scope; } |
859 static scope_id top_scope (void) { return xtop_scope; } | 859 static scope_id top_scope (void) { return xtop_scope; } |
860 | 860 |
861 static scope_id current_scope (void) { return xcurrent_scope; } | 861 static scope_id current_scope (void) { return xcurrent_scope; } |
862 static scope_id current_caller_scope (void) { return xcurrent_caller_scope; } | |
863 | 862 |
864 static context_id current_context (void) { return xcurrent_context; } | 863 static context_id current_context (void) { return xcurrent_context; } |
865 | 864 |
866 // We use parent_scope to handle parsing subfunctions. | 865 // We use parent_scope to handle parsing subfunctions. |
867 static scope_id parent_scope (void) { return xparent_scope; } | 866 static scope_id parent_scope (void) { return xparent_scope; } |
885 } | 884 } |
886 else | 885 else |
887 instance = p->second; | 886 instance = p->second; |
888 | 887 |
889 xcurrent_scope = scope; | 888 xcurrent_scope = scope; |
890 xcurrent_context = instance->xcurrent_context_this_table; | 889 xcurrent_context = 0; |
891 } | 890 } |
892 } | 891 } |
893 | 892 |
894 static void set_scope_and_context (scope_id scope, context_id context) | 893 static void set_scope_and_context (scope_id scope, context_id context) |
895 { | 894 { |
919 static void push_scope (scope_id scope) | 918 static void push_scope (scope_id scope) |
920 { | 919 { |
921 if (scope_stack.empty ()) | 920 if (scope_stack.empty ()) |
922 scope_stack.push_front (xtop_scope); | 921 scope_stack.push_front (xtop_scope); |
923 | 922 |
924 xcurrent_caller_scope = xcurrent_scope; | |
925 | |
926 set_scope (scope); | 923 set_scope (scope); |
927 | 924 |
928 scope_stack.push_front (scope); | 925 scope_stack.push_front (scope); |
929 } | 926 } |
930 | 927 |
931 static void pop_scope (void) | 928 static void pop_scope (void) |
932 { | 929 { |
933 scope_stack.pop_front (); | 930 scope_stack.pop_front (); |
934 | 931 |
935 set_scope (scope_stack[0]); | 932 set_scope (scope_stack[0]); |
936 | |
937 xcurrent_caller_scope = scope_stack.size () > 1 ? scope_stack[1] : -1; | |
938 } | 933 } |
939 | 934 |
940 static void pop_scope (void *) { pop_scope (); } | 935 static void pop_scope (void *) { pop_scope (); } |
941 | 936 |
942 static void reset_scope (void) | 937 static void reset_scope (void) |
944 scope_stack.clear (); | 939 scope_stack.clear (); |
945 | 940 |
946 scope_stack.push_front (xtop_scope); | 941 scope_stack.push_front (xtop_scope); |
947 | 942 |
948 set_scope (xtop_scope); | 943 set_scope (xtop_scope); |
949 | |
950 xcurrent_caller_scope = -1; | |
951 } | 944 } |
952 | 945 |
953 static void set_parent_scope (scope_id scope) | 946 static void set_parent_scope (scope_id scope) |
954 { | 947 { |
955 xparent_scope = scope; | 948 xparent_scope = scope; |
1823 | 1816 |
1824 static const scope_id xglobal_scope; | 1817 static const scope_id xglobal_scope; |
1825 static const scope_id xtop_scope; | 1818 static const scope_id xtop_scope; |
1826 | 1819 |
1827 static scope_id xcurrent_scope; | 1820 static scope_id xcurrent_scope; |
1828 static scope_id xcurrent_caller_scope; | |
1829 | 1821 |
1830 // We use parent_scope to handle parsing subfunctions. | 1822 // We use parent_scope to handle parsing subfunctions. |
1831 static scope_id xparent_scope; | 1823 static scope_id xparent_scope; |
1832 | 1824 |
1833 // Used to handle recursive calls. | |
1834 context_id xcurrent_context_this_table; | |
1835 static context_id xcurrent_context; | 1825 static context_id xcurrent_context; |
1836 | 1826 |
1837 static std::deque<scope_id> scope_stack; | 1827 static std::deque<scope_id> scope_stack; |
1838 | 1828 |
1839 symbol_table (void) | 1829 symbol_table (void) |
1840 : table_name (), table (), xcurrent_context_this_table () { } | 1830 : table_name (), table () { } |
1841 | 1831 |
1842 ~symbol_table (void) { } | 1832 ~symbol_table (void) { } |
1843 | 1833 |
1844 static symbol_table *get_instance (scope_id scope, bool create = true) | 1834 static symbol_table *get_instance (scope_id scope, bool create = true) |
1845 { | 1835 { |
2023 return retval; | 2013 return retval; |
2024 } | 2014 } |
2025 | 2015 |
2026 void do_push_context (void) | 2016 void do_push_context (void) |
2027 { | 2017 { |
2028 xcurrent_context = ++xcurrent_context_this_table; | |
2029 | |
2030 for (table_iterator p = table.begin (); p != table.end (); p++) | 2018 for (table_iterator p = table.begin (); p != table.end (); p++) |
2031 p->second.push_context (); | 2019 p->second.push_context (); |
2032 } | 2020 } |
2033 | 2021 |
2034 void do_pop_context (void) | 2022 void do_pop_context (void) |
2035 { | 2023 { |
2036 xcurrent_context = --xcurrent_context_this_table; | |
2037 | |
2038 for (table_iterator p = table.begin (); p != table.end (); ) | 2024 for (table_iterator p = table.begin (); p != table.end (); ) |
2039 { | 2025 { |
2040 if (p->second.pop_context () == 0) | 2026 if (p->second.pop_context () == 0) |
2041 table.erase (p++); | 2027 table.erase (p++); |
2042 else | 2028 else |