Skip to content

Commit

Permalink
Remove using namespace std from source
Browse files Browse the repository at this point in the history
Add new `sass.hpp` header for minimal std includes and
exporting only specific symbols from std into our `Sass`
namespace. Also removed some redundant includes!
  • Loading branch information
mgreter committed Jul 21, 2015
1 parent bc802ba commit ed8388d
Show file tree
Hide file tree
Showing 69 changed files with 137 additions and 155 deletions.
4 changes: 2 additions & 2 deletions include/sass.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SASS_H
#define SASS_H
#ifndef SASS_C_H
#define SASS_C_H

// #define DEBUG 1

Expand Down
7 changes: 4 additions & 3 deletions include/sass2scss.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
#define SASS2SCSS_VERSION "1.0.3"
#endif

// using std::string
using namespace std;

// add namespace for c++
namespace Sass
{

using std::stack;
using std::string;
using std::stringstream;

// pretty print options
const int SASS2SCSS_PRETTIFY_0 = 0;
const int SASS2SCSS_PRETTIFY_1 = 1;
Expand Down
14 changes: 9 additions & 5 deletions src/ast.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ast.hpp"
#include "sass.hpp"
#include "context.hpp"
#include "node.hpp"
#include "extend.hpp"
Expand All @@ -10,7 +11,6 @@
#include <iostream>

namespace Sass {
using namespace std;

static Null sass_null(Sass::Null(ParserState("null")));

Expand Down Expand Up @@ -1451,6 +1451,10 @@ namespace Sass {

string Color::to_string(bool compressed, int precision) const
{
using std::hex;
using std::setw;
using std::setfill;

stringstream ss;

// original color name
Expand Down Expand Up @@ -1550,8 +1554,8 @@ namespace Sass {
// check if we got scientific notation in result
if (ss.str().find_first_of("e") != string::npos) {
ss.clear(); ss.str(string());
ss.precision(max(12, precision));
ss << fixed << value_;
ss.precision(std::max(12, precision));
ss << std::fixed << value_;
}

string tmp = ss.str();
Expand All @@ -1567,7 +1571,7 @@ namespace Sass {
if (is_int)
{
ss.precision(0);
ss << fixed << value_;
ss << std::fixed << value_;
res = string(ss.str());
}
// process floats
Expand All @@ -1578,7 +1582,7 @@ namespace Sass {
{ precision = pos_fract - pos_point; }
// round value again
ss.precision(precision);
ss << fixed << value_;
ss << std::fixed << value_;
res = string(ss.str());
// maybe we truncated up to decimal point
size_t pos = res.find_last_not_of("0");
Expand Down
12 changes: 7 additions & 5 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

#include <set>
#include <deque>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <typeinfo>
#include <algorithm>
Expand All @@ -30,6 +27,7 @@

#endif

#include "sass.hpp"
#include "util.hpp"
#include "units.hpp"
#include "context.hpp"
Expand All @@ -52,7 +50,6 @@
#include "sass_functions.h"

namespace Sass {
using namespace std;

// from boost (functional/hash):
// http://www.boost.org/doc/libs/1_35_0/doc/html/hash/combine.html
Expand Down Expand Up @@ -173,7 +170,12 @@ namespace std {
}

namespace Sass {
using namespace std;

using std::deque;
using std::make_pair;
using std::istringstream;
using std::ostringstream;
using std::unordered_map;

/////////////////////////////////////////////////////////////////////////////
// Mixin class for AST nodes that should behave like vectors. Uses the
Expand Down
1 change: 0 additions & 1 deletion src/ast_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "ast.hpp"

namespace Sass {
using namespace std;

class AST_Factory {
vector<AST_Node*> nodes;
Expand Down
5 changes: 1 addition & 4 deletions src/backtrace.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#ifndef SASS_BACKTRACE_H
#define SASS_BACKTRACE_H

#include <sstream>

#include "sass.hpp"
#include "file.hpp"
#include "position.hpp"

namespace Sass {

using namespace std;

struct Backtrace {

Backtrace* parent;
Expand Down
2 changes: 1 addition & 1 deletion src/bind.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "bind.hpp"
#include "ast.hpp"
#include "sass.hpp"
#include "context.hpp"
#include "eval.hpp"
#include <map>
Expand All @@ -8,7 +9,6 @@
#include "to_string.hpp"

namespace Sass {
using namespace std;

void bind(string callee, Parameters* ps, Arguments* as, Context& ctx, Env* env, Eval* eval)
{
Expand Down
1 change: 0 additions & 1 deletion src/bind.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef SASS_BIND_H
#define SASS_BIND_H

#include <string>
#include "environment.hpp"

namespace Sass {
Expand Down
9 changes: 4 additions & 5 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
#include "emitter.hpp"

namespace Sass {
using namespace Constants;
using namespace File;
using namespace Sass;
using std::cerr;
using std::endl;

using std::unordered_map;
using File::make_canonical_path;
using File::resolve_relative_path;

Sass_Queued::Sass_Queued(const string& load_path, const string& abs_path, const char* source)
{
Expand Down
5 changes: 2 additions & 3 deletions src/context.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef SASS_CONTEXT_H
#define SASS_CONTEXT_H

#include <string>
#include <vector>
#include <map>

#define BUFFERSIZE 255
#include "b64/encode.h"

#include "sass.hpp"
#include "ast_fwd_decl.hpp"
#include "kwd_arg_macros.hpp"
#include "memory_manager.hpp"
Expand All @@ -21,7 +20,7 @@
struct Sass_Function;

namespace Sass {
using namespace std;

struct Sass_Queued {
string abs_path;
string load_path;
Expand Down
1 change: 0 additions & 1 deletion src/cssize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "environment.hpp"

namespace Sass {
using namespace std;

typedef Environment<AST_Node*> Env;
struct Backtrace;
Expand Down
7 changes: 2 additions & 5 deletions src/debugger.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#ifndef SASS_DEBUGGER_H
#define SASS_DEBUGGER_H

#include <string>
#include <sstream>
#include "node.hpp"
#include "ast_fwd_decl.hpp"

using namespace std;
using namespace Sass;

/*
inline void debug_extenstion_map(Sass::ExtensionSubsetMap* map, string ind = "")
{
Expand Down Expand Up @@ -68,6 +63,8 @@ inline string pstate_source_position(AST_Node* node)

inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
{
using std::string;
using namespace Sass;
if (node == 0) return;
if (ind == "") cerr << "####################################################################\n";
if (dynamic_cast<Bubble*>(node)) {
Expand Down
1 change: 0 additions & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "utf8_string.hpp"

namespace Sass {
using namespace std;

Emitter::Emitter(Context* ctx)
: wbuf(),
Expand Down
4 changes: 2 additions & 2 deletions src/emitter.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef SASS_EMITTER_H
#define SASS_EMITTER_H

#include <string>
#include "sass.hpp"
#include "source_map.hpp"
#include "ast_fwd_decl.hpp"

namespace Sass {

class Context;
using namespace std;

class Emitter {

Expand Down
6 changes: 2 additions & 4 deletions src/environment.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#ifndef SASS_ENVIRONMENT_H
#define SASS_ENVIRONMENT_H

#include <string>
#include <iostream>
#include <map>

#include "sass.hpp"
#include "ast_fwd_decl.hpp"
#include "ast_def_macros.hpp"
#include "memory_manager.hpp"

namespace Sass {
using std::string;

using std::map;
using std::cerr;
using std::endl;

template <typename T>
class Environment {
Expand Down
3 changes: 0 additions & 3 deletions src/error_handling.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#ifndef SASS_ERROR_HANDLING_H
#define SASS_ERROR_HANDLING_H

#include <string>

#include "position.hpp"

namespace Sass {
using namespace std;

struct Backtrace;

Expand Down
1 change: 0 additions & 1 deletion src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "color_maps.hpp"

namespace Sass {
using namespace std;

inline double add(double x, double y) { return x + y; }
inline double sub(double x, double y) { return x - y; }
Expand Down
2 changes: 1 addition & 1 deletion src/eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#define SASS_EVAL_H

#include <iostream>
#include "sass.hpp"
#include "context.hpp"
#include "listize.hpp"
#include "operation.hpp"

namespace Sass {
using namespace std;

class Expand;
class Context;
Expand Down
1 change: 0 additions & 1 deletion src/expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "environment.hpp"

namespace Sass {
using namespace std;

class Listize;
class Context;
Expand Down
4 changes: 2 additions & 2 deletions src/extend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ namespace Sass {
if (comparator(x[i], y[j], pCompareOut)) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i][j - 1], c[i - 1][j]);
c[i][j] = std::max(c[i][j - 1], c[i - 1][j]);
}
}
}
Expand Down Expand Up @@ -529,7 +529,7 @@ namespace Sass {

for (SourcesSet::iterator sourcesSetIterator = sources.begin(), sourcesSetIteratorEnd = sources.end(); sourcesSetIterator != sourcesSetIteratorEnd; ++sourcesSetIterator) {
const Complex_Selector* const pCurrentSelector = *sourcesSetIterator;
maxSpecificity = max(maxSpecificity, pCurrentSelector->specificity());
maxSpecificity = std::max(maxSpecificity, pCurrentSelector->specificity());
}

DEBUG_PRINTLN(TRIM, "MAX SPECIFICITY: " << maxSpecificity)
Expand Down
1 change: 0 additions & 1 deletion src/extend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "subset_map.hpp"

namespace Sass {
using namespace std;

class Context;
class Node;
Expand Down
10 changes: 7 additions & 3 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sass2scss.h"

#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#endif

Expand All @@ -31,7 +32,8 @@

namespace Sass {
namespace File {
using namespace std;

using std::wstring;

// return the current directory
// always with forward slashes
Expand Down Expand Up @@ -84,7 +86,7 @@ namespace Sass {
size_t pos_w = string::npos;
#endif
if (pos_p != string::npos && pos_w != string::npos) {
pos = max(pos_p, pos_w);
pos = std::max(pos_p, pos_w);
}
else if (pos_p != string::npos) {
pos = pos_p;
Expand Down Expand Up @@ -188,7 +190,7 @@ namespace Sass {
string stripped_base = "";

size_t index = 0;
size_t minSize = min(absolute_uri.size(), absolute_base.size());
size_t minSize = std::min(absolute_uri.size(), absolute_base.size());
for (size_t i = 0; i < minSize; ++i) {
#ifdef FS_CASE_SENSITIVE
if (absolute_uri[i] != absolute_base[i]) break;
Expand Down Expand Up @@ -299,6 +301,8 @@ namespace Sass {
// will auto convert .sass files
char* read_file(const string& path)
{
using std::ios;
using std::ifstream;
#ifdef _WIN32
BYTE* pBuffer;
DWORD dwBytes;
Expand Down
Loading

0 comments on commit ed8388d

Please sign in to comment.