1 // Copyright 2016-2021 Doug Moen 2 // Licensed under the Apache License, version 2.0 3 // See accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0 4 5 #ifndef LIBCURV_SC_CONTEXT_H 6 #define LIBCURV_SC_CONTEXT_H 7 8 #include <libcurv/context.h> 9 #include <libcurv/sc_frame.h> 10 11 namespace curv { 12 13 struct At_SC_Frame : public Context 14 { 15 SC_Frame& call_frame_; 16 At_SC_FrameAt_SC_Frame17 At_SC_Frame(SC_Frame& frame) : call_frame_(frame) {} 18 19 virtual void get_locations(std::list<Func_Loc>& locs) const override; 20 Shared<const String> rewrite_message(Shared<const String>) const override; 21 virtual System& system() const override; 22 virtual Frame* frame() const override; 23 }; 24 25 /// Exception Context where we know the Phrase that contains the error. 26 struct At_SC_Phrase : public At_Syntax 27 { 28 Shared<const Phrase> phrase_; 29 SC_Frame& call_frame_; 30 31 At_SC_Phrase(Shared<const Phrase> phrase, SC_Frame& frame); 32 33 virtual void get_locations(std::list<Func_Loc>& locs) const override; 34 Shared<const String> rewrite_message(Shared<const String>) const override; 35 virtual System& system() const override; 36 virtual Frame* frame() const override; 37 virtual const Phrase& syntax() const override; 38 }; 39 40 // This is part of v1 of the API for builtin SC function call. 41 // It is used by Tuple_Function::sc_tuple_call() in builtin.cc. 42 // See At_SC_Arg_Expr for the v2 version. 43 struct At_SC_Tuple_Arg : public Context 44 { 45 size_t tuple_index_; 46 SC_Frame& call_frame_; // frame for THIS function call 47 At_SC_Tuple_ArgAt_SC_Tuple_Arg48 At_SC_Tuple_Arg(size_t i, SC_Frame& f) : tuple_index_(i), call_frame_(f) {} 49 50 void get_locations(std::list<Func_Loc>& locs) const override; 51 Shared<const String> rewrite_message(Shared<const String>) const override; 52 virtual System& system() const override; 53 virtual Frame* frame() const override; 54 }; 55 56 // This is part of v2 of the API for builtin SC function call. 57 // It is used by Function::sc_call_expr() in builtin.cc. 58 // It closely models the semantics of At_Arg from context.h. 59 // See At_SC_Tuple_Arg for the v1 version. 60 struct At_SC_Arg_Expr : public At_Syntax 61 { At_SC_Arg_ExprAt_SC_Arg_Expr62 At_SC_Arg_Expr( 63 const Function& fn, 64 Shared<const Phrase> callphrase, 65 SC_Frame& parentframe) 66 : 67 func_(fn), 68 call_phrase_(callphrase), 69 parent_frame_(parentframe) 70 {} 71 72 const Function& func_; 73 Shared<const Phrase> call_phrase_; 74 SC_Frame& parent_frame_; // The CALLER's frame. This call has no frame. 75 76 virtual void get_locations(std::list<Func_Loc>& locs) const override; 77 Shared<const String> rewrite_message(Shared<const String>) const override; 78 virtual System& system() const override; 79 virtual Frame* frame() const override; 80 virtual const Phrase& syntax() const override; 81 }; 82 83 void get_sc_frame_locations(const SC_Frame* f, std::list<Func_Loc>& locs); 84 Shared<const String> sc_frame_rewrite_message( 85 const SC_Frame*, Shared<const String>); 86 87 } // namespace curv 88 #endif // header guard 89