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
parent
ba4fd2d2e0
commit
f2271eb806
|
@ -30,13 +30,13 @@ namespace macro
|
||||||
{
|
{
|
||||||
// A Parent class just for clarity
|
// A Parent class just for clarity
|
||||||
public:
|
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
|
// Directives can be interpreted
|
||||||
virtual void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) = 0;
|
virtual void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class TextNode : public Directive
|
class TextNode : public Directive
|
||||||
{
|
{
|
||||||
// Class for text not interpreted by macroprocessor
|
// Class for text not interpreted by macroprocessor
|
||||||
|
@ -46,16 +46,11 @@ namespace macro
|
||||||
const string text;
|
const string text;
|
||||||
public:
|
public:
|
||||||
TextNode(string text_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
TextNode(string text_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), text{move(text_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; }
|
||||||
}
|
|
||||||
inline void
|
|
||||||
interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override
|
|
||||||
{
|
|
||||||
output << text;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Eval : public Directive
|
class Eval : public Directive
|
||||||
{
|
{
|
||||||
// Class for @{} statements
|
// Class for @{} statements
|
||||||
|
@ -65,36 +60,33 @@ namespace macro
|
||||||
const ExpressionPtr expr;
|
const ExpressionPtr expr;
|
||||||
public:
|
public:
|
||||||
Eval(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Include : public Directive
|
class Include : public Directive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const ExpressionPtr expr;
|
const ExpressionPtr expr;
|
||||||
public:
|
public:
|
||||||
Include(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class IncludePath : public Directive
|
class IncludePath : public Directive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const ExpressionPtr expr;
|
const ExpressionPtr expr;
|
||||||
public:
|
public:
|
||||||
IncludePath(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Define : public Directive
|
class Define : public Directive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -105,18 +97,15 @@ namespace macro
|
||||||
Define(VariablePtr var_arg,
|
Define(VariablePtr var_arg,
|
||||||
ExpressionPtr value_arg,
|
ExpressionPtr value_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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,
|
Define(FunctionPtr func_arg,
|
||||||
ExpressionPtr value_arg,
|
ExpressionPtr value_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Echo : public Directive
|
class Echo : public Directive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -124,12 +113,11 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
Echo(ExpressionPtr expr_arg,
|
Echo(ExpressionPtr expr_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Error : public Directive
|
class Error : public Directive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -137,12 +125,11 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
Error(ExpressionPtr expr_arg,
|
Error(ExpressionPtr expr_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class EchoMacroVars : public Directive
|
class EchoMacroVars : public Directive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -151,17 +138,14 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
EchoMacroVars(bool save_arg,
|
EchoMacroVars(bool save_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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,
|
EchoMacroVars(bool save_arg, vector<string> vars_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class For : public Directive
|
class For : public Directive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -174,12 +158,11 @@ namespace macro
|
||||||
vector<DirectivePtr> statements_arg,
|
vector<DirectivePtr> statements_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), index_vec{move(index_vec_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class If : public Directive
|
class If : public Directive
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -195,33 +178,29 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
If(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
If(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
protected:
|
protected:
|
||||||
void interpretBody(const vector<DirectivePtr> &body, ostream &output, bool no_line_macro, vector<filesystem::path> &paths);
|
void interpretBody(const vector<DirectivePtr> &body, ostream &output, bool no_line_macro, vector<filesystem::path> &paths);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Ifdef : public If
|
class Ifdef : public If
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Ifdef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
Ifdef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Ifndef : public If
|
class Ifndef : public If
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Ifndef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
Ifndef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_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;
|
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,9 +46,7 @@ namespace macro
|
||||||
class TokenizerFlex : public TokenizerFlexLexer
|
class TokenizerFlex : public TokenizerFlexLexer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TokenizerFlex(istream *in) : TokenizerFlexLexer{in}
|
TokenizerFlex(istream *in) : TokenizerFlexLexer{in} { }
|
||||||
{
|
|
||||||
}
|
|
||||||
TokenizerFlex(const TokenizerFlex &) = delete;
|
TokenizerFlex(const TokenizerFlex &) = delete;
|
||||||
TokenizerFlex(TokenizerFlex &&) = delete;
|
TokenizerFlex(TokenizerFlex &&) = delete;
|
||||||
TokenizerFlex &operator=(const TokenizerFlex &) = delete;
|
TokenizerFlex &operator=(const TokenizerFlex &) = delete;
|
||||||
|
@ -71,9 +69,7 @@ namespace macro
|
||||||
stack<vector<DirectivePtr>> directive_stack;
|
stack<vector<DirectivePtr>> directive_stack;
|
||||||
public:
|
public:
|
||||||
Driver(Environment &env_arg, bool no_line_macro_arg) :
|
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(const Driver &) = delete;
|
||||||
Driver(Driver &&) = delete;
|
Driver(Driver &&) = delete;
|
||||||
Driver &operator=(const Driver &) = delete;
|
Driver &operator=(const Driver &) = delete;
|
||||||
|
|
|
@ -34,12 +34,8 @@ namespace macro
|
||||||
map<string, ExpressionPtr> variables;
|
map<string, ExpressionPtr> variables;
|
||||||
map<string, tuple<FunctionPtr, ExpressionPtr>> functions;
|
map<string, tuple<FunctionPtr, ExpressionPtr>> functions;
|
||||||
public:
|
public:
|
||||||
Environment() : parent{nullptr}
|
Environment() : parent{nullptr} { }
|
||||||
{
|
Environment(const Environment *parent_arg) : parent{parent_arg} { }
|
||||||
}
|
|
||||||
Environment(const Environment *parent_arg) : parent{parent_arg}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void define(VariablePtr var, ExpressionPtr value);
|
void define(VariablePtr var, ExpressionPtr value);
|
||||||
void define(FunctionPtr func, ExpressionPtr value);
|
void define(FunctionPtr func, ExpressionPtr value);
|
||||||
ExpressionPtr getVariable(const string &name) const;
|
ExpressionPtr getVariable(const string &name) const;
|
||||||
|
@ -47,24 +43,12 @@ namespace macro
|
||||||
codes::BaseType getType(const string &name);
|
codes::BaseType getType(const string &name);
|
||||||
bool isVariableDefined(const string &name) const noexcept;
|
bool isVariableDefined(const string &name) const noexcept;
|
||||||
bool isFunctionDefined(const string &name) const noexcept;
|
bool isFunctionDefined(const string &name) const noexcept;
|
||||||
inline bool
|
inline bool isSymbolDefined(const string &name) const noexcept { return isVariableDefined(name) || isFunctionDefined(name); }
|
||||||
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 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 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;
|
void printFunction(ostream &output, const tuple<FunctionPtr, ExpressionPtr> &function, int line, bool save) const;
|
||||||
inline size_t
|
inline size_t size() const noexcept { return variables.size() + functions.size(); }
|
||||||
size() const noexcept
|
inline const Environment *getGlobalEnv() const noexcept { return parent == nullptr ? this : parent->getGlobalEnv(); }
|
||||||
{
|
|
||||||
return variables.size() + functions.size();
|
|
||||||
}
|
|
||||||
inline const Environment *
|
|
||||||
getGlobalEnv() const noexcept
|
|
||||||
{
|
|
||||||
return parent == nullptr ? this : parent->getGlobalEnv();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue