polserver/pol-core/bscript/compilercfg.cpp

177 lines
7 KiB
C++
Raw Permalink Normal View History

/** @file
*
* @par History
*/
2015-11-11 00:23:20 +01:00
#include "compilercfg.h"
#include <stdlib.h>
2015-11-11 00:23:20 +01:00
#include "../clib/Program/ProgramConfig.h"
#include "../clib/cfgelem.h"
#include "../clib/cfgfile.h"
2018-01-01 21:49:30 +01:00
#include "../clib/fileutil.h"
2015-11-11 00:23:20 +01:00
namespace Pol::Bscript
{
void CompilerConfig::Read( const std::string& path )
{
"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
#ifdef _WIN32
bool win_platform = true;
#else
bool win_platform = false;
#endif
Clib::ConfigFile cf( path.c_str() );
Clib::ConfigElem elem;
cf.readraw( elem );
PackageRoot.clear();
IncludeDirectory.clear();
std::string tmp;
while ( elem.remove_prop( "PackageRoot", &tmp ) )
{
PackageRoot.push_back( Clib::normalized_dir_form( tmp ) );
}
if ( elem.remove_prop( "IncludeDirectory", &tmp ) )
{
IncludeDirectory = Clib::normalized_dir_form( tmp );
}
ModuleDirectory = Clib::normalized_dir_form( elem.remove_string( "ModuleDirectory" ) );
PolScriptRoot = Clib::normalized_dir_form( elem.remove_string( "PolScriptRoot" ) );
GenerateListing = elem.remove_bool( "GenerateListing", false );
GenerateDebugInfo = elem.remove_bool( "GenerateDebugInfo", false );
GenerateDebugTextInfo = elem.remove_bool( "GenerateDebugTextInfo", false );
GenerateAbstractSyntaxTree = elem.remove_bool( "GenerateAbstractSyntaxTree", false );
VerbosityLevel = elem.remove_int( "VerbosityLevel", 0 );
DisplayWarnings = elem.remove_bool( "DisplayWarnings", false );
CompileAspPages = elem.remove_bool( "CompileAspPages", false );
AutoCompileByDefault = elem.remove_bool( "AutoCompileByDefault", false );
UpdateOnlyOnAutoCompile = elem.remove_bool( "UpdateOnlyOnAutoCompile", false );
OnlyCompileUpdatedScripts = elem.remove_bool( "OnlyCompileUpdatedScripts", false );
WatchModeByDefault = elem.remove_bool( "WatchModeByDefault", false );
DisplaySummary = elem.remove_bool( "DisplaySummary", false );
OptimizeObjectMembers = elem.remove_bool( "OptimizeObjectMembers", true );
ErrorOnWarning = elem.remove_bool( "ErrorOnWarning", false );
GenerateDependencyInfo = elem.remove_bool( "GenerateDependencyInfo", OnlyCompileUpdatedScripts );
DisplayUpToDateScripts = elem.remove_bool( "DisplayUpToDateScripts", true );
ThreadedCompilation = elem.remove_bool( "ThreadedCompilation", false );
NumberOfThreads = elem.remove_int( "NumberOfThreads", 0 );
ParanoiaWarnings = elem.remove_bool( "ParanoiaWarnings", false );
ErrorOnFileCaseMissmatch = elem.remove_bool( "ErrorOnFileCaseMissmatch", false );
EmParseTreeCacheSize = elem.remove_int( "EmParseTreeCacheSize", 25 );
IncParseTreeCacheSize = elem.remove_int( "IncParseTreeCacheSize", 50 );
ShortCircuitEvaluation = elem.remove_bool( "ShortCircuitEvaluation", false );
ShortCircuitEvaluationWarning = elem.remove_bool( "ShortCircuitEvaluationWarning", true );
"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
more formatting improvements (#696) * more formatting improvements: replace inside of comments tabs with spaces if UseTabs is false do not strip whitespaces at the beginning of linecomments better handling of long lines eg string additions "binpack": if an array fits equally into up to 3 lines use this instead of having each element in a newline struct/dicts get only packed if they fit into a single line, or half of the room for two lines align comments in statements * fixed linecomment forcing newline in simple splits formatting of functionexpressions ``` @(blubb) { blah; }; ``` * fixed windows lineendings fixed extra newline before long comment in certain situations added option FormatterFormatInsideComments to deactivate trimming and replacing of tabs * fixed typo.. ecompile cfg is now FormatterIndentLevel * FormatterBracketAttachToType: array{} vs array {} FormatterAllowSingleLines: allow single line case/functionrefs * align case label expressions comments at the end still make the expression packable other bugs * better detection of case labels, by buffering the text. fixed more problems with comments while packing lines * do not allow more then 3 lines to be packed to a single one * fixed hopefully last bug with comments and packing removed FormatterAllowSingleLines added FormatterAlignTrailingComments FormatterAlignConsecutiveShortCaseStatements FormatterAllowShortCaseLabelsOnASingleLine FormatterAllowShortFuncRefsOnASingleLine * better linesplits when prefferedBreak is used (functions with params) * fixed unalign lines with comments in arrays * simplified ecompile code, use callback for compilation during iteration through the directories. use for pkgs recursive_directory_iterator * core-changes * onlinedocs * onlinedocs-typo * corrected cfg * do not touch comments at all when disabled detect aligned */ * fixed group formatting in var statements in more complicated situations * when packing finishes right before the last element check if this element also fit into the last line * remaining ); or similar parts dont start a new line during group formatting * fixed edge cases of preferredBreak tactic with paranthesis alignment * changed defaults, updated docs
2024-09-13 06:49:00 +02:00
FormatterLineWidth = elem.remove_unsigned( "FormatterLineWidth", 100 );
"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
FormatterKeepKeywords = elem.remove_bool( "FormatterKeepKeywords", false );
more formatting improvements (#696) * more formatting improvements: replace inside of comments tabs with spaces if UseTabs is false do not strip whitespaces at the beginning of linecomments better handling of long lines eg string additions "binpack": if an array fits equally into up to 3 lines use this instead of having each element in a newline struct/dicts get only packed if they fit into a single line, or half of the room for two lines align comments in statements * fixed linecomment forcing newline in simple splits formatting of functionexpressions ``` @(blubb) { blah; }; ``` * fixed windows lineendings fixed extra newline before long comment in certain situations added option FormatterFormatInsideComments to deactivate trimming and replacing of tabs * fixed typo.. ecompile cfg is now FormatterIndentLevel * FormatterBracketAttachToType: array{} vs array {} FormatterAllowSingleLines: allow single line case/functionrefs * align case label expressions comments at the end still make the expression packable other bugs * better detection of case labels, by buffering the text. fixed more problems with comments while packing lines * do not allow more then 3 lines to be packed to a single one * fixed hopefully last bug with comments and packing removed FormatterAllowSingleLines added FormatterAlignTrailingComments FormatterAlignConsecutiveShortCaseStatements FormatterAllowShortCaseLabelsOnASingleLine FormatterAllowShortFuncRefsOnASingleLine * better linesplits when prefferedBreak is used (functions with params) * fixed unalign lines with comments in arrays * simplified ecompile code, use callback for compilation during iteration through the directories. use for pkgs recursive_directory_iterator * core-changes * onlinedocs * onlinedocs-typo * corrected cfg * do not touch comments at all when disabled detect aligned */ * fixed group formatting in var statements in more complicated situations * when packing finishes right before the last element check if this element also fit into the last line * remaining ); or similar parts dont start a new line during group formatting * fixed edge cases of preferredBreak tactic with paranthesis alignment * changed defaults, updated docs
2024-09-13 06:49:00 +02:00
FormatterIndentLevel = elem.remove_ushort( "FormatterIndentLevel", 2 );
"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
FormatterMergeEmptyLines = elem.remove_bool( "FormatterMergeEmptyLines", true );
FormatterEmptyParenthesisSpacing = elem.remove_bool( "FormatterEmptyParenthesisSpacing", false );
FormatterEmptyBracketSpacing = elem.remove_bool( "FormatterEmptyBracketSpacing", false );
FormatterConditionalParenthesisSpacing =
elem.remove_bool( "FormatterConditionalParenthesisSpacing", true );
FormatterParenthesisSpacing = elem.remove_bool( "FormatterParenthesisSpacing", true );
FormatterBracketSpacing = elem.remove_bool( "FormatterBracketSpacing", true );
FormatterDelimiterSpacing = elem.remove_bool( "FormatterDelimiterSpacing", true );
FormatterAssignmentSpacing = elem.remove_bool( "FormatterAssignmentSpacing", true );
FormatterComparisonSpacing = elem.remove_bool( "FormatterComparisonSpacing", true );
FormatterEllipsisSpacing = elem.remove_bool( "FormatterEllipsisSpacing", false );
"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
FormatterOperatorSpacing = elem.remove_bool( "FormatterOperatorSpacing", true );
FormatterWindowsLineEndings = elem.remove_bool( "FormatterWindowsLineEndings", win_platform );
FormatterUseTabs = elem.remove_bool( "FormatterUseTabs", false );
FormatterTabWidth = elem.remove_ushort( "FormatterTabWidth", 4 );
more formatting improvements (#696) * more formatting improvements: replace inside of comments tabs with spaces if UseTabs is false do not strip whitespaces at the beginning of linecomments better handling of long lines eg string additions "binpack": if an array fits equally into up to 3 lines use this instead of having each element in a newline struct/dicts get only packed if they fit into a single line, or half of the room for two lines align comments in statements * fixed linecomment forcing newline in simple splits formatting of functionexpressions ``` @(blubb) { blah; }; ``` * fixed windows lineendings fixed extra newline before long comment in certain situations added option FormatterFormatInsideComments to deactivate trimming and replacing of tabs * fixed typo.. ecompile cfg is now FormatterIndentLevel * FormatterBracketAttachToType: array{} vs array {} FormatterAllowSingleLines: allow single line case/functionrefs * align case label expressions comments at the end still make the expression packable other bugs * better detection of case labels, by buffering the text. fixed more problems with comments while packing lines * do not allow more then 3 lines to be packed to a single one * fixed hopefully last bug with comments and packing removed FormatterAllowSingleLines added FormatterAlignTrailingComments FormatterAlignConsecutiveShortCaseStatements FormatterAllowShortCaseLabelsOnASingleLine FormatterAllowShortFuncRefsOnASingleLine * better linesplits when prefferedBreak is used (functions with params) * fixed unalign lines with comments in arrays * simplified ecompile code, use callback for compilation during iteration through the directories. use for pkgs recursive_directory_iterator * core-changes * onlinedocs * onlinedocs-typo * corrected cfg * do not touch comments at all when disabled detect aligned */ * fixed group formatting in var statements in more complicated situations * when packing finishes right before the last element check if this element also fit into the last line * remaining ); or similar parts dont start a new line during group formatting * fixed edge cases of preferredBreak tactic with paranthesis alignment * changed defaults, updated docs
2024-09-13 06:49:00 +02:00
FormatterInsertNewlineAtEOF = elem.remove_bool( "FormatterInsertNewlineAtEOF", true );
FormatterFormatInsideComments = elem.remove_bool( "FormatterFormatInsideComments", true );
FormatterBracketAttachToType = elem.remove_bool( "FormatterBracketAttachToType", true );
FormatterAlignTrailingComments = elem.remove_bool( "FormatterAlignTrailingComments", true );
FormatterAlignConsecutiveShortCaseStatements =
elem.remove_bool( "FormatterAlignConsecutiveShortCaseStatements", true );
FormatterAllowShortCaseLabelsOnASingleLine =
elem.remove_bool( "FormatterAllowShortCaseLabelsOnASingleLine", true );
FormatterAllowShortFuncRefsOnASingleLine =
elem.remove_bool( "FormatterAllowShortFuncRefsOnASingleLine", true );
"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
more formatting improvements (#696) * more formatting improvements: replace inside of comments tabs with spaces if UseTabs is false do not strip whitespaces at the beginning of linecomments better handling of long lines eg string additions "binpack": if an array fits equally into up to 3 lines use this instead of having each element in a newline struct/dicts get only packed if they fit into a single line, or half of the room for two lines align comments in statements * fixed linecomment forcing newline in simple splits formatting of functionexpressions ``` @(blubb) { blah; }; ``` * fixed windows lineendings fixed extra newline before long comment in certain situations added option FormatterFormatInsideComments to deactivate trimming and replacing of tabs * fixed typo.. ecompile cfg is now FormatterIndentLevel * FormatterBracketAttachToType: array{} vs array {} FormatterAllowSingleLines: allow single line case/functionrefs * align case label expressions comments at the end still make the expression packable other bugs * better detection of case labels, by buffering the text. fixed more problems with comments while packing lines * do not allow more then 3 lines to be packed to a single one * fixed hopefully last bug with comments and packing removed FormatterAllowSingleLines added FormatterAlignTrailingComments FormatterAlignConsecutiveShortCaseStatements FormatterAllowShortCaseLabelsOnASingleLine FormatterAllowShortFuncRefsOnASingleLine * better linesplits when prefferedBreak is used (functions with params) * fixed unalign lines with comments in arrays * simplified ecompile code, use callback for compilation during iteration through the directories. use for pkgs recursive_directory_iterator * core-changes * onlinedocs * onlinedocs-typo * corrected cfg * do not touch comments at all when disabled detect aligned */ * fixed group formatting in var statements in more complicated situations * when packing finishes right before the last element check if this element also fit into the last line * remaining ); or similar parts dont start a new line during group formatting * fixed edge cases of preferredBreak tactic with paranthesis alignment * changed defaults, updated docs
2024-09-13 06:49:00 +02:00
// This is where we TRY to validate full paths from what was provided in the
// ecompile.cfg. Maybe Turley or Shini can find the best way to do this in *nix.
2015-11-11 00:23:20 +01:00
#ifdef WIN32
std::string MyPath = path.c_str();
// If it's just "ecompile.cfg", let's change it to the exe's path which it SHOULD be
// with.
if ( stricmp( MyPath.c_str(), "ecompile.cfg" ) == 0 )
{
std::string workingDir = PROG_CONFIG::programDir();
// Let's find the NEXT-TO-LAST / in the path, and remove from there on. Oh yay!
// To bad we can't just force everyone to use ABSOLUTE PATHS NANDO. :o
MyPath = workingDir.substr( 0, workingDir.length() - 1 );
MyPath = MyPath.substr( 0, MyPath.find_last_of( '/' ) + 1 );
}
if ( IncludeDirectory.find( ':' ) == std::string::npos )
{
if ( IncludeDirectory.substr( 0, 1 ) !=
"." ) // Let's make sure they didn't try using this method
{
IncludeDirectory = MyPath + IncludeDirectory;
}
}
if ( ModuleDirectory.find( ':' ) == std::string::npos )
{
if ( ModuleDirectory.substr( 0, 1 ) !=
"." ) // Let's make sure they didn't try using this method
{
ModuleDirectory = MyPath + ModuleDirectory;
}
}
if ( PolScriptRoot.find( ':' ) == std::string::npos )
{
if ( PolScriptRoot.substr( 0, 1 ) != "." ) // Let's make sure they didn't try using this method
{
PolScriptRoot = MyPath + PolScriptRoot;
}
}
for ( unsigned pr = 0; pr < PackageRoot.size(); ++pr )
{
if ( PackageRoot[pr].find( ':' ) == std::string::npos )
{
if ( PackageRoot[pr].substr( 0, 1 ) !=
"." ) // Let's make sure they didn't try using this method
{
PackageRoot[pr] = MyPath + PackageRoot[pr];
}
}
}
2015-11-11 00:23:20 +01:00
#endif
}
2015-11-11 00:23:20 +01:00
void CompilerConfig::SetDefaults()
{
const char* tmp;
2015-11-11 00:23:20 +01:00
tmp = getenv( "ECOMPILE_PATH_EM" );
ModuleDirectory = tmp ? Clib::normalized_dir_form( tmp ) : PROG_CONFIG::programDir();
2015-11-11 00:23:20 +01:00
tmp = getenv( "ECOMPILE_PATH_INC" );
IncludeDirectory = tmp ? Clib::normalized_dir_form( tmp ) : PROG_CONFIG::programDir();
2015-11-11 00:23:20 +01:00
PolScriptRoot = IncludeDirectory;
2015-11-11 00:23:20 +01:00
DisplayUpToDateScripts = true;
EmParseTreeCacheSize = 25;
IncParseTreeCacheSize = 50;
}
2015-11-11 00:23:20 +01:00
CompilerConfig compilercfg;
} // namespace Pol::Bscript