polserver/pol-core/bscript/compiler/Compiler.h

55 lines
1.7 KiB
C
Raw Permalink Normal View History

#ifndef POLSERVER_COMPILER_H
#define POLSERVER_COMPILER_H
#include <memory>
#include <string>
#include "bscript/compiler/model/UserFunctionInclusion.h"
namespace Pol::Bscript::Compiler
{
class CompiledScript;
class CompilerWorkspace;
class SourceFileCache;
class Profile;
class Report;
class Compiler
{
public:
Compiler( SourceFileCache& em_cache, SourceFileCache& inc_cache, Profile& );
~Compiler();
Compiler( const Compiler& ) = delete;
Compiler& operator=( const Compiler& ) = delete;
bool compile_file( const std::string& filename );
bool write_ecl( const std::string& pathname );
void write_listing( const std::string& pathname );
void write_dbg( const std::string& pathname, bool include_debug_text );
void write_included_filenames( const std::string& pathname );
void set_include_compile_mode();
void compile_file_steps( const std::string& pathname, Report& );
"Preview/Initial"- Version sourcecode formatting feature (#626) * Squash only prettify changes from escript_formating_try * support of "format-off" / "format-on" comments to mark areas without formatting * fix typo * added FormatterIdentLevel, FormatterMergeEmptyLines cfg entry better line splits for dicts/arrays * added several spacing options. the current setting list is now: //LineWidth FormatterLineWidth 80 // keep original keyword spelling FormatterKeepKeywords 0 // number of spaces for ident FormatterIdentLevel 2 // multiple newlines get merged to a single FormatterMergeEmptyLines 1 // space between emtpy parenthesis eg foo() vs foo( ) FormatterEmptyParenthesisSpacing 0 // space between emtpy brackets eg struct{} vs struct{ } FormatterEmptyBracketSpacing 0 // space after/before parenthesis in conditionals // eg if ( true ) vs if (true) FormatterConditionalParenthesisSpacing 1 // space after/before parenthesis // eg foo( true ) vs foo(true) FormatterParenthesisSpacing 1 // space after/before brackets // eg array{ true } vs array{true} FormatterBracketSpacing 1 // add space after delimiter comma or semi in for loops // eg {1, 2, 3} vs {1,2,3} FormatterDelimiterSpacing 1 // add space around assignment // eg a := 1; vs a:=1; FormatterAssignmentSpacing 1 // add space around comparison // eg a == 1 vs a==1 FormatterComparisonSpacing 1 // add space around operations // eg a + 1 vs a+1 FormatterOperatorSpacing 1 // use \r\n as newline instead of \n FormatterWindowsLineEndings 0 * added tab support // use tabs instead of spaces FormatterUseTabs 0 // tab width FormatterTabWidth 4 * extended example ecompile.cfg with formatter settings * cleanup * program args comma is optional... fixed line comments in group splitting * since tokenids are now correct no more guessing for linecomments needed * comments use as start tokenid the whitespace token if its on the same line * splitted processing from linebuilding * renamed TokenPart to FmtToken better matches the purpose. Comments get directly stored as FmtToken started with a context enum * better(?) formatting for groups * fix eof rawlines added check that all comments/rawlines got parsed * const correctness * datatype adapted to antlr * fixed warnings * added InsertNewlineAtEOF * add newline at the end if the original file had one dont strip comment whitespace if its somejind of "header block" use the defined lineending for /* */ comments * docs * \r\n is default on windows \n otherwise * fixed warning --------- Co-authored-by: Kevin Eady <8634912+KevinEady@users.noreply.github.com>
2024-02-26 21:21:44 +01:00
bool format_file( const std::string& filename, bool is_module, bool inplace );
private:
std::unique_ptr<CompilerWorkspace> build_workspace( const std::string&, Report& );
void register_constants( CompilerWorkspace&, Report& );
2020-08-10 04:54:59 -07:00
void optimize( CompilerWorkspace&, Report& );
void disambiguate( CompilerWorkspace&, Report& );
void analyze( CompilerWorkspace&, Report& );
std::unique_ptr<CompiledScript> generate( std::unique_ptr<CompilerWorkspace> );
void display_outcome( const std::string& filename, Report& );
SourceFileCache& em_cache;
SourceFileCache& inc_cache;
Profile& profile;
std::unique_ptr<CompiledScript> output;
UserFunctionInclusion user_function_inclusion = UserFunctionInclusion::ReferencedOnly;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_COMPILER_H