Commit graph

64 commits

Author SHA1 Message Date
turleypol
bce1154d7a
ClangTidy readability-else-after-return (#857)
* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-18 09:35:52 +01:00
turleypol
21577d8e5b
Clang Tidy concat namespaces (#855)
* tidy

* Automated clang-tidy change: modernize-concat-nested-namespaces

* compile test

* fix namespace

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-17 10:30:21 +01:00
turleypol
bc9064c338
Clang Tidy default constructor (#852)
* trigger clang tidy

* Automated clang-tidy change: modernize-use-equals-default

* compile test

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
2026-01-15 22:31:14 +01:00
turleypol
ed1b61aab9
Optimize comparison helper class for containers (#826)
* use transparent comparator to optimize away temporary string creation

* missing headers
should be case sensitive compare not insensitive

* flyweightstring support
made it insensitive again
next missing header

* more missing includes :(

* simplified via small wrapper

* allow also char[], removed on caller side some temp object creation which are no longer
needed

* it still only accepts string like objects.. fixed

* switched to strnicmp added comments

* missing header

* fixed comparison

* added unittest
2026-01-02 15:04:19 +01:00
turleypol
fb3faddeae
use c++20 (#799)
* use c++20
* increased used clang version
* compiler report and logfacility use now compile time formatting, which
means that the formatstring gets checked at compile time. (which found 2 errors)
adapted a few places since report only accepts formatting arguments
adapted a few places with logging since char[] is compile time
formatting and string or chr* is runtime formatting
* use std::ranges instead of boost
* disabled pragma_assume vs specific macro (I guess noone cares)
* needed to fix ancient ms exception code
* modernized SpinLock
* removed unused code in ECompile
* replaced std::filesystem::path::u8string with string. It now returns an actual u8string type
* cleanup layers.h added the defines for other layers which where before
  only defined in the pkt
* osmod::OpenConnection and HTTPRequest cleanup: early outs, dont check for pChild which is
  only needed for startscript and placed suspend at the very last
  position

* fix warning

* rebuild cache with new compiler version

* define c++ standard for external libs where possible

* added fixme
2025-08-01 21:40:10 +02:00
turleypol
7090c64840
Short Circuit Optimizer (#797)
* first working short curcuit for && and or
creates jumps after each expressions to skip the following

* fixed valuestack when short circuit jmp does not jump

* use specialized instructions for short circuit && and ||

1: lhs
2: logical jump if false/true goto 4 <- if jmp do logical convert
3: rhs
4: logical convert
5: rest

logical convert is needed since "normal" && || operations convert isTrue
to BLong

added BObjectRef BObjectImp set specialization to remove noise

* fixed converted objimp when jump on false values

* first version of short circuit warning
should be moved to analyzer
added whitelist of module functions which have no sideeffect to reduce
the number of warnings

* moved warning visitor to analyzer and added it as extra compile step
fixed sourceline print and cache the content

* missing include, unused member

* included the correct header

* ecompile.cfg to activate and warn
ecompile cmdline arg to activate it
run all tests also with it active
fixed that only the most right side statement was checked

* ecompile cmdline

* increase ecompile version
cleanup

* compilation error

* missing header

* allow -S- to deactivate shortcircuit like the other params do

* extended whitelist functions

* revert fileformat version increase
fixed escript test cmake

* use the correct arg

* escript testoutput can now be different if shortcircuit is active

* docs

* additional test

* addressed comments
2025-07-28 21:48:34 +02:00
Kevin Eady
87e0c534f4
Add ecompile flag -Z to print AST (#796)
* Add -Z option to print string tree

* Simple test to print an AST

* Make CompiledScript owner of the tree

* some refactoring
- rename ecompile.cfg option
- rename AST generator class

* core-changes, docs

* fix warnings
2025-07-23 23:00:34 +02:00
Jakub Kalita
c94ff9d4cf
Fix directory traversal in ecompile (#757)
* Fix directory traversal in ecompile

* Update core-changes
2025-02-04 19:52:19 +00:00
turleypol
12eabd789f
more dead code from old compiler (#751) 2025-01-23 21:39:16 +01:00
Kevin Eady
ef5931bcc6
Correctly load packages in ecompile (#731) 2024-10-27 11:06:48 +00:00
Kevin Eady
e3512d001b Add scope handling for functions and variables (#690)
* Add Report.debug

* Implement function call scoping

* Implement variable scoping
- Rename `Identifier::scope` to `calling_scope`, and concatenate the identifier scope into `name` if necessary.
- Track current scope in SemanticAnalyzer, similar to UserFunctionVisitor.
- Use current scope in SemanticAnalyzer when visiting identifiers.

* Update grammar for `::identifier` global scoping

* Introduce ScopableName for function resolution

* Address review comments
- Check for display_debugs missing

* Add ScopableName for identifier resolution

* Some cleanup
- Remove `Identifier::calling_scope`, as it is tracked in the semantic
  analyzer
- Refactor `ScopeName::exists` to `global` for better clarification of
  its use
- Removed `X::maybe_scoped_string/name`

* Address self-review comments

* Rename `Function::module_name` to `scope`
2024-10-10 18:06:04 +02:00
turleypol
145eb8185b
fixed missing space when packing funcrefs (#714)
* fixed missing space when packing funcrefs
pack functioncall during group formatting without forcing a newline

* error if resulting format string is empty

* core changes

* do not start a newline when next part is a closing parenthesis during
groupformatting

* pkg loading is again quiet
2024-10-03 15:10:21 +02:00
turleypol
ba9ad6d1d5
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
Kevin Eady
62a252ad3a
Add daemon watch mode to ecompile (#630)
* Add libefsw at 3419347

* saving work

* some cleanup

* move to fs::paths

* saving work.. maybe hitting a limit with number of watched dirs?

* migrate to watching only ecompile.cfg specified folders, cleanup/doc

* Display summary between compilations in watch mode; fix cache reuse

* Fix inf loop; some cmake, format changes...

* some windows compilation fixes... tweaks to windows cmake?

* Update Efsw.cmake for build lib changes

* removed debug flag

* silence efsw build
dont add antlr project if it already exists

* Address review comments:
- use std::move on efswwatcher add_*

* add docs

* Add WatchModeByDefault ecompile.cfg option

* iniital work on tests

* Add CI actions

* some changes (passes locally on win, mac, linux)

* Fix fixtures dependency; use ecompile verbose mode

* Add core-changes

* Send ctrl+c instead of killing process

* Proper Python file naming

* Kill ecompile process on windows, SIGINT otherwise

---------

Co-authored-by: turleypol <turley@polserver.com>
2024-03-16 00:08:06 +01:00
turleypol
7627e3d353
"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
Kevin Eady
593cfffb83
Add uninit, true, false keywords to grammar (#596)
* Update grammar

* Update expression handling for uninit

* update existing tests

* Add new tests

* Remove fullpath from escriptgrammar generation comment

* fix tests

* Update eScript guide

* Declare escript version 0x11

* Add core-changes

* Add `true` and `false` to grammar

* true/false implementation

* Fix existing tests

* Add new tests

* Update core changes

* add docs

* Fix BooleanValue::describe_to

* bool optimizations

* optimize uninit

* remove unused var assignments

* Update grammar for case labels for uninit, booleans

* Fix case label handling for uninit, true, false

* Tests

* Fix compiler version display v1.1700000017881393 -> v1.17

* optimize boolean binary operations

* fix unary boolean optimizer

* add boolean, uninit optimizer test

* Use new fmt lib apis

* Fix compiler warning

* really fix warning lol

* Add Executor[Module]::getParam for bools, FindSubstance test
2024-01-20 05:38:25 +01:00
turleypol
d848deae18
POLLOG* macros use the new formatting (#598)
* POLLOG* macros use the new formatting
removed all old logging functions

* removed old fmt lib from everything except StreamWriter
removed unneeded functions

* fixed review comments
2024-01-16 17:55:42 +01:00
turleypol
0e675c516a
use new formatter for ERROR_PRINT, added ERROR_PRINTLN (#595)
* use new formatter for ERROR_PRINT, added ERROR_PRINTLN

* remove old log define

* fix comments
2024-01-12 06:51:44 +01:00
turleypol
43b776b94d
New format lib version (#592)
* renamed include guard to be able to use both format lib versions in
parallel

* build Fmt lib and link it into clib

* use std::string instead of format Writer for logging
added variant "2" for logging with new fmt lib

* use new logging variant for two logs

* always add \n to flush log, lets see if the assumption holds

* use new lib for tostring

* replaced all INFO_PRINTS in clib

* formatter for Token, BObject and BObjectImp

* started with bsccript

* use function instead of actual object for logging

* remaining bscript, started plib

* logvariant without newline added, more template magic

* format support for base types, added test for format padding
new version for fdump

* chanhed ecompile/runecl fixed compilation with ESCRIPT_PROFILE

* rewrite INFO_PRINT in plib,poltool/uoconvert/uotool

* replaced remaining INFO_PRINTS, renamed macros INFO_PRINT for logging
without newline, INFO_PRINTLN for newline addition.
Replaced also INFO_PRINT_TRACE and renamed it to INFO_PRINTLN_TRACE

* gitignore for fmt lib

* cleanup vim leftovers
2024-01-10 18:29:10 +01:00
Jakub Kalita
b34a9de0e1
Fixed ecompile summary output (#450) 2022-01-16 08:47:34 +01:00
turleypol
0eb6aa624d
use std::filesystem to iterate over directories (#448)
* use std::filesystem to iterate over directories
realms folder can now contain files

* Ignore unix like hidden dir entries

* simplified recursive compilation
2021-12-30 07:21:20 +01:00
Kevin Eady
9c36b977cd
Internal work to remove OGC (#384)
* Remove LegacyFunctionOrder

* Remove compiler.cpp, compiler.h

* Remove parser.cpp/h and wordlist generation

* Update breaking-changes, core-changes
2021-03-06 01:39:26 +01:00
Kevin Eady
ae96ecbf77
Remove OGC from EcompileMain, testsuites (#383)
* Remove OGC from escript testsuite

* Remove compiler options

* Remove Facility::Compiler

* Update docs and options in ecompile help usage

* Update core-changes, breaking-changes
2021-03-04 17:39:14 +01:00
turleypol
e34d4f142c
clang format based stylechecker (#362)
* clang format based stylechecker

* fixed format
2021-02-24 09:50:51 +01:00
Eric Swanson
89d663ca00
Use new compiler (when configured) for compile_inc (#303) 2020-09-13 00:41:45 -07:00
Eric Swanson
1567241871
New compiler: write debug info (.dbg and .dbg.txt) (#302)
Also: OG compiler debug info for foreach iterator changed to match actual variable name

Adds:
- ast/DebugStatementMarker: for "intrusive debug" (ecompile -i) instructions
- codegen/DebugBlockGuard: pushes and pops debug block #
- format/DebugStoreSerializer: writes .dbg and .dbg.txt files
- representation/DebugBlock: holds parent block # and local variable names for each block
- representation/DebugStore: holds all debug information
2020-09-12 14:26:58 -07:00
Eric Swanson
88648186ce
New compiler: include directives (#292) 2020-09-09 19:10:51 -07:00
Eric Swanson
b3bd302785
Add limited support for user functions (#262)
Adds:
- ast/UserFunction AST node for user-defined functions.
- astbuilder/AvailableUserFunction: reference to a parse tree for a user function.
  - The AST builder only generates ASTs for user functions that are actually referenced.
- astbuilder/UserFunctionVisitor: visits (builds an AST for) a parse tree for a user function.
  - This happens after the .src or .inc file has been otherwise processed, so this class serves to hook up the correct SourceFileIdentifier to the AST.
2020-08-31 18:46:27 -07:00
Eric Swanson
86c0efbc21
Build AST nodes for module function declarations (#239)
Adds enough to build the AST nodes for the module function declarations in a .em file.

Adds:

- Function: base class for module function declarations and user functions
- FunctionParameterDeclaration: declaration for a function parameter, as well as its default value if any
- FunctionParameterList: just a holder for function parameter declarations
- ModuleFunctionDeclaration: for function declarations in .em files
- FunctionResolver: hooks up function calls to module functions or user functions
- ModuleProcessor: a visitor for processing const declarations and module function declarations (const declarations are yet to come from the main branch)
2020-08-23 15:01:39 -07:00
Eric Swanson
81331b7200
Add FloatValue (#233) 2020-08-19 19:43:08 +02:00
Eric Swanson
f0f4fc6f9f
Improve SourceFileCache::keep_some() (#226)
* Log cache prune time

* pair, nth_element, no shared ptr, no string copy
2020-08-16 22:59:13 -07:00
Eric Swanson
50e42719b8
Add file/SourceFileCache (#222)
* Add file/SourceFileCache

Co-authored-by: Fernando Rozenblit <rozenblit@gmail.com>
2020-08-16 17:22:16 -07:00
Eric Swanson
303665bcd8
Add error listener, and convert lexer symbols to lowercase (#216)
Add file/ConformingCharStream - converts symbols to lowercase to match grammar

Add file/ErrorListener
2020-08-14 03:28:37 -07:00
Eric Swanson
6b3fdcb263
Add CodeGenerator stub (#206)
* Add codegen/CodeGenerator stub

* Destructor is trivial
2020-08-11 09:08:48 +02:00
Eric Swanson
72bd179051
Add analyzer/Disambiguator stub (#205)
The Disambiguator will correct the AST based on context.

At present, it needs to handle ambiguities in the grammar between
case group selectors and named break/continue labels.
2020-08-11 08:21:34 +02:00
Eric Swanson
d184dda473
Add Optimizer stub (#203) 2020-08-10 13:54:59 +02:00
Eric Swanson
eb6594b4c6
Add ast/NodeVisitor, analyzer/SemanticAnalyzer stubs (#201) 2020-08-10 10:37:07 +02:00
Eric Swanson
2e1870028b
Add model/CompilerWorkspace, astbuilder/BuilderWorkspace, astbuilder/CompilerWorkspaceBuilder (#200)
Add astbuilder/BuilderWorkspace:
  - Temporary workspace used while building the AST (which goes in the CompilerWorkspace)

Add astbuilder/CompilerWorkspaceBuilder:
  - Builds a CompilerWorkspace for a script

Add model/CompilerWorkspace:
  - Holds AST
  - Holds some intermediate data used by semantic analyzer, optimizer, code generator
2020-08-10 09:42:37 +02:00
Eric Swanson
cc28f4f4f2
Add compiler/ Profile and Report (#193)
* Add compiler/Profile

* Add compiler/Report

* From CR notes: add newline on caught exception.
Also added comments that messages should have a newline at the end.
2020-08-08 16:31:55 +02:00
Fernando Rozenblit
af19074ed4
Update to cpp14 (#188)
* use c++14 on linux, visual studio still undefined which means highest
available

* removed make_unique.h due to c++14 no more needed

* stumbled across pre c++14 code

* Removed use of boost::make_unique<> (updated to C++14)

Co-authored-by: turleypol <turley@polserver.com>
2020-08-05 20:28:07 +02:00
Eric Swanson
49ec52beae
Add ecompile mode: compare old and new compiler output (#187)
* Add -G / CompareCompilerOutput ecompile mode that runs old and new compiler and compares output.
Add LegacyFunctionOrder because parity needs to know how the old compiler ordered functions.

* Fix class/struct mixup, add to cmake sources
2020-08-05 09:01:07 +02:00
Eric Swanson
6e8c7ad074
Add stub for new compiler, with -g and UseCompiler2020 options to select. (#184) 2020-08-05 07:42:46 +02:00
Eric Swanson
e5e87a91f5 Use Compiler& rather than pointer 2020-08-04 00:23:08 -07:00
Eric Swanson
a0e681c841 - Add Facility::Compiler interface for both original and new compiler to implement.
- Make original compiler implement
- Alter ECompileMain to use this interface
2020-08-03 23:11:03 -07:00
Eric Swanson
2ee50ffa8b Removed "verbose" boolean; check compilercfg.VerbosityLevel > 0 instead. 2020-08-03 04:17:31 -07:00
Eric Swanson
8b98737829 Move Compiler.verbosity_level_ to CompilerConfig.VerbosityLevel 2020-08-03 00:31:27 -07:00
Eric Swanson
a0c6007079 Move compiler to Legacy namespace 2020-07-28 19:08:50 -07:00
turleypol
59c816cab1 added ecompile.cfg and cmdline flag to trigger error when include
directives use the wrong capitalization. The existing warning will now
lead to an error when warnings get treated as errors.
2019-10-07 21:01:26 +02:00
turleypol
4ac7f227c7 ecompile now writes errors and warnings to stderr.
exit code is 1 when any compilation fails.
2019-10-05 13:19:38 +02:00
turleypol
ea0c533364 fixed leak in compiler and xml filemod
ecompile/runecl no longer try to log to pol logs
activated xml unittest
print stderr on testfailure
2018-12-23 13:55:47 +01:00