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
00030
namespace SH {
00031
00032 ShContext* ShContext::m_instance = 0;
00033
00034 ShContext* ShContext::current()
00035 {
00036
if (!m_instance) {
00037 m_instance =
new ShContext();
00038 }
00039
return m_instance;
00040 }
00041
00042 ShContext::ShContext()
00043 : m_optimization(2),
00044 m_throw_errors(true)
00045 {
00046 }
00047
00048
int ShContext::optimization()
const
00049
{
00050
return m_optimization;
00051 }
00052
00053
void ShContext::optimization(
int level)
00054 {
00055 m_optimization = level;
00056 }
00057
00058
bool ShContext::throw_errors()
const
00059
{
00060
return m_throw_errors;
00061 }
00062
00063
void ShContext::throw_errors(
bool on)
00064 {
00065 m_throw_errors = on;
00066 }
00067
00068
void ShContext::disable_optimization(
const std::string& name)
00069 {
00070 m_disabled_optimizations.insert(name);
00071 }
00072
00073
void ShContext::enable_optimization(
const std::string& name)
00074 {
00075 m_disabled_optimizations.erase(name);
00076 }
00077
00078
bool ShContext::optimization_disabled(
const std::string& name)
const
00079
{
00080
return m_disabled_optimizations.find(name) != m_disabled_optimizations.end();
00081 }
00082
00083 ShContext::BoundProgramMap::iterator ShContext::begin_bound()
00084 {
00085
return m_bound.begin();
00086 }
00087
00088 ShContext::BoundProgramMap::iterator ShContext::end_bound()
00089 {
00090
return m_bound.end();
00091 }
00092
00093
void ShContext::set_binding(
const std::string& unit,
const ShProgram program)
00094 {
00095
if (!program.node()) {
00096 m_bound.erase(unit);
00097 }
else {
00098 m_bound[unit] = program;
00099 }
00100 }
00101
00102 ShProgramNodePtr ShContext::parsing()
00103 {
00104
if (m_parsing.empty())
return 0;
00105
return m_parsing.top();
00106 }
00107
00108
void ShContext::enter(
const ShProgramNodePtr& program)
00109 {
00110 m_parsing.push(program);
00111 }
00112
00113
void ShContext::exit()
00114 {
00115 SH_DEBUG_ASSERT(!m_parsing.empty());
00116 m_parsing.pop();
00117 }
00118
00119 ShBoundIterator
shBeginBound()
00120 {
00121
return ShContext::current()->begin_bound();
00122 }
00123
00124 ShBoundIterator
shEndBound()
00125 {
00126
return ShContext::current()->end_bound();
00127 }
00128
00129 }