Partial reversion of global indentation of macro processor header files introduced in e2d5a83592

The global indentation introduced in e2d5a83592 made the macro processor header files difficult to read. Revert spacing changes that made simple, inline, one-line functions take up 5 lines making headers tougher to read. Similary change for constructors, not to place each brace on an individual line.
issue#70
Houtan Bastani 2019-12-23 19:08:51 +01:00
parent ba4fd2d2e0
commit f2271eb806
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
4 changed files with 243 additions and 911 deletions

View File

@ -30,13 +30,13 @@ namespace macro
{
// A Parent class just for clarity
public:
Directive(Environment &env_arg, Tokenizer::location location_arg) : Node(env_arg, move(location_arg))
{
}
Directive(Environment &env_arg, Tokenizer::location location_arg) :
Node(env_arg, move(location_arg)) { }
// Directives can be interpreted
virtual void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) = 0;
};
class TextNode : public Directive
{
// Class for text not interpreted by macroprocessor
@ -46,16 +46,11 @@ namespace macro
const string text;
public:
TextNode(string text_arg, Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), text{move(text_arg)}
{
}
inline void
interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override
{
output << text;
}
Directive(env_arg, move(location_arg)), text{move(text_arg)} { }
inline void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override { output << text; }
};
class Eval : public Directive
{
// Class for @{} statements
@ -65,36 +60,33 @@ namespace macro
const ExpressionPtr expr;
public:
Eval(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr{move(expr_arg)}
{
}
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class Include : public Directive
{
private:
const ExpressionPtr expr;
public:
Include(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr{move(expr_arg)}
{
}
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class IncludePath : public Directive
{
private:
const ExpressionPtr expr;
public:
IncludePath(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr{move(expr_arg)}
{
}
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class Define : public Directive
{
private:
@ -105,18 +97,15 @@ namespace macro
Define(VariablePtr var_arg,
ExpressionPtr value_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), var{move(var_arg)}, value{move(value_arg)}
{
}
Directive(env_arg, move(location_arg)), var{move(var_arg)}, value{move(value_arg)} { }
Define(FunctionPtr func_arg,
ExpressionPtr value_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), func{move(func_arg)}, value{move(value_arg)}
{
}
Directive(env_arg, move(location_arg)), func{move(func_arg)}, value{move(value_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class Echo : public Directive
{
private:
@ -124,12 +113,11 @@ namespace macro
public:
Echo(ExpressionPtr expr_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr{move(expr_arg)}
{
}
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class Error : public Directive
{
private:
@ -137,12 +125,11 @@ namespace macro
public:
Error(ExpressionPtr expr_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr{move(expr_arg)}
{
}
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class EchoMacroVars : public Directive
{
private:
@ -151,17 +138,14 @@ namespace macro
public:
EchoMacroVars(bool save_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), save{save_arg}
{
}
Directive(env_arg, move(location_arg)), save{save_arg} { }
EchoMacroVars(bool save_arg, vector<string> vars_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), save{save_arg}, vars{move(vars_arg)}
{
}
Directive(env_arg, move(location_arg)), save{save_arg}, vars{move(vars_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class For : public Directive
{
private:
@ -174,12 +158,11 @@ namespace macro
vector<DirectivePtr> statements_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), index_vec{move(index_vec_arg)},
index_vals{move(index_vals_arg)}, statements{move(statements_arg)}
{
}
index_vals{move(index_vals_arg)}, statements{move(statements_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class If : public Directive
{
protected:
@ -195,33 +178,29 @@ namespace macro
public:
If(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr_and_body{move(expr_and_body_arg)}
{
}
Directive(env_arg, move(location_arg)), expr_and_body{move(expr_and_body_arg)} { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
protected:
void interpretBody(const vector<DirectivePtr> &body, ostream &output, bool no_line_macro, vector<filesystem::path> &paths);
};
class Ifdef : public If
{
public:
Ifdef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
Environment &env_arg, Tokenizer::location location_arg) :
If(move(expr_and_body_arg), env_arg, move(location_arg))
{
}
If(move(expr_and_body_arg), env_arg, move(location_arg)) { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
class Ifndef : public If
{
public:
Ifndef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
Environment &env_arg, Tokenizer::location location_arg) :
If(move(expr_and_body_arg), env_arg, move(location_arg))
{
}
If(move(expr_and_body_arg), env_arg, move(location_arg)) { }
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
};
}

View File

@ -46,9 +46,7 @@ namespace macro
class TokenizerFlex : public TokenizerFlexLexer
{
public:
TokenizerFlex(istream *in) : TokenizerFlexLexer{in}
{
}
TokenizerFlex(istream *in) : TokenizerFlexLexer{in} { }
TokenizerFlex(const TokenizerFlex &) = delete;
TokenizerFlex(TokenizerFlex &&) = delete;
TokenizerFlex &operator=(const TokenizerFlex &) = delete;
@ -71,9 +69,7 @@ namespace macro
stack<vector<DirectivePtr>> directive_stack;
public:
Driver(Environment &env_arg, bool no_line_macro_arg) :
env{env_arg}, no_line_macro(no_line_macro_arg)
{
}
env{env_arg}, no_line_macro(no_line_macro_arg) { }
Driver(const Driver &) = delete;
Driver(Driver &&) = delete;
Driver &operator=(const Driver &) = delete;

View File

@ -34,12 +34,8 @@ namespace macro
map<string, ExpressionPtr> variables;
map<string, tuple<FunctionPtr, ExpressionPtr>> functions;
public:
Environment() : parent{nullptr}
{
}
Environment(const Environment *parent_arg) : parent{parent_arg}
{
}
Environment() : parent{nullptr} { }
Environment(const Environment *parent_arg) : parent{parent_arg} { }
void define(VariablePtr var, ExpressionPtr value);
void define(FunctionPtr func, ExpressionPtr value);
ExpressionPtr getVariable(const string &name) const;
@ -47,24 +43,12 @@ namespace macro
codes::BaseType getType(const string &name);
bool isVariableDefined(const string &name) const noexcept;
bool isFunctionDefined(const string &name) const noexcept;
inline bool
isSymbolDefined(const string &name) const noexcept
{
return isVariableDefined(name) || isFunctionDefined(name);
}
inline bool isSymbolDefined(const string &name) const noexcept { return isVariableDefined(name) || isFunctionDefined(name); }
void print(ostream &output, const vector<string> &vars, int line = -1, bool save = false) const;
void printVariable(ostream &output, const string &name, int line, bool save) const;
void printFunction(ostream &output, const tuple<FunctionPtr, ExpressionPtr> &function, int line, bool save) const;
inline size_t
size() const noexcept
{
return variables.size() + functions.size();
}
inline const Environment *
getGlobalEnv() const noexcept
{
return parent == nullptr ? this : parent->getGlobalEnv();
}
inline size_t size() const noexcept { return variables.size() + functions.size(); }
inline const Environment *getGlobalEnv() const noexcept { return parent == nullptr ? this : parent->getGlobalEnv(); }
};
}
#endif

File diff suppressed because it is too large Load Diff