Skip to content

Commit

Permalink
Merge pull request #913 from am11/master
Browse files Browse the repository at this point in the history
Code: Fixes VC warnings
  • Loading branch information
xzyfer committed Mar 3, 2015
2 parents 8e74f7f + 4b08df3 commit fb64dbd
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 57 deletions.
4 changes: 2 additions & 2 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ namespace Sass {
ADD_PROPERTY(bool, group_end);
public:
Bubble(ParserState pstate, Statement* n, Statement* g = 0, size_t t = 0)
: Statement(pstate, Statement::BUBBLE, t), node_(n), group_end_(g)
: Statement(pstate, Statement::BUBBLE, t), node_(n), group_end_(g == 0)
{ }
bool bubbles() { return true; }
ATTACH_OPERATIONS();
Expand Down Expand Up @@ -1523,7 +1523,7 @@ namespace Sass {

if (with)
{
if (!l || !l->length()) return str.compare("rule");
if (!l || !l->length() != 0) return str.compare("rule") != 0;
for (size_t i = 0, L = l->length(); i < L; ++i)
{
v = unquote((*l)[i]->perform(&to_string));
Expand Down
4 changes: 2 additions & 2 deletions b64/encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For details, see http://sourceforge.net/projects/libb64

namespace base64
{
extern "C"
extern "C"
{
#include "cencode.h"
}
Expand Down Expand Up @@ -54,7 +54,7 @@ namespace base64
do
{
istream_in.read(plaintext, N);
plainlength = istream_in.gcount();
plainlength = static_cast<int>(istream_in.gcount());
//
codelength = encode(plaintext, plainlength, code);
ostream_in.write(code, codelength);
Expand Down
2 changes: 1 addition & 1 deletion bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Sass {
class AST_Node;
class Parameters;
class Arguments;
struct Context;
class Context;
class Eval;
typedef Environment<AST_Node*> Env;

Expand Down
8 changes: 4 additions & 4 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ namespace Sass {
names_to_colors[name] = value;
// only map fully opaque colors
if (color_values[i*4+3] >= 1) {
int numval = color_values[i*4]*0x10000;
numval += color_values[i*4+1]*0x100;
numval += color_values[i*4+2];
int numval = static_cast<int>(color_values[i*4])*0x10000;
numval += static_cast<int>(color_values[i*4+1])*0x100;
numval += static_cast<int>(color_values[i*4+2]);
colors_to_names[numval] = name;
}
++i;
Expand Down Expand Up @@ -287,7 +287,7 @@ namespace Sass {
add_source(input_path, input_path, contents);
return parse_file();
}
add_source(input_path, input_path, strdup(source_c_str));
add_source(input_path, input_path, copy_c_str(source_c_str));
return parse_file();
}

Expand Down
4 changes: 2 additions & 2 deletions extend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Sass {
using namespace std;

struct Context;
class Context;

typedef Subset_Map<string, pair<Complex_Selector*, Compound_Selector*> > ExtensionSubsetMap;

Expand Down Expand Up @@ -42,4 +42,4 @@ namespace Sass {

}

#endif
#endif
2 changes: 1 addition & 1 deletion file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Sass {
using namespace std;
struct Context;
class Context;
namespace File {
string get_cwd();
string base_name(string);
Expand Down
24 changes: 12 additions & 12 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace Sass {
// random_device degrades sharply once the entropy pool
// is exhausted. For practical use, random_device is
// generally only used to seed a PRNG such as mt19937.
static mt19937 rand(GetSeed());
static mt19937 rand(static_cast<unsigned int>(GetSeed()));

// features
static set<string> features;
Expand Down Expand Up @@ -759,7 +759,7 @@ namespace Sass {
if (String_Quoted* string_quoted = dynamic_cast<String_Quoted*>(arg)) {
String_Constant* result = new (ctx.mem) String_Constant(pstate, string_quoted->value());
// remember if the string was quoted (color tokens)
result->sass_fix_1291(string_quoted->quote_mark());
result->sass_fix_1291(string_quoted->quote_mark() != 0);
return result;
}
return new (ctx.mem) String_Constant(pstate, string(arg->perform(&to_string)));
Expand Down Expand Up @@ -820,7 +820,7 @@ namespace Sass {

if (index > 0 && index <= len) {
// positive and within string length
str.insert(UTF_8::offset_at_position(str, index - 1), ins);
str.insert(UTF_8::offset_at_position(str, static_cast<size_t>(index) - 1), ins);
}
else if (index > len) {
// positive and past string length
Expand All @@ -832,7 +832,7 @@ namespace Sass {
else if (std::abs(index) <= len) {
// negative and within string length
index += len + 1;
str.insert(UTF_8::offset_at_position(str, index), ins);
str.insert(UTF_8::offset_at_position(str, static_cast<size_t>(index)), ins);
}
else {
// negative and past string length
Expand Down Expand Up @@ -906,8 +906,8 @@ namespace Sass {
string str = unquote(s->value());

// normalize into 0-based indices
size_t start = UTF_8::offset_at_position(str, UTF_8::normalize_index(n->value(), UTF_8::code_point_count(str)));
size_t end = UTF_8::offset_at_position(str, UTF_8::normalize_index(m->value(), UTF_8::code_point_count(str)));
size_t start = UTF_8::offset_at_position(str, UTF_8::normalize_index(static_cast<int>(n->value()), UTF_8::code_point_count(str)));
size_t end = UTF_8::offset_at_position(str, UTF_8::normalize_index(static_cast<int>(m->value()), UTF_8::code_point_count(str)));

// `str-slice` should always return an empty string when $end-at == 0
// `normalize_index` normalizes 1 -> 0 so we need to check the original value
Expand Down Expand Up @@ -1068,12 +1068,12 @@ namespace Sass {
if (l && trunc(l->value()) != l->value()) error("argument $limit of `" + string(sig) + "` must be an integer", pstate);
if (l) {
uniform_real_distribution<> distributor(1, l->value() + 1);
uint_fast32_t distributed = distributor(rand);
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
return new (ctx.mem) Number(pstate, (double)distributed);
}
else {
uniform_real_distribution<> distributor(0, 1);
uint_fast32_t distributed = distributor(rand);
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
return new (ctx.mem) Number(pstate, trunc(distributed));
}
}
Expand Down Expand Up @@ -1117,12 +1117,12 @@ namespace Sass {

if (m) {
l = new (ctx.mem) List(pstate, 1);
*l << m->keys()[index];
*l << m->at(m->keys()[index]);
*l << m->keys()[static_cast<unsigned int>(index)];
*l << m->at(m->keys()[static_cast<unsigned int>(index)]);
return l;
}
else {
return l->value_at_index(index);
return l->value_at_index(static_cast<int>(index));
}
}

Expand Down Expand Up @@ -1539,7 +1539,7 @@ namespace Sass {
{
std::stringstream ss;
uniform_real_distribution<> distributor(0, 4294967296); // 16^8
uint_fast32_t distributed = distributor(rand);
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
ss << "u" << setfill('0') << setw(8) << std::hex << distributed;
return new (ctx.mem) String_Constant(pstate, ss.str());
}
Expand Down
2 changes: 1 addition & 1 deletion functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name(Env& env, Env& d_env, Context& ctx, Signature sig, ParserState pstate, Backtrace* backtrace)

namespace Sass {
struct Context;
class Context;
struct Backtrace;
class AST_Node;
class Expression;
Expand Down
2 changes: 1 addition & 1 deletion inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ namespace Sass {
}
// otherwise get the possible resolved color name
else {
int numval = r * 0x10000 + g * 0x100 + b;
int numval = static_cast<int>(r) * 0x10000 + static_cast<int>(g) * 0x100 + static_cast<int>(b);
if (ctx && ctx->colors_to_names.count(numval))
res_name = ctx->colors_to_names[numval];
}
Expand Down
2 changes: 1 addition & 1 deletion node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Sass {
using namespace std;


struct Context;
class Context;

/*
There are a lot of stumbling blocks when trying to port the ruby extend code to C++. The biggest is the choice of
Expand Down
2 changes: 1 addition & 1 deletion parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ namespace Sass {
while (peek< sequence< optional_spaces_and_comments, exactly<','> > >())
{
// consume everything up and including the comma speparator
reloop = lex< sequence< optional_spaces_and_comments, exactly<','> > >();
reloop = lex< sequence< optional_spaces_and_comments, exactly<','> > >() != 0;
// remember line break (also between some commas)
if (peek_newline()) comb->has_line_feed(true);
if (comb->tail() && peek_newline()) comb->tail()->has_line_feed(true);
Expand Down
2 changes: 1 addition & 1 deletion remove_placeholders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Sass {

using namespace std;

struct Context;
class Context;

class Remove_Placeholders : public Operation_CRTP<void, Remove_Placeholders> {

Expand Down
21 changes: 11 additions & 10 deletions sass_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstring>
#include <stdexcept>
#include "json.hpp"
#include "copy_c_str.hpp"
#include "context.hpp"
#include "sass_values.h"
#include "sass_context.h"
Expand Down Expand Up @@ -168,7 +169,7 @@ extern "C" {
#define IMPLEMENT_SASS_OPTION_STRING_ACCESSOR(type, option) \
type ADDCALL sass_option_get_##option (struct Sass_Options* options) { return options->option; } \
void ADDCALL sass_option_set_##option (struct Sass_Options* options, type option) \
{ free(options->option); options->option = option ? strdup(option) : 0; }
{ free(options->option); options->option = option ? copy_c_str(option) : 0; }

#define IMPLEMENT_SASS_CONTEXT_GETTER(type, option) \
type ADDCALL sass_context_get_##option (struct Sass_Context* ctx) { return ctx->option; }
Expand All @@ -181,7 +182,7 @@ extern "C" {
return str == NULL ? "" : str;
}

static void copy_strings(const std::vector<std::string>& strings, char*** array, int skip = 0) {
static void copy_strings(const std::vector<std::string>& strings, char*** array, int skip = 0) throw() {
int num = static_cast<int>(strings.size());
char** arr = (char**) malloc(sizeof(char*) * (num + 1));
if (arr == 0) throw(bad_alloc());
Expand Down Expand Up @@ -224,9 +225,9 @@ extern "C" {
json_append_member(json_err, "message", json_mkstring(e.message.c_str()));
msg_stream << e.pstate.path << ":" << e.pstate.line+1 << ": " << e.message << endl;
c_ctx->error_json = json_stringify(json_err, " ");;
c_ctx->error_message = strdup(msg_stream.str().c_str());
c_ctx->error_message = copy_c_str(msg_stream.str().c_str());
c_ctx->error_status = 1;
c_ctx->error_file = strdup(e.pstate.path.c_str());
c_ctx->error_file = copy_c_str(e.pstate.path.c_str());
c_ctx->error_line = e.pstate.line+1;
c_ctx->error_column = e.pstate.column+1;
c_ctx->output_string = 0;
Expand All @@ -240,7 +241,7 @@ extern "C" {
json_append_member(json_err, "status", json_mknumber(2));
json_append_member(json_err, "message", json_mkstring(ba.what()));
c_ctx->error_json = json_stringify(json_err, " ");;
c_ctx->error_message = strdup(msg_stream.str().c_str());
c_ctx->error_message = copy_c_str(msg_stream.str().c_str());
c_ctx->error_status = 2;
c_ctx->output_string = 0;
c_ctx->source_map_string = 0;
Expand All @@ -253,7 +254,7 @@ extern "C" {
json_append_member(json_err, "status", json_mknumber(3));
json_append_member(json_err, "message", json_mkstring(e.what()));
c_ctx->error_json = json_stringify(json_err, " ");;
c_ctx->error_message = strdup(msg_stream.str().c_str());
c_ctx->error_message = copy_c_str(msg_stream.str().c_str());
c_ctx->error_status = 3;
c_ctx->output_string = 0;
c_ctx->source_map_string = 0;
Expand All @@ -266,7 +267,7 @@ extern "C" {
json_append_member(json_err, "status", json_mknumber(4));
json_append_member(json_err, "message", json_mkstring(e.c_str()));
c_ctx->error_json = json_stringify(json_err, " ");;
c_ctx->error_message = strdup(msg_stream.str().c_str());
c_ctx->error_message = copy_c_str(msg_stream.str().c_str());
c_ctx->error_status = 4;
c_ctx->output_string = 0;
c_ctx->source_map_string = 0;
Expand All @@ -279,7 +280,7 @@ extern "C" {
json_append_member(json_err, "status", json_mknumber(5));
json_append_member(json_err, "message", json_mkstring("unknown"));
c_ctx->error_json = json_stringify(json_err, " ");;
c_ctx->error_message = strdup(msg_stream.str().c_str());
c_ctx->error_message = copy_c_str(msg_stream.str().c_str());
c_ctx->error_status = 5;
c_ctx->output_string = 0;
c_ctx->source_map_string = 0;
Expand Down Expand Up @@ -610,7 +611,7 @@ extern "C" {
static void sass_clear_context (struct Sass_Context* ctx)
{
if (ctx == 0) return;
// release the allocated memory (mostly via strdup)
// release the allocated memory (mostly via copy_c_str)
if (ctx->output_string) free(ctx->output_string);
if (ctx->source_map_string) free(ctx->source_map_string);
if (ctx->error_message) free(ctx->error_message);
Expand Down Expand Up @@ -701,7 +702,7 @@ extern "C" {

struct string_list* include_path = (struct string_list*) calloc(1, sizeof(struct string_list));
if (include_path == 0) return;
include_path->string = path ? strdup(path) : 0;
include_path->string = path ? copy_c_str(path) : 0;
struct string_list* last = options->include_paths;
if (!options->include_paths) {
options->include_paths = include_path;
Expand Down
5 changes: 3 additions & 2 deletions sass_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#endif

#include <cstring>
#include "copy_c_str.hpp"
#include "context.hpp"
#include "sass_functions.h"

Expand Down Expand Up @@ -85,8 +86,8 @@ extern "C" {
{
Sass_Import* v = (Sass_Import*) calloc(1, sizeof(Sass_Import));
if (v == 0) return 0;
v->path = path ? strdup(path) : 0;
v->base = base ? strdup(base) : 0;
v->path = path ? Sass::copy_c_str(path) : 0;
v->base = base ? Sass::copy_c_str(base) : 0;
v->source = source;
v->srcmap = srcmap;
return v;
Expand Down
Loading

0 comments on commit fb64dbd

Please sign in to comment.