00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #include "ShContext.hpp"
00028 #include "ShDebug.hpp"
00029 #include "ShTypeInfo.hpp"
00030
00031 namespace SH {
00032
00033 ShContext* ShContext::m_instance = 0;
00034
00035 ShContext* ShContext::current()
00036 {
00037 if (!m_instance) {
00038 m_instance = new ShContext();
00039
00040
00041
00042 ShTypeInfo::init();
00043 }
00044 return m_instance;
00045 }
00046
00047 ShContext::ShContext()
00048 : m_optimization(2),
00049 m_throw_errors(true)
00050 {
00051 }
00052
00053
00054 int ShContext::optimization() const
00055 {
00056 return m_optimization;
00057 }
00058
00059 void ShContext::optimization(int level)
00060 {
00061 m_optimization = level;
00062 }
00063
00064 bool ShContext::throw_errors() const
00065 {
00066 return m_throw_errors;
00067 }
00068
00069 void ShContext::throw_errors(bool on)
00070 {
00071 m_throw_errors = on;
00072 }
00073
00074 void ShContext::disable_optimization(const std::string& name)
00075 {
00076 m_disabled_optimizations.insert(name);
00077 }
00078
00079 void ShContext::enable_optimization(const std::string& name)
00080 {
00081 m_disabled_optimizations.erase(name);
00082 }
00083
00084 bool ShContext::optimization_disabled(const std::string& name) const
00085 {
00086 return m_disabled_optimizations.find(name) != m_disabled_optimizations.end();
00087 }
00088
00089 ShContext::BoundProgramMap::iterator ShContext::begin_bound()
00090 {
00091 return m_bound.begin();
00092 }
00093
00094 ShContext::BoundProgramMap::iterator ShContext::end_bound()
00095 {
00096 return m_bound.end();
00097 }
00098
00099 void ShContext::set_binding(const std::string& unit, const ShProgram program)
00100 {
00101 if (!program.node()) {
00102 m_bound.erase(unit);
00103 } else {
00104 m_bound[unit] = program;
00105 }
00106 }
00107
00108 ShProgramNodePtr ShContext::parsing()
00109 {
00110 if (m_parsing.empty()) return 0;
00111 return m_parsing.top();
00112 }
00113
00114 void ShContext::enter(const ShProgramNodePtr& program)
00115 {
00116 m_parsing.push(program);
00117 }
00118
00119 void ShContext::exit()
00120 {
00121 SH_DEBUG_ASSERT(!m_parsing.empty());
00122 m_parsing.pop();
00123 }
00124
00125 ShBoundIterator shBeginBound()
00126 {
00127 return ShContext::current()->begin_bound();
00128 }
00129
00130 ShBoundIterator shEndBound()
00131 {
00132 return ShContext::current()->end_bound();
00133 }
00134
00135 }