Skip to content

Commit

Permalink
[#56] : Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Nov 1, 2020
1 parent fd31d44 commit 8679ae4
Show file tree
Hide file tree
Showing 34 changed files with 168 additions and 173 deletions.
8 changes: 4 additions & 4 deletions demos/reference_language_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ void piranha_demo::ReferenceLanguageRules::registerBuiltinNodeTypes() {
registerBuiltinType<piranha::ConsoleInputNode>("__piranha__console_in");

// Literals
registerLiteralType(piranha::LITERAL_STRING, "__piranha__literal_string");
registerLiteralType(piranha::LITERAL_INT, "__piranha__literal_int");
registerLiteralType(piranha::LITERAL_FLOAT, "__piranha__literal_float");
registerLiteralType(piranha::LITERAL_BOOL, "__piranha__literal_bool");
registerLiteralType(piranha::LiteralType::String, "__piranha__literal_string");
registerLiteralType(piranha::LiteralType::Integer, "__piranha__literal_int");
registerLiteralType(piranha::LiteralType::Float, "__piranha__literal_float");
registerLiteralType(piranha::LiteralType::Boolean, "__piranha__literal_bool");

// Conversions
registerConversion(
Expand Down
3 changes: 2 additions & 1 deletion include/build_settings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PIRANHA_BUILD_SETTINGS_H
#define PIRANHA_BUILD_SETTINGS_H

#define ENABLE_MEMORY_TRACKER 1
#define ENABLE_MEMORY_TRACKER 0
#define STD_ALLOC_ENABLE_LEDGER 0

#endif /* PIRANHA_BUILD_SETTINGS_H */
1 change: 0 additions & 1 deletion include/divide_operation_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ namespace piranha {
} /* namespace piranha */

#endif /* PIRANHA_DIVIDE_OPERATION_OUTPUT_H */

8 changes: 4 additions & 4 deletions include/fundamental_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ namespace piranha {
class FundamentalOutput<piranha::native_float> : public NodeOutput {
public:
FundamentalOutput() : NodeOutput(&FundamentalType::FloatType) {};
~FundamentalOutput() {}
~FundamentalOutput() { /* void */ }
};

template <>
class FundamentalOutput<piranha::native_int> : public NodeOutput {
public:
FundamentalOutput() : NodeOutput(&FundamentalType::IntType) {};
~FundamentalOutput() {}
~FundamentalOutput() { /* void */ }
};

template <>
class FundamentalOutput<piranha::native_bool> : public NodeOutput {
public:
FundamentalOutput() : NodeOutput(&FundamentalType::BoolType) {};
~FundamentalOutput() {}
~FundamentalOutput() { /* void */ }
};

template <>
class FundamentalOutput<piranha::native_string> : public NodeOutput {
public:
FundamentalOutput() : NodeOutput(&FundamentalType::StringType) {};
~FundamentalOutput() {}
~FundamentalOutput() { /* void */ }
};

typedef FundamentalOutput<piranha::native_float> FloatValueOutput;
Expand Down
22 changes: 11 additions & 11 deletions include/fundamental_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ namespace piranha {
typedef int native_int;
typedef vector native_vector;

enum LiteralType {
LITERAL_FLOAT,
LITERAL_BOOL,
LITERAL_STRING,
LITERAL_INT,
LITERAL_UNDEFINED
enum class LiteralType {
Float,
Boolean,
String,
Integer,
Undefined
};

template <typename NativeType>
inline LiteralType LiteralTypeLookup() { static_assert(false, "Looking up a type that does not exist"); return LITERAL_UNDEFINED; };
inline LiteralType LiteralTypeLookup() { static_assert(false, "Looking up a type that does not exist"); return LiteralType::Undefined; };

template <> inline LiteralType LiteralTypeLookup<native_float>() { return LITERAL_FLOAT; }
template <> inline LiteralType LiteralTypeLookup<native_bool>() { return LITERAL_BOOL; }
template <> inline LiteralType LiteralTypeLookup<native_int>() { return LITERAL_INT; }
template <> inline LiteralType LiteralTypeLookup<native_string>() { return LITERAL_STRING; }
template <> inline LiteralType LiteralTypeLookup<native_float>() { return LiteralType::Float; }
template <> inline LiteralType LiteralTypeLookup<native_bool>() { return LiteralType::Boolean; }
template <> inline LiteralType LiteralTypeLookup<native_int>() { return LiteralType::Integer; }
template <> inline LiteralType LiteralTypeLookup<native_string>() { return LiteralType::String; }

template <typename NativeType>
inline const ChannelType *NativeTypeLookup() { static_assert(false, "Looking up a type that does not exist"); return nullptr; }
Expand Down
8 changes: 4 additions & 4 deletions include/ir_compilation_unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace piranha {

class IrCompilationUnit : public IrParserStructure {
public:
enum ParseResult {
IO_ERROR,
SUCCESS,
FAIL
enum class ParseResult {
IoError,
Success,
Fail
};

public:
Expand Down
1 change: 0 additions & 1 deletion include/ir_reference.h

This file was deleted.

30 changes: 15 additions & 15 deletions include/ir_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ namespace piranha {

class IrValue : public IrParserStructure {
public:
enum VALUE_TYPE {
CONSTANT_FLOAT,
CONSTANT_INT,
CONSTANT_STRING,
CONSTANT_LABEL,
CONSTANT_BOOL,

BINARY_OPERATION,
UNARY_OPERATION,

NODE_REF,
INTERNAL_REFERENCE
enum class ValueType {
ConstantFloat,
ConstantInt,
ConstantString,
ConstantLabel,
ConstantBool,

BinaryOperation,
UnaryOperation,

NodeReference,
InternalReference
};

public:
IrValue(VALUE_TYPE type);
IrValue(ValueType type);
virtual ~IrValue();

VALUE_TYPE getType() const { return m_type; }
ValueType getType() const { return m_type; }

private:
VALUE_TYPE m_type;
ValueType m_type;
};

} /* namespace piranha */
Expand Down
20 changes: 10 additions & 10 deletions include/ir_value_constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace piranha {

class IrNode;

template <typename T, IrValue::VALUE_TYPE TypeCode>
template <typename T, IrValue::ValueType TypeCode>
class IrValueConstant : public IrValue {
protected:
typedef T_IrTokenInfo<T> _TokenInfo;
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace piranha {
_TokenInfo m_token;
};

template <typename T, IrValue::VALUE_TYPE TypeCode>
template <typename T, IrValue::ValueType TypeCode>
class IrValueLiteral : public IrValueConstant<T, TypeCode> {
protected:
typedef IrValueConstant<T, TypeCode> Base;
Expand All @@ -95,7 +95,7 @@ namespace piranha {
virtual void _expand(IrContextTree *context) {
if (Base::m_rules == nullptr) return;

std::string builtinType =
const std::string builtinType =
Base::m_rules->resolveLiteralBuiltinType(LiteralTypeLookup<T>());

if (builtinType.empty()) {
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace piranha {
};

// Specialized type for labels
class IrValueLabel : public IrValueConstant<std::string, IrValue::CONSTANT_LABEL> {
class IrValueLabel : public IrValueConstant<std::string, IrValue::ValueType::ConstantLabel> {
public:
IrValueLabel(const _TokenInfo &value) : IrValueConstant(value) { /* void */ }
~IrValueLabel() { /* void */ }
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace piranha {
};

// Specialized type for node references
class IrValueNodeRef : public IrValueConstant<IrNode *, IrValue::NODE_REF> {
class IrValueNodeRef : public IrValueConstant<IrNode *, IrValue::ValueType::NodeReference> {
public:
IrValueNodeRef(const _TokenInfo &value) : IrValueConstant(value) {
registerComponent(value.data);
Expand Down Expand Up @@ -241,7 +241,7 @@ namespace piranha {

// Specialized type for internal structure references (during expansions)
class IrInternalReference
: public IrValueConstant<IrParserStructure *, IrValue::INTERNAL_REFERENCE>
: public IrValueConstant<IrParserStructure *, IrValue::ValueType::InternalReference>
{
public:
IrInternalReference(IrParserStructure *reference, IrContextTree *newContext)
Expand Down Expand Up @@ -284,10 +284,10 @@ namespace piranha {
IrContextTree *m_newContext;
};

typedef IrValueLiteral<piranha::native_int, IrValue::CONSTANT_INT> IrValueInt;
typedef IrValueLiteral<piranha::native_string, IrValue::CONSTANT_STRING> IrValueString;
typedef IrValueLiteral<piranha::native_float, IrValue::CONSTANT_FLOAT> IrValueFloat;
typedef IrValueLiteral<piranha::native_bool, IrValue::CONSTANT_BOOL> IrValueBool;
typedef IrValueLiteral<piranha::native_int, IrValue::ValueType::ConstantInt> IrValueInt;
typedef IrValueLiteral<piranha::native_string, IrValue::ValueType::ConstantString> IrValueString;
typedef IrValueLiteral<piranha::native_float, IrValue::ValueType::ConstantFloat> IrValueFloat;
typedef IrValueLiteral<piranha::native_bool, IrValue::ValueType::ConstantBool> IrValueBool;

} /* namespace piranha */

Expand Down
8 changes: 4 additions & 4 deletions include/language_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ namespace piranha {

template <typename NativeType>
std::string getLiteralBuiltinName() const { return ""; }
template<> std::string getLiteralBuiltinName<piranha::native_bool>() const { return *m_literalRules.lookup(LITERAL_BOOL); }
template<> std::string getLiteralBuiltinName<piranha::native_string>() const { return *m_literalRules.lookup(LITERAL_STRING); }
template<> std::string getLiteralBuiltinName<piranha::native_int>() const { return *m_literalRules.lookup(LITERAL_INT); }
template<> std::string getLiteralBuiltinName<piranha::native_float>() const { return *m_literalRules.lookup(LITERAL_FLOAT); }
template<> std::string getLiteralBuiltinName<piranha::native_bool>() const { return *m_literalRules.lookup(LiteralType::Boolean); }
template<> std::string getLiteralBuiltinName<piranha::native_string>() const { return *m_literalRules.lookup(LiteralType::String); }
template<> std::string getLiteralBuiltinName<piranha::native_int>() const { return *m_literalRules.lookup(LiteralType::Integer); }
template<> std::string getLiteralBuiltinName<piranha::native_float>() const { return *m_literalRules.lookup(LiteralType::Float); }

bool checkConversion(const ChannelType *input, const ChannelType *output) const;
Node *generateConversion(const ChannelType *input, const ChannelType *output);
Expand Down
4 changes: 2 additions & 2 deletions include/memory_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace piranha {
std::string filename;
int line;
int index;
void *address;

bool freed;
void *address = nullptr;
bool freed = false;
};

protected:
Expand Down
9 changes: 4 additions & 5 deletions include/standard_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
#define PIRANHA_STANDARD_ALLOCATOR_H

#include "memory_tracker.h"
#include "build_settings.h"

#include <assert.h>
#include <new>

#include <iostream>

#define STD_ALLOC_ENABLE_LEDGER (true)

namespace piranha {

class StandardAllocator {
Expand All @@ -21,7 +20,7 @@ namespace piranha {

template <typename t_alloc>
t_alloc *allocate(unsigned int n = 1, unsigned int alignment = 1) {
#ifdef STD_ALLOC_ENABLE_LEDGER
#if STD_ALLOC_ENABLE_LEDGER
m_allocationLedger++;
#endif /* STD_ALLOC_ENABLE_LEDGER */

Expand Down Expand Up @@ -58,7 +57,7 @@ namespace piranha {
void free(t_alloc *memory, int n = 1) {
if (memory == nullptr) return;

#ifdef STD_ALLOC_ENABLE_LEDGER
#if STD_ALLOC_ENABLE_LEDGER
m_allocationLedger--;
assert(m_allocationLedger >= 0);
#endif /* STD_ALLOC_ENABLE_LEDGER */
Expand All @@ -78,7 +77,7 @@ namespace piranha {
void aligned_free(t_alloc *memory, int n = 1) {
if (memory == nullptr) return;

#ifdef STD_ALLOC_ENABLE_LEDGER
#if STD_ALLOC_ENABLE_LEDGER
m_allocationLedger--;
assert(m_allocationLedger >= 0);
#endif /* STD_ALLOC_ENABLE_LEDGER */
Expand Down
2 changes: 1 addition & 1 deletion include/vector_split.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace piranha {
template<int index>
class VectorSplitOutput : public FloatValueOutput {
public:
VectorSplitOutput() { /* void */ }
VectorSplitOutput() { m_input = nullptr; }
~VectorSplitOutput() { /* void */ }

virtual void fullCompute(void *_target) const {
Expand Down
1 change: 0 additions & 1 deletion project/piranha/piranha.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ py $(ProjectDir)\..\..\scripts\package_piranha.py $(PlatformTarget) $(Configura
<ClInclude Include="..\..\include\exceptions.h" />
<ClInclude Include="..\..\include\int_conversions.h" />
<ClInclude Include="..\..\include\ir_literal_node.h" />
<ClInclude Include="..\..\include\ir_reference.h" />
<ClInclude Include="..\..\include\key_value_lookup.h" />
<ClInclude Include="..\..\include\language_rules.h" />
<ClInclude Include="..\..\include\node_allocator.h" />
Expand Down
6 changes: 0 additions & 6 deletions project/piranha/piranha.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@
<Filter Include="Source Files\optimization">
<UniqueIdentifier>{3813da9e-a5ca-404c-9c78-ea3d44b60f5e}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\syntax\reference">
<UniqueIdentifier>{6e8d407c-e612-4d90-b24c-623aea7016ce}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\node_output.h">
Expand Down Expand Up @@ -363,9 +360,6 @@
<ClInclude Include="..\..\include\memory_tracker.h">
<Filter>Header Files\memory</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ir_reference.h">
<Filter>Header Files\syntax\reference</Filter>
</ClInclude>
<ClInclude Include="..\..\include\build_settings.h">
<Filter>Header Files\configuration</Filter>
</ClInclude>
Expand Down
3 changes: 2 additions & 1 deletion src/compilation_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "../include/ir_parser_structure.h"

piranha::CompilationError::CompilationError(const IrTokenInfo &location,
const ErrorCode_struct &code, IrContextTree *instantiation) {
const ErrorCode_struct &code, IrContextTree *instantiation)
{
m_errorLocation = location;
m_code = code;
m_instantiation = instantiation;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ piranha::IrCompilationUnit *piranha::Compiler::analyze(const IrPath &scriptPath)
newUnit->setErrorList(&m_errorList);
IrCompilationUnit::ParseResult parseResult = newUnit->parseFile(scriptPath);

if (parseResult == IrCompilationUnit::IO_ERROR) {
if (parseResult == IrCompilationUnit::ParseResult::IoError) {
delete TRACK(newUnit);
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/error_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void piranha::ErrorList::addCompilationError(CompilationError *err) {
}

void piranha::ErrorList::free() {
int errorCount = getErrorCount();
const int errorCount = getErrorCount();

for (int i = 0; i < errorCount; i++) {
delete FTRACK(m_compilationErrors[i]);
Expand Down
4 changes: 2 additions & 2 deletions src/ir_attribute_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ piranha::IrAttributeList::~IrAttributeList() {

void piranha::IrAttributeList::addAttribute(IrAttribute *attribute) {
if (attribute != nullptr) {
int index = getAttributeCount();
const int index = getAttributeCount();

m_attributes.push_back(attribute);
attribute->setPosition(index);
Expand All @@ -25,7 +25,7 @@ void piranha::IrAttributeList::addAttribute(IrAttribute *attribute) {
piranha::IrAttribute *piranha::IrAttributeList::
getAttribute(IrAttributeDefinition *definition) const
{
int attributeCount = getAttributeCount();
const int attributeCount = getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
IrAttribute *attribute = getAttribute(i);
if (attribute->getAttributeDefinition() == definition) {
Expand Down
Loading

0 comments on commit 8679ae4

Please sign in to comment.