forked from jasder/antlr
VS solution update + compile fixes after latest changes.
This commit is contained in:
parent
7b030d601f
commit
185e956f9e
|
@ -21,7 +21,7 @@ using namespace org::antlr::v4::runtime;
|
|||
|
||||
int main(int argc, const char * argv[]) {
|
||||
|
||||
ANTLRInputStream input(L"divideŴ and conquer");
|
||||
ANTLRInputStream input(L"x * y + z");
|
||||
TLexer lexer(&input);
|
||||
CommonTokenStream tokens(&lexer);
|
||||
|
||||
|
|
|
@ -161,6 +161,7 @@
|
|||
<ClCompile Include="..\..\runtime\ANTLRInputStream.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\AbstractPredicateTransition.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ActionTransition.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\AmbiguityInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ArrayPredictionContext.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ATN.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ATNConfig.cpp" />
|
||||
|
@ -177,22 +178,42 @@
|
|||
<ClCompile Include="..\..\runtime\atn\BlockEndState.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\BlockStartState.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ConfigLookup.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ContextSensitivityInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\DecisionEventInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\DecisionInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\DecisionState.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\EmptyPredictionContext.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\EpsilonTransition.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ErrorInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerActionExecutor.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerActionType.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerATNConfig.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerATNSimulator.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerChannelAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerCustomAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerIndexedCustomAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerModeAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerMoreAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerPopModeAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerPushModeAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerSkipAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LexerTypeAction.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LL1Analyzer.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LookaheadEventInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\LoopEndState.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\NotSetTransition.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\OrderedATNConfigSet.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ParseInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ParserATNSimulator.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\PlusBlockStartState.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\PlusLoopbackState.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\PrecedencePredicateTransition.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\PredicateEvalInfo.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\PredicateTransition.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\PredictionContext.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\PredictionMode.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\ProfilingATNSimulator.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\RangeTransition.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\RuleStartState.cpp" />
|
||||
<ClCompile Include="..\..\runtime\atn\RuleStopState.cpp" />
|
||||
|
@ -232,7 +253,7 @@
|
|||
<ClCompile Include="..\..\runtime\misc\Interval.cpp" />
|
||||
<ClCompile Include="..\..\runtime\misc\IntervalSet.cpp" />
|
||||
<ClCompile Include="..\..\runtime\misc\MurmurHash.cpp" />
|
||||
<ClCompile Include="..\..\runtime\misc\TestRig.cpp" />
|
||||
<ClCompile Include="..\..\runtime\misc\Predicate.cpp" />
|
||||
<ClCompile Include="..\..\runtime\NoViableAltException.cpp" />
|
||||
<ClCompile Include="..\..\runtime\Parser.cpp" />
|
||||
<ClCompile Include="..\..\runtime\ParserInterpreter.cpp" />
|
||||
|
@ -274,6 +295,7 @@
|
|||
<ClCompile Include="..\..\runtime\tree\Trees.cpp" />
|
||||
<ClCompile Include="..\..\runtime\UnbufferedCharStream.cpp" />
|
||||
<ClCompile Include="..\..\runtime\UnbufferedTokenStream.cpp" />
|
||||
<ClCompile Include="..\..\runtime\VocabularyImpl.cpp" />
|
||||
<ClCompile Include="..\..\runtime\WritableToken.cpp" />
|
||||
<ClCompile Include="antlrcpp-Prefix.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
|
@ -290,6 +312,7 @@
|
|||
<ClInclude Include="..\..\runtime\ANTLRInputStream.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\AbstractPredicateTransition.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ActionTransition.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\AmbiguityInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ArrayPredictionContext.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ATN.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ATNConfig.h" />
|
||||
|
@ -306,22 +329,42 @@
|
|||
<ClInclude Include="..\..\runtime\atn\BlockEndState.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\BlockStartState.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ConfigLookup.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ContextSensitivityInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\DecisionEventInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\DecisionInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\DecisionState.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\EmptyPredictionContext.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\EpsilonTransition.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ErrorInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerActionExecutor.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerActionType.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerATNConfig.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerATNSimulator.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerChannelAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerCustomAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerIndexedCustomAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerModeAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerMoreAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerPopModeAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerPushModeAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerSkipAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LexerTypeAction.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LL1Analyzer.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LookaheadEventInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\LoopEndState.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\NotSetTransition.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\OrderedATNConfigSet.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ParseInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ParserATNSimulator.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\PlusBlockStartState.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\PlusLoopbackState.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\PrecedencePredicateTransition.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\PredicateEvalInfo.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\PredicateTransition.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\PredictionContext.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\PredictionMode.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\ProfilingATNSimulator.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\RangeTransition.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\RuleStartState.h" />
|
||||
<ClInclude Include="..\..\runtime\atn\RuleStopState.h" />
|
||||
|
@ -362,6 +405,7 @@
|
|||
<ClInclude Include="..\..\runtime\misc\Interval.h" />
|
||||
<ClInclude Include="..\..\runtime\misc\IntervalSet.h" />
|
||||
<ClInclude Include="..\..\runtime\misc\MurmurHash.h" />
|
||||
<ClInclude Include="..\..\runtime\misc\Predicate.h" />
|
||||
<ClInclude Include="..\..\runtime\misc\TestRig.h" />
|
||||
<ClInclude Include="..\..\runtime\NoViableAltException.h" />
|
||||
<ClInclude Include="..\..\runtime\Parser.h" />
|
||||
|
@ -407,6 +451,8 @@
|
|||
<ClInclude Include="..\..\runtime\tree\xpath\XPathLexer.h" />
|
||||
<ClInclude Include="..\..\runtime\UnbufferedCharStream.h" />
|
||||
<ClInclude Include="..\..\runtime\UnbufferedTokenStream.h" />
|
||||
<ClInclude Include="..\..\runtime\Vocabulary.h" />
|
||||
<ClInclude Include="..\..\runtime\VocabularyImpl.h" />
|
||||
<ClInclude Include="..\..\runtime\WritableToken.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -430,6 +430,78 @@
|
|||
<ClInclude Include="..\..\runtime\tree\xpath\XPathLexer.h">
|
||||
<Filter>Header Files\tree\xpath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\Vocabulary.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\VocabularyImpl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\AmbiguityInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\ContextSensitivityInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\DecisionEventInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\DecisionInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\ErrorInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerActionExecutor.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerActionType.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerChannelAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerCustomAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerIndexedCustomAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerModeAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerMoreAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerPopModeAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerPushModeAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerSkipAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LexerTypeAction.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\LookaheadEventInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\ParseInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\PredicateEvalInfo.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\atn\ProfilingATNSimulator.h">
|
||||
<Filter>Header Files\atn</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\runtime\misc\Predicate.h">
|
||||
<Filter>Header Files\misc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="antlrcpp-Prefix.cpp" />
|
||||
|
@ -712,9 +784,6 @@
|
|||
<ClCompile Include="..\..\runtime\misc\MurmurHash.cpp">
|
||||
<Filter>Source Files\misc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\misc\TestRig.cpp">
|
||||
<Filter>Source Files\misc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\support\Arrays.cpp">
|
||||
<Filter>Source Files\support</Filter>
|
||||
</ClCompile>
|
||||
|
@ -793,5 +862,74 @@
|
|||
<ClCompile Include="..\..\runtime\tree\pattern\TokenTagToken.cpp">
|
||||
<Filter>Source Files\tree\pattern</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\VocabularyImpl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\AmbiguityInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\ContextSensitivityInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\DecisionEventInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\DecisionInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\ErrorInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerActionExecutor.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerActionType.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerChannelAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerCustomAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerIndexedCustomAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerModeAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerMoreAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerPopModeAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerPushModeAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerSkipAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LexerTypeAction.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\LookaheadEventInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\ParseInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\PredicateEvalInfo.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\atn\ProfilingATNSimulator.cpp">
|
||||
<Filter>Source Files\atn</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\runtime\misc\Predicate.cpp">
|
||||
<Filter>Source Files\misc</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,10 +1,11 @@
|
|||
@echo off
|
||||
:: Created 2016, Mike Lischke (public domain)
|
||||
|
||||
:: This script is used to generate source files from the test grammars in the same folder. The generated files are placed
|
||||
:: into a subfolder "generated" which the demo project uses to compile a demo binary.
|
||||
|
||||
set LOCATION=antlr-4.1.1-dev-complete.jar
|
||||
::java -jar %LOCATION% -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
set LOCATION=antlr4-4.5.4-SNAPSHOT.jar
|
||||
java -jar %LOCATION% -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
::java -jar %LOCATION% -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4
|
||||
java -jar %LOCATION% -Dlanguage=Java -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
::java -jar %LOCATION% -Dlanguage=Java -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ Ref<Vocabulary> VocabularyImpl::fromTokenNames(const std::vector<std::wstring> &
|
|||
|
||||
std::vector<std::wstring> literalNames = tokenNames;
|
||||
std::vector<std::wstring> symbolicNames = tokenNames;
|
||||
std::locale locale;
|
||||
for (size_t i = 0; i < tokenNames.size(); i++) {
|
||||
std::wstring tokenName = tokenNames[i];
|
||||
if (tokenName == L"") {
|
||||
|
@ -67,7 +68,7 @@ Ref<Vocabulary> VocabularyImpl::fromTokenNames(const std::vector<std::wstring> &
|
|||
if (firstChar == L'\'') {
|
||||
symbolicNames[i] = L"";
|
||||
continue;
|
||||
} else if (std::isupper(firstChar)) {
|
||||
} else if (std::isupper(firstChar, locale)) {
|
||||
literalNames[i] = L"";
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "LexerActionExecutor.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
using namespace antlrcpp;
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "LexerCustomAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "LexerIndexedCustomAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "LexerModeAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "LexerMoreAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "LexerPopModeAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "LexerPushModeAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "LexerSkipAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "LexerTypeAction.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::misc;
|
||||
|
||||
|
|
|
@ -110,16 +110,16 @@ long long ParseInfo::getTotalATNLookaheadOps() {
|
|||
return k;
|
||||
}
|
||||
|
||||
int ParseInfo::getDFASize() {
|
||||
int n = 0;
|
||||
size_t ParseInfo::getDFASize() {
|
||||
size_t n = 0;
|
||||
std::vector<dfa::DFA> decisionToDFA = _atnSimulator->decisionToDFA;
|
||||
for (size_t i = 0; i < decisionToDFA.size(); ++i) {
|
||||
n += getDFASize((int)i);
|
||||
n += getDFASize(i);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ParseInfo::getDFASize(int decision) {
|
||||
size_t ParseInfo::getDFASize(size_t decision) {
|
||||
dfa::DFA &decisionToDFA = _atnSimulator->decisionToDFA[decision];
|
||||
return decisionToDFA.states.size();
|
||||
}
|
||||
|
|
|
@ -111,13 +111,13 @@ namespace atn {
|
|||
/// Gets the total number of DFA states stored in the DFA cache for all
|
||||
/// decisions in the ATN.
|
||||
/// </summary>
|
||||
virtual int getDFASize();
|
||||
virtual size_t getDFASize();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of DFA states stored in the DFA cache for a
|
||||
/// particular decision.
|
||||
/// </summary>
|
||||
virtual size_t getDFASize(int decision);
|
||||
virtual size_t getDFASize(size_t decision);
|
||||
|
||||
protected:
|
||||
const ProfilingATNSimulator *_atnSimulator; // non-owning, we are created by this simulator.
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include "ProfilingATNSimulator.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
using namespace org::antlr::v4::runtime::dfa;
|
||||
using namespace antlrcpp;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "TerminalNodeImpl.h"
|
||||
#include "ATN.h"
|
||||
#include "Interval.h"
|
||||
#include "Token.h"
|
||||
#include "CommonToken.h"
|
||||
#include "Predicate.h"
|
||||
|
||||
|
@ -231,7 +232,7 @@ void Trees::stripChildrenOutOfRange(Ref<ParserRuleContext> t, Ref<ParserRuleCont
|
|||
Interval range = child->getSourceInterval();
|
||||
if (is<ParserRuleContext>(child) && (range.b < (int)startIndex || range.a > (int)stopIndex)) {
|
||||
if (isAncestorOf(child, root)) { // replace only if subtree doesn't have displayed root
|
||||
Ref<CommonToken> abbrev = std::make_shared<CommonToken>(Token::INVALID_TYPE, L"...");
|
||||
Ref<CommonToken> abbrev = std::make_shared<CommonToken>((int)Token::INVALID_TYPE, L"...");
|
||||
t->children[i] = std::make_shared<TerminalNodeImpl>(abbrev);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "TerminalNode.h"
|
||||
#include "ParserRuleContext.h"
|
||||
#include "Recognizer.h"
|
||||
#include "Token.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
#include "BasicFontMetrics.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
double BasicFontMetrics::getWidth(const std::wstring &s, int fontSize) {
|
||||
double w = 0;
|
||||
for (auto c : s.toCharArray()) {
|
||||
w += getWidth(c, fontSize);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
double BasicFontMetrics::getWidth(wchar_t c, int fontSize) {
|
||||
if (c > MAX_CHAR || widths[c] == 0) { // return width('m')
|
||||
return widths[L'm'] / 1000.0;
|
||||
}
|
||||
return widths[c] / 1000.0 * fontSize;
|
||||
}
|
||||
|
||||
double BasicFontMetrics::getLineHeight(int fontSize) {
|
||||
return maxCharHeight / 1000.0 * fontSize;
|
||||
}
|
||||
|
||||
void BasicFontMetrics::InitializeInstanceFields() {
|
||||
maxCharHeight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
/// <summary>
|
||||
/// Font metrics. The only way to generate accurate images
|
||||
/// in any format that contain text is to know the font metrics.
|
||||
/// Specifically, we need to know the width of every character and the
|
||||
/// maximum height (since we want all characters to fit within same line height).
|
||||
/// I used ttf2tfm to dump the font metrics from Mac TrueType fonts and
|
||||
/// then converted that to a Java class for use in a PostScript generator
|
||||
/// for trees. Commands:
|
||||
///
|
||||
/// <pre>
|
||||
/// $ ttf2tfm /Library/Fonts/Arial\ Black.ttf > metrics
|
||||
/// </pre>
|
||||
///
|
||||
/// Then run metrics into python code after stripping header/footer:
|
||||
///
|
||||
/// <pre>
|
||||
/// #
|
||||
/// # Process lines from ttf2tfm that look like this:
|
||||
/// # Glyph Code Glyph Name Width llx lly urx ury
|
||||
/// # ------------------------------------------------------------------------
|
||||
/// # 3 00020 space 333 0, 0 -- 0, 0
|
||||
/// #
|
||||
/// lines = open("metrics").read().split('\n')
|
||||
/// print "public class FontName {"
|
||||
/// print " {"
|
||||
/// maxh = 0;
|
||||
/// for line in lines[4:]: # skip header 0..3
|
||||
/// all = line.split(' ')
|
||||
/// words = [x for x in all if len(x)>0]
|
||||
/// ascii = int(words[1], 16)
|
||||
/// height = int(words[8])
|
||||
/// if height>maxh: maxh = height
|
||||
/// if ascii>=128: break
|
||||
/// print " widths[%d] = %s; // %s" % (ascii, words[3], words[2])
|
||||
///
|
||||
/// print " maxCharHeight = "+str(maxh)+";"
|
||||
/// print " }"
|
||||
/// print "}"
|
||||
/// </pre>
|
||||
///
|
||||
/// Units are 1000th of an 'em'.
|
||||
/// </summary>
|
||||
class BasicFontMetrics {
|
||||
public:
|
||||
static const int MAX_CHAR = L'\u00FF';
|
||||
protected:
|
||||
int maxCharHeight;
|
||||
int widths[MAX_CHAR + 1];
|
||||
|
||||
public:
|
||||
virtual double getWidth(const std::wstring &s, int fontSize);
|
||||
|
||||
virtual double getWidth(wchar_t c, int fontSize);
|
||||
|
||||
virtual double getLineHeight(int fontSize);
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
|
||||
public:
|
||||
BasicFontMetrics() {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
#include "PostScriptDocument.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
const std::wstring PostScriptDocument::DEFAULT_FONT = L"Courier New";
|
||||
|
||||
//JAVA TO C++ CONVERTER TODO TASK: Static constructors are not allowed in native C++:
|
||||
PostScriptDocument::PostScriptDocument() {
|
||||
POSTSCRIPT_FONT_NAMES = std::unordered_map<std::wstring, std::wstring>();
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SANS_SERIF + std::wstring(L".plain"), L"ArialMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SANS_SERIF + std::wstring(L".bold"), L"Arial-BoldMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SANS_SERIF + std::wstring(L".italic"), L"Arial-ItalicMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SANS_SERIF + std::wstring(L".bolditalic"), L"Arial-BoldItalicMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SERIF + std::wstring(L".plain"), L"TimesNewRomanPSMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SERIF + std::wstring(L".bold"), L"TimesNewRomanPS-BoldMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SERIF + std::wstring(L".italic"), L"TimesNewRomanPS-ItalicMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::SERIF + std::wstring(L".bolditalic"), L"TimesNewRomanPS-BoldItalicMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::MONOSPACED + std::wstring(L".plain"), L"CourierNewPSMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::MONOSPACED + std::wstring(L".bold"), L"CourierNewPS-BoldMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::MONOSPACED + std::wstring(L".italic"), L"CourierNewPS-ItalicMT");
|
||||
POSTSCRIPT_FONT_NAMES->put(Font::MONOSPACED + std::wstring(L".bolditalic"), L"CourierNewPS-BoldItalicMT");
|
||||
}
|
||||
|
||||
//JAVA TO C++ CONVERTER TODO TASK: Calls to same-class constructors are not supported in C++ prior to C++11:
|
||||
PostScriptDocument::PostScriptDocument() {
|
||||
}
|
||||
|
||||
PostScriptDocument::PostScriptDocument(const std::wstring &fontName, int fontSize) {
|
||||
InitializeInstanceFields();
|
||||
header();
|
||||
setFont(fontName, fontSize);
|
||||
}
|
||||
|
||||
std::wstring PostScriptDocument::getPS() {
|
||||
close();
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no native C++ equivalent to 'toString':
|
||||
return header() + ps->toString();
|
||||
}
|
||||
|
||||
void PostScriptDocument::boundingBox(int w, int h) {
|
||||
boundingBoxWidth = w;
|
||||
boundingBoxHeight = h;
|
||||
boundingBox_Renamed = std::wstring::format(Locale::US, L"%%%%BoundingBox: %d %d %d %d\n", 0,0, boundingBoxWidth,boundingBoxHeight);
|
||||
}
|
||||
|
||||
void PostScriptDocument::close() {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
// ps.append("showpage\n");
|
||||
ps->append(L"%%Trailer\n");
|
||||
closed = true;
|
||||
}
|
||||
|
||||
StringBuilder *PostScriptDocument::header() {
|
||||
StringBuilder *b = new StringBuilder();
|
||||
b->append(L"%!PS-Adobe-3.0 EPSF-3.0\n");
|
||||
b->append(boundingBox_Renamed)->append(L"\n");
|
||||
b->append(L"0.3 setlinewidth\n");
|
||||
b->append(std::wstring(L"%% x y w h highlight\n") + std::wstring(L"/highlight {\n") + std::wstring(L" 4 dict begin\n") + std::wstring(L" /h exch def\n") + std::wstring(L" /w exch def\n") + std::wstring(L" /y exch def\n") + std::wstring(L" /x exch def\n") + std::wstring(L" gsave\n") + std::wstring(L" newpath\n") + std::wstring(L" x y moveto\n") + std::wstring(L" 0 h rlineto % up to left corner\n") + std::wstring(L" w 0 rlineto % to upper right corner\n") + std::wstring(L" 0 h neg rlineto % to lower right corner\n") + std::wstring(L" w neg 0 rlineto % back home to lower left corner\n") + std::wstring(L" closepath\n") + std::wstring(L" .95 .83 .82 setrgbcolor\n") + std::wstring(L" fill\n") + std::wstring(L" grestore\n") + std::wstring(L" end\n") + std::wstring(L"} def\n"));
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void PostScriptDocument::setFont(const std::wstring &fontName, int fontSize) {
|
||||
this->fontMetrics = new SystemFontMetrics(fontName);
|
||||
this->fontName = fontMetrics->getFont()->getPSName();
|
||||
this->fontSize = fontSize;
|
||||
|
||||
std::wstring psname = POSTSCRIPT_FONT_NAMES->get(this->fontName);
|
||||
if (psname == L"") {
|
||||
psname = this->fontName;
|
||||
}
|
||||
|
||||
ps->append(std::wstring::format(Locale::US, L"/%s findfont %d scalefont setfont\n", psname, fontSize));
|
||||
}
|
||||
|
||||
void PostScriptDocument::lineWidth(double w) {
|
||||
lineWidth_Renamed = w;
|
||||
ps->append(w)->append(L" setlinewidth\n");
|
||||
}
|
||||
|
||||
void PostScriptDocument::move(double x, double y) {
|
||||
ps->append(std::wstring::format(Locale::US, L"%1.3f %1.3f moveto\n", x, y));
|
||||
}
|
||||
|
||||
void PostScriptDocument::lineto(double x, double y) {
|
||||
ps->append(std::wstring::format(Locale::US, L"%1.3f %1.3f lineto\n", x, y));
|
||||
}
|
||||
|
||||
void PostScriptDocument::line(double x1, double y1, double x2, double y2) {
|
||||
move(x1, y1);
|
||||
lineto(x2, y2);
|
||||
}
|
||||
|
||||
void PostScriptDocument::rect(double x, double y, double width, double height) {
|
||||
line(x, y, x, y + height);
|
||||
line(x, y + height, x + width, y + height);
|
||||
line(x + width, y + height, x + width, y);
|
||||
line(x + width, y, x, y);
|
||||
}
|
||||
|
||||
void PostScriptDocument::highlight(double x, double y, double width, double height) {
|
||||
ps->append(std::wstring::format(Locale::US, L"%1.3f %1.3f %1.3f %1.3f highlight\n", x, y, width, height));
|
||||
}
|
||||
|
||||
void PostScriptDocument::stroke() {
|
||||
ps->append(L"stroke\n");
|
||||
}
|
||||
|
||||
void PostScriptDocument::text(const std::wstring &s, double x, double y) {
|
||||
StringBuilder *buf = new StringBuilder();
|
||||
// escape \, (, ): \\, \(, \)
|
||||
for (auto c : s.toCharArray()) {
|
||||
switch (c) {
|
||||
case L'\\' :
|
||||
case L'(' :
|
||||
case L')' :
|
||||
buf->append(L'\\');
|
||||
buf->append(c);
|
||||
break;
|
||||
default :
|
||||
buf->append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no native C++ equivalent to 'toString':
|
||||
s = buf->toString();
|
||||
move(x,y);
|
||||
ps->append(std::wstring::format(Locale::US, L"(%s) show\n", s));
|
||||
stroke();
|
||||
}
|
||||
|
||||
double PostScriptDocument::getWidth(wchar_t c) {
|
||||
return fontMetrics->getWidth(c, fontSize);
|
||||
}
|
||||
|
||||
double PostScriptDocument::getWidth(const std::wstring &s) {
|
||||
return fontMetrics->getWidth(s, fontSize);
|
||||
}
|
||||
|
||||
double PostScriptDocument::getLineHeight() {
|
||||
return fontMetrics->getLineHeight(fontSize);
|
||||
}
|
||||
|
||||
int PostScriptDocument::getFontSize() {
|
||||
return fontSize;
|
||||
}
|
||||
|
||||
void PostScriptDocument::InitializeInstanceFields() {
|
||||
boundingBoxWidth = 0;
|
||||
boundingBoxHeight = 0;
|
||||
fontSize = 12;
|
||||
lineWidth_Renamed = 0.3;
|
||||
ps = new StringBuilder();
|
||||
closed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "SystemFontMetrics.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
|
||||
class PostScriptDocument {
|
||||
public:
|
||||
static const std::wstring DEFAULT_FONT;
|
||||
|
||||
static Map<std::wstring, std::wstring> *const POSTSCRIPT_FONT_NAMES;
|
||||
//JAVA TO C++ CONVERTER TODO TASK: Static constructors are not allowed in native C++:
|
||||
static PostScriptDocument();
|
||||
|
||||
protected:
|
||||
int boundingBoxWidth;
|
||||
int boundingBoxHeight;
|
||||
|
||||
SystemFontMetrics *fontMetrics;
|
||||
std::wstring fontName;
|
||||
int fontSize;
|
||||
//JAVA TO C++ CONVERTER NOTE: The variable lineWidth was renamed since C++ does not allow variables with the same name as methods:
|
||||
double lineWidth_Renamed;
|
||||
//JAVA TO C++ CONVERTER NOTE: The variable boundingBox was renamed since C++ does not allow variables with the same name as methods:
|
||||
std::wstring boundingBox_Renamed;
|
||||
|
||||
StringBuilder *ps;
|
||||
bool closed;
|
||||
|
||||
public:
|
||||
//JAVA TO C++ CONVERTER TODO TASK: Calls to same-class constructors are not supported in C++ prior to C++11:
|
||||
PostScriptDocument(); //this(DEFAULT_FONT, 12);
|
||||
|
||||
PostScriptDocument(const std::wstring &fontName, int fontSize);
|
||||
|
||||
virtual std::wstring getPS();
|
||||
|
||||
virtual void boundingBox(int w, int h);
|
||||
|
||||
virtual void close();
|
||||
|
||||
/// <summary>
|
||||
/// Compute the header separately because we need to wait for the bounding box </summary>
|
||||
protected:
|
||||
virtual StringBuilder *header();
|
||||
|
||||
public:
|
||||
virtual void setFont(const std::wstring &fontName, int fontSize);
|
||||
|
||||
virtual void lineWidth(double w);
|
||||
|
||||
virtual void move(double x, double y);
|
||||
|
||||
virtual void lineto(double x, double y);
|
||||
|
||||
virtual void line(double x1, double y1, double x2, double y2);
|
||||
|
||||
virtual void rect(double x, double y, double width, double height);
|
||||
|
||||
/// <summary>
|
||||
/// Make red box </summary>
|
||||
virtual void highlight(double x, double y, double width, double height);
|
||||
|
||||
virtual void stroke();
|
||||
|
||||
// public void rarrow(double x, double y) {
|
||||
// ps.append(String.format(Locale.US, "%1.3f %1.3f rarrow\n", x,y));
|
||||
// }
|
||||
//
|
||||
// public void darrow(double x, double y) {
|
||||
// ps.append(String.format(Locale.US, "%1.3f %1.3f darrow\n", x,y));
|
||||
// }
|
||||
|
||||
virtual void text(const std::wstring &s, double x, double y);
|
||||
|
||||
// courier new: wid/hei 7.611979 10.0625
|
||||
/// <summary>
|
||||
/// All chars are 600 thousands of an 'em' wide if courier </summary>
|
||||
virtual double getWidth(wchar_t c);
|
||||
virtual double getWidth(const std::wstring &s);
|
||||
virtual double getLineHeight();
|
||||
|
||||
virtual int getFontSize();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
#include "SystemFontMetrics.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
SystemFontMetrics::SystemFontMetrics(const std::wstring &fontName) : font(new Font(fontName, Font::PLAIN, 1000)) {
|
||||
BufferedImage *img = new BufferedImage(40, 40, BufferedImage::TYPE_4BYTE_ABGR);
|
||||
Graphics2D *graphics = GraphicsEnvironment::getLocalGraphicsEnvironment()->createGraphics(img);
|
||||
FontRenderContext *fontRenderContext = graphics->getFontRenderContext();
|
||||
double maxHeight = 0;
|
||||
for (int i = 0; i < 255; i++) {
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no native C++ equivalent to 'toString':
|
||||
TextLayout *layout = new TextLayout(wchar_t::toString(static_cast<wchar_t>(i)), font, fontRenderContext);
|
||||
maxHeight = std::max(maxHeight, layout->getBounds()->getHeight());
|
||||
BasicFontMetrics::widths[i] = static_cast<int>(layout->getAdvance());
|
||||
}
|
||||
|
||||
BasicFontMetrics::maxCharHeight = static_cast<int>(Math::round(maxHeight));
|
||||
}
|
||||
|
||||
Font *SystemFontMetrics::getFont() {
|
||||
return font;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "BasicFontMetrics.h"
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
|
||||
///
|
||||
/// <summary>
|
||||
/// @author Sam Harwell
|
||||
/// </summary>
|
||||
class SystemFontMetrics : public BasicFontMetrics {
|
||||
protected:
|
||||
Font *const font;
|
||||
|
||||
public:
|
||||
SystemFontMetrics(const std::wstring &fontName);
|
||||
|
||||
virtual Font *getFont();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
#include "TreeLayoutAdaptor.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
using org::abego::treelayout::TreeForTreeLayout;
|
||||
using org::antlr::v4::runtime::tree::Tree;
|
||||
|
||||
TreeLayoutAdaptor::AntlrTreeChildrenIterable::AntlrTreeChildrenIterable(Tree *tree) : tree(tree) {
|
||||
}
|
||||
|
||||
Iterator<Tree*> *TreeLayoutAdaptor::AntlrTreeChildrenIterable::iterator() {
|
||||
return new IteratorAnonymousInnerClassHelper(this);
|
||||
}
|
||||
|
||||
TreeLayoutAdaptor::AntlrTreeChildrenIterable::IteratorAnonymousInnerClassHelper::IteratorAnonymousInnerClassHelper(AntlrTreeChildrenIterable *outerInstance) {
|
||||
this->outerInstance = outerInstance;
|
||||
i = 0;
|
||||
}
|
||||
|
||||
bool TreeLayoutAdaptor::AntlrTreeChildrenIterable::IteratorAnonymousInnerClassHelper::hasNext() {
|
||||
return outerInstance->tree->getChildCount() > i;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::tree::Tree *TreeLayoutAdaptor::AntlrTreeChildrenIterable::IteratorAnonymousInnerClassHelper::next() {
|
||||
if (!hasNext()) {
|
||||
throw NoSuchElementException();
|
||||
}
|
||||
|
||||
return outerInstance->tree->getChild(i++);
|
||||
}
|
||||
|
||||
void TreeLayoutAdaptor::AntlrTreeChildrenIterable::IteratorAnonymousInnerClassHelper::remove() {
|
||||
throw UnsupportedOperationException();
|
||||
}
|
||||
|
||||
TreeLayoutAdaptor::AntlrTreeChildrenReverseIterable::AntlrTreeChildrenReverseIterable(Tree *tree) : tree(tree) {
|
||||
}
|
||||
|
||||
Iterator<Tree*> *TreeLayoutAdaptor::AntlrTreeChildrenReverseIterable::iterator() {
|
||||
return new IteratorAnonymousInnerClassHelper(this);
|
||||
}
|
||||
|
||||
TreeLayoutAdaptor::AntlrTreeChildrenReverseIterable::IteratorAnonymousInnerClassHelper::IteratorAnonymousInnerClassHelper(AntlrTreeChildrenReverseIterable *outerInstance) {
|
||||
this->outerInstance = outerInstance;
|
||||
i = outerInstance->tree->getChildCount();
|
||||
}
|
||||
|
||||
bool TreeLayoutAdaptor::AntlrTreeChildrenReverseIterable::IteratorAnonymousInnerClassHelper::hasNext() {
|
||||
return i > 0;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::tree::Tree *TreeLayoutAdaptor::AntlrTreeChildrenReverseIterable::IteratorAnonymousInnerClassHelper::next() {
|
||||
if (!hasNext()) {
|
||||
throw NoSuchElementException();
|
||||
}
|
||||
|
||||
return outerInstance->tree->getChild(--i);
|
||||
}
|
||||
|
||||
void TreeLayoutAdaptor::AntlrTreeChildrenReverseIterable::IteratorAnonymousInnerClassHelper::remove() {
|
||||
throw UnsupportedOperationException();
|
||||
}
|
||||
|
||||
TreeLayoutAdaptor::TreeLayoutAdaptor(Tree *root) {
|
||||
this->root = root;
|
||||
}
|
||||
|
||||
bool TreeLayoutAdaptor::isLeaf(Tree *node) {
|
||||
return node->getChildCount() == 0;
|
||||
}
|
||||
|
||||
bool TreeLayoutAdaptor::isChildOfParent(Tree *node, Tree *parentNode) {
|
||||
return node->getParent() == parentNode;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::tree::Tree *TreeLayoutAdaptor::getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::tree::Tree *TreeLayoutAdaptor::getLastChild(Tree *parentNode) {
|
||||
return parentNode->getChild(parentNode->getChildCount() - 1);
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::tree::Tree *TreeLayoutAdaptor::getFirstChild(Tree *parentNode) {
|
||||
return parentNode->getChild(0);
|
||||
}
|
||||
|
||||
Iterable<Tree*> *TreeLayoutAdaptor::getChildrenReverse(Tree *node) {
|
||||
return new AntlrTreeChildrenReverseIterable(node);
|
||||
}
|
||||
|
||||
Iterable<Tree*> *TreeLayoutAdaptor::getChildren(Tree *node) {
|
||||
return new AntlrTreeChildrenIterable(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/Tree.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
using org::abego::treelayout::TreeForTreeLayout;
|
||||
using org::antlr::v4::runtime::tree::Tree;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adaptor ANTLR trees to <seealso cref="TreeForTreeLayout"/>. </summary>
|
||||
class TreeLayoutAdaptor : public TreeForTreeLayout<Tree*> {
|
||||
private:
|
||||
class AntlrTreeChildrenIterable : public Iterable<Tree*> {
|
||||
private:
|
||||
Tree *const tree;
|
||||
|
||||
public:
|
||||
AntlrTreeChildrenIterable(Tree *tree);
|
||||
|
||||
virtual Iterator<Tree*> *iterator() override;
|
||||
|
||||
private:
|
||||
class IteratorAnonymousInnerClassHelper : public Iterator<Tree*> {
|
||||
private:
|
||||
AntlrTreeChildrenIterable *const outerInstance;
|
||||
|
||||
public:
|
||||
IteratorAnonymousInnerClassHelper(AntlrTreeChildrenIterable *outerInstance);
|
||||
|
||||
private:
|
||||
int i;
|
||||
|
||||
public:
|
||||
virtual bool hasNext();
|
||||
|
||||
virtual Tree *next();
|
||||
|
||||
virtual void remove();
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
class AntlrTreeChildrenReverseIterable : public Iterable<Tree*> {
|
||||
private:
|
||||
Tree *const tree;
|
||||
|
||||
public:
|
||||
AntlrTreeChildrenReverseIterable(Tree *tree);
|
||||
|
||||
virtual Iterator<Tree*> *iterator() override;
|
||||
|
||||
private:
|
||||
class IteratorAnonymousInnerClassHelper : public Iterator<Tree*> {
|
||||
private:
|
||||
AntlrTreeChildrenReverseIterable *const outerInstance;
|
||||
|
||||
public:
|
||||
IteratorAnonymousInnerClassHelper(AntlrTreeChildrenReverseIterable *outerInstance);
|
||||
|
||||
private:
|
||||
int i;
|
||||
|
||||
public:
|
||||
virtual bool hasNext();
|
||||
|
||||
virtual Tree *next();
|
||||
|
||||
virtual void remove();
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
Tree *root;
|
||||
|
||||
public:
|
||||
TreeLayoutAdaptor(Tree *root);
|
||||
|
||||
virtual bool isLeaf(Tree *node) override;
|
||||
|
||||
virtual bool isChildOfParent(Tree *node, Tree *parentNode) override;
|
||||
|
||||
virtual Tree *getRoot() override;
|
||||
|
||||
virtual Tree *getLastChild(Tree *parentNode) override;
|
||||
|
||||
virtual Tree *getFirstChild(Tree *parentNode) override;
|
||||
|
||||
virtual Iterable<Tree*> *getChildrenReverse(Tree *node) override;
|
||||
|
||||
virtual Iterable<Tree*> *getChildren(Tree *node) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
#include "TreePostScriptGenerator.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/gui/TreeLayoutAdaptor.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/ErrorNode.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/misc/Utils.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
using org::abego::treelayout::Configuration;
|
||||
using org::abego::treelayout::NodeExtentProvider;
|
||||
using org::abego::treelayout::TreeForTreeLayout;
|
||||
using org::abego::treelayout::TreeLayout;
|
||||
using org::abego::treelayout::util::DefaultConfiguration;
|
||||
using org::antlr::v4::runtime::misc::Nullable;
|
||||
using org::antlr::v4::runtime::misc::Utils;
|
||||
using org::antlr::v4::runtime::tree::ErrorNode;
|
||||
using org::antlr::v4::runtime::tree::Tree;
|
||||
|
||||
TreePostScriptGenerator::VariableExtentProvide::VariableExtentProvide(TreePostScriptGenerator *outerInstance) : outerInstance(outerInstance) {
|
||||
}
|
||||
|
||||
double TreePostScriptGenerator::VariableExtentProvide::getWidth(Tree *tree) {
|
||||
std::wstring s = outerInstance->getText(tree);
|
||||
return outerInstance->doc->getWidth(s) + outerInstance->nodeWidthPadding*2;
|
||||
}
|
||||
|
||||
double TreePostScriptGenerator::VariableExtentProvide::getHeight(Tree *tree) {
|
||||
std::wstring s = outerInstance->getText(tree);
|
||||
double h = outerInstance->doc->getLineHeight() + outerInstance->nodeHeightPaddingAbove + outerInstance->nodeHeightPaddingBelow;
|
||||
//JAVA TO C++ CONVERTER WARNING: Since the array size is not known in this declaration, Java to C++ Converter has converted this array to a pointer. You will need to call 'delete[]' where appropriate:
|
||||
//ORIGINAL LINE: String[] lines = s.split("\n");
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no direct native C++ equivalent to the Java String 'split' method:
|
||||
std::wstring *lines = s.split(L"\n");
|
||||
return h * lines->length;
|
||||
}
|
||||
|
||||
//JAVA TO C++ CONVERTER TODO TASK: Calls to same-class constructors are not supported in C++ prior to C++11:
|
||||
TreePostScriptGenerator::TreePostScriptGenerator(std::vector<std::wstring> &ruleNames, Tree *root) {
|
||||
}
|
||||
|
||||
TreePostScriptGenerator::TreePostScriptGenerator(std::vector<std::wstring> &ruleNames, Tree *root, const std::wstring &fontName, int fontSize) {
|
||||
InitializeInstanceFields();
|
||||
this->root = root;
|
||||
setTreeTextProvider(new TreeViewer::DefaultTreeTextProvider(ruleNames));
|
||||
doc = new PostScriptDocument(fontName, fontSize);
|
||||
bool compareNodeIdentities = true;
|
||||
this->treeLayout = new TreeLayout<Tree*>(new TreeLayoutAdaptor(root), new VariableExtentProvide(this), new DefaultConfiguration<Tree*>(gapBetweenLevels, gapBetweenNodes, Configuration::Location::Bottom), compareNodeIdentities);
|
||||
}
|
||||
|
||||
std::wstring TreePostScriptGenerator::getPS() {
|
||||
// generate the edges and boxes (with text)
|
||||
generateEdges(getTree()->getRoot());
|
||||
for (Tree *node : treeLayout->getNodeBounds()->keySet()) {
|
||||
generateNode(node);
|
||||
}
|
||||
|
||||
Dimension *size = treeLayout->getBounds()->getBounds()->getSize();
|
||||
doc->boundingBox(size->width, size->height);
|
||||
doc->close();
|
||||
return doc->getPS();
|
||||
}
|
||||
|
||||
void TreePostScriptGenerator::generateEdges(Tree *parent) {
|
||||
if (!getTree()->isLeaf(parent)) {
|
||||
Rectangle2D::Double *parentBounds = getBoundsOfNode(parent);
|
||||
// System.out.println("%% parent("+getText(parent)+")="+parentBounds);
|
||||
double x1 = parentBounds->getCenterX();
|
||||
double y1 = parentBounds->y;
|
||||
for (auto child : getChildren(parent)) {
|
||||
Rectangle2D::Double *childBounds = getBoundsOfNode(child);
|
||||
// System.out.println("%% child("+getText(child)+")="+childBounds);
|
||||
double x2 = childBounds->getCenterX();
|
||||
double y2 = childBounds->getMaxY();
|
||||
doc->line(x1, y1, x2, y2);
|
||||
generateEdges(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TreePostScriptGenerator::generateNode(Tree *t) {
|
||||
// draw the text on top of the box (possibly multiple lines)
|
||||
//JAVA TO C++ CONVERTER WARNING: Since the array size is not known in this declaration, Java to C++ Converter has converted this array to a pointer. You will need to call 'delete[]' where appropriate:
|
||||
//ORIGINAL LINE: String[] lines = getText(t).split("\n");
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no direct native C++ equivalent to the Java String 'split' method:
|
||||
std::wstring *lines = getText(t).split(L"\n");
|
||||
Rectangle2D::Double *box = getBoundsOfNode(t);
|
||||
// for debugging, turn this on to see boundingbox of nodes
|
||||
//doc.rect(box.x, box.y, box.width, box.height);
|
||||
// make error nodes from parse tree red by default
|
||||
if (dynamic_cast<ErrorNode*>(t) != nullptr) {
|
||||
doc->highlight(box->x, box->y, box->width, box->height);
|
||||
}
|
||||
double x = box->x + nodeWidthPadding;
|
||||
double y = box->y + nodeHeightPaddingBelow;
|
||||
for (int i = 0; i < lines->length; i++) {
|
||||
doc->text(lines[i], x, y);
|
||||
y += doc->getLineHeight();
|
||||
}
|
||||
}
|
||||
|
||||
TreeForTreeLayout<Tree*> *TreePostScriptGenerator::getTree() {
|
||||
return treeLayout->getTree();
|
||||
}
|
||||
|
||||
Iterable<Tree*> *TreePostScriptGenerator::getChildren(Tree *parent) {
|
||||
return getTree()->getChildren(parent);
|
||||
}
|
||||
|
||||
Rectangle2D::Double *TreePostScriptGenerator::getBoundsOfNode(Tree *node) {
|
||||
return treeLayout->getNodeBounds()->get(node);
|
||||
}
|
||||
|
||||
std::wstring TreePostScriptGenerator::getText(Tree *tree) {
|
||||
std::wstring s = treeTextProvider->getText(tree);
|
||||
s = Utils::escapeWhitespace(s, false);
|
||||
return s;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::tree::gui::TreeTextProvider *TreePostScriptGenerator::getTreeTextProvider() {
|
||||
return treeTextProvider;
|
||||
}
|
||||
|
||||
void TreePostScriptGenerator::setTreeTextProvider(TreeTextProvider *treeTextProvider) {
|
||||
this->treeTextProvider = treeTextProvider;
|
||||
}
|
||||
|
||||
void TreePostScriptGenerator::InitializeInstanceFields() {
|
||||
gapBetweenLevels = 17;
|
||||
gapBetweenNodes = 7;
|
||||
nodeWidthPadding = 1;
|
||||
nodeHeightPaddingAbove = 0;
|
||||
nodeHeightPaddingBelow = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/Tree.h"
|
||||
#include "TreeViewer.h"
|
||||
#include "TreeTextProvider.h"
|
||||
#include "PostScriptDocument.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
using org::abego::treelayout::Configuration;
|
||||
using org::abego::treelayout::NodeExtentProvider;
|
||||
using org::abego::treelayout::TreeForTreeLayout;
|
||||
using org::abego::treelayout::TreeLayout;
|
||||
using org::abego::treelayout::util::DefaultConfiguration;
|
||||
using org::antlr::v4::runtime::misc::Nullable;
|
||||
using org::antlr::v4::runtime::misc::Utils;
|
||||
using org::antlr::v4::runtime::tree::ErrorNode;
|
||||
using org::antlr::v4::runtime::tree::Tree;
|
||||
|
||||
|
||||
class TreePostScriptGenerator {
|
||||
public:
|
||||
class VariableExtentProvide : public NodeExtentProvider<Tree*> {
|
||||
private:
|
||||
TreePostScriptGenerator *const outerInstance;
|
||||
|
||||
public:
|
||||
VariableExtentProvide(TreePostScriptGenerator *outerInstance);
|
||||
|
||||
virtual double getWidth(Tree *tree) override;
|
||||
|
||||
virtual double getHeight(Tree *tree) override;
|
||||
};
|
||||
|
||||
protected:
|
||||
double gapBetweenLevels;
|
||||
double gapBetweenNodes;
|
||||
int nodeWidthPadding; // added to left/right
|
||||
int nodeHeightPaddingAbove;
|
||||
int nodeHeightPaddingBelow;
|
||||
|
||||
Tree *root;
|
||||
TreeTextProvider *treeTextProvider;
|
||||
TreeLayout<Tree*> *treeLayout;
|
||||
|
||||
PostScriptDocument *doc;
|
||||
|
||||
public:
|
||||
//JAVA TO C++ CONVERTER TODO TASK: Calls to same-class constructors are not supported in C++ prior to C++11:
|
||||
TreePostScriptGenerator(std::vector<std::wstring> &ruleNames, Tree *root); //this(ruleNames, root, PostScriptDocument.DEFAULT_FONT, 11);
|
||||
|
||||
TreePostScriptGenerator(std::vector<std::wstring> &ruleNames, Tree *root, const std::wstring &fontName, int fontSize);
|
||||
|
||||
virtual std::wstring getPS();
|
||||
|
||||
protected:
|
||||
virtual void generateEdges(Tree *parent);
|
||||
|
||||
virtual void generateNode(Tree *t);
|
||||
|
||||
virtual TreeForTreeLayout<Tree*> *getTree();
|
||||
|
||||
virtual Iterable<Tree*> *getChildren(Tree *parent);
|
||||
|
||||
virtual Rectangle2D::Double *getBoundsOfNode(Tree *node);
|
||||
|
||||
virtual std::wstring getText(Tree *tree);
|
||||
|
||||
public:
|
||||
virtual TreeTextProvider *getTreeTextProvider();
|
||||
|
||||
virtual void setTreeTextProvider(TreeTextProvider *treeTextProvider);
|
||||
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#include "TreeTextProvider.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
using org::antlr::v4::runtime::tree::Tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Tree.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
class TreeTextProvider {
|
||||
public:
|
||||
virtual std::wstring getText(tree::Tree *node) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,616 +0,0 @@
|
|||
#include "TreeViewer.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/Trees.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/gui/TreeLayoutAdaptor.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/ErrorNode.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/misc/Utils.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/misc/JFileChooserConfirmOverwrite.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/misc/GraphicsSupport.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
using org::abego::treelayout::NodeExtentProvider;
|
||||
using org::abego::treelayout::TreeForTreeLayout;
|
||||
using org::abego::treelayout::TreeLayout;
|
||||
using org::abego::treelayout::util::DefaultConfiguration;
|
||||
using org::antlr::v4::runtime::misc::GraphicsSupport;
|
||||
using org::antlr::v4::runtime::misc::JFileChooserConfirmOverwrite;
|
||||
using org::antlr::v4::runtime::misc::NotNull;
|
||||
using org::antlr::v4::runtime::misc::Nullable;
|
||||
using org::antlr::v4::runtime::misc::Utils;
|
||||
using org::antlr::v4::runtime::tree::ErrorNode;
|
||||
using org::antlr::v4::runtime::tree::Tree;
|
||||
using org::antlr::v4::runtime::tree::Trees;
|
||||
|
||||
TreeViewer::DefaultTreeTextProvider::DefaultTreeTextProvider(std::vector<std::wstring> &ruleNames) : ruleNames(ruleNames) {
|
||||
}
|
||||
|
||||
std::wstring TreeViewer::DefaultTreeTextProvider::getText(Tree *node) {
|
||||
return static_cast<std::wstring>(Trees::getNodeText(node, ruleNames));
|
||||
}
|
||||
|
||||
TreeViewer::VariableExtentProvide::VariableExtentProvide(TreeViewer *viewer) {
|
||||
this->viewer = viewer;
|
||||
}
|
||||
|
||||
double TreeViewer::VariableExtentProvide::getWidth(Tree *tree) {
|
||||
FontMetrics *fontMetrics = viewer->getFontMetrics(viewer->font);
|
||||
std::wstring s = viewer->getText(tree);
|
||||
int w = fontMetrics->stringWidth(s) + viewer->nodeWidthPadding*2;
|
||||
return w;
|
||||
}
|
||||
|
||||
double TreeViewer::VariableExtentProvide::getHeight(Tree *tree) {
|
||||
FontMetrics *fontMetrics = viewer->getFontMetrics(viewer->font);
|
||||
int h = fontMetrics->getHeight() + viewer->nodeHeightPadding*2;
|
||||
std::wstring s = viewer->getText(tree);
|
||||
//JAVA TO C++ CONVERTER WARNING: Since the array size is not known in this declaration, Java to C++ Converter has converted this array to a pointer. You will need to call 'delete[]' where appropriate:
|
||||
//ORIGINAL LINE: String[] lines = s.split("\n");
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no direct native C++ equivalent to the Java String 'split' method:
|
||||
std::wstring *lines = s.split(L"\n");
|
||||
return h * lines->length;
|
||||
}
|
||||
|
||||
TreeViewer::TreeNodeWrapper::TreeNodeWrapper(Tree *tree, TreeViewer *viewer) : javax::swing::tree::DefaultMutableTreeNode(tree), viewer(viewer) {
|
||||
}
|
||||
|
||||
std::wstring TreeViewer::TreeNodeWrapper::toString() {
|
||||
return viewer->getText(static_cast<Tree*>(this->getUserObject()));
|
||||
}
|
||||
|
||||
int TreeViewer::EmptyIcon::getIconWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TreeViewer::EmptyIcon::getIconHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TreeViewer::EmptyIcon::paintIcon(Component *c, Graphics *g, int x, int y) {
|
||||
/* Do nothing. */
|
||||
}
|
||||
|
||||
java::awt::Color *const TreeViewer::LIGHT_RED = new java::awt::Color(244, 213, 211);
|
||||
|
||||
TreeViewer::TreeViewer(std::vector<std::wstring> &ruleNames, Tree *tree) {
|
||||
InitializeInstanceFields();
|
||||
setTreeTextProvider(new DefaultTreeTextProvider(ruleNames));
|
||||
bool useIdentity = true; // compare node identity
|
||||
this->treeLayout = new TreeLayout<Tree*>(new TreeLayoutAdaptor(tree), new TreeViewer::VariableExtentProvide(this), new DefaultConfiguration<Tree*>(gapBetweenLevels, gapBetweenNodes), useIdentity);
|
||||
updatePreferredSize();
|
||||
setFont(font);
|
||||
}
|
||||
|
||||
void TreeViewer::updatePreferredSize() {
|
||||
setPreferredSize(getScaledTreeSize());
|
||||
invalidate();
|
||||
if (getParent() != nullptr) {
|
||||
getParent()->validate();
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
bool TreeViewer::getUseCurvedEdges() {
|
||||
return useCurvedEdges;
|
||||
}
|
||||
|
||||
void TreeViewer::setUseCurvedEdges(bool useCurvedEdges) {
|
||||
this->useCurvedEdges = useCurvedEdges;
|
||||
}
|
||||
|
||||
void TreeViewer::paintEdges(Graphics *g, Tree *parent) {
|
||||
if (!getTree()->isLeaf(parent)) {
|
||||
BasicStroke *stroke = new BasicStroke(1.0f, BasicStroke::CAP_ROUND, BasicStroke::JOIN_ROUND);
|
||||
(static_cast<Graphics2D*>(g))->setStroke(stroke);
|
||||
|
||||
Rectangle2D::Double *parentBounds = getBoundsOfNode(parent);
|
||||
double x1 = parentBounds->getCenterX();
|
||||
double y1 = parentBounds->getMaxY();
|
||||
for (Tree *child : getTree()->getChildren(parent)) {
|
||||
Rectangle2D::Double *childBounds = getBoundsOfNode(child);
|
||||
double x2 = childBounds->getCenterX();
|
||||
double y2 = childBounds->getMinY();
|
||||
if (getUseCurvedEdges()) {
|
||||
CubicCurve2D *c = new CubicCurve2D::Double();
|
||||
double ctrlx1 = x1;
|
||||
double ctrly1 = (y1 + y2) / 2;
|
||||
double ctrlx2 = x2;
|
||||
double ctrly2 = y1;
|
||||
c->setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
|
||||
(static_cast<Graphics2D*>(g))->draw(c);
|
||||
} else {
|
||||
g->drawLine(static_cast<int>(x1), static_cast<int>(y1), static_cast<int>(x2), static_cast<int>(y2));
|
||||
}
|
||||
paintEdges(g, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TreeViewer::paintBox(Graphics *g, Tree *tree) {
|
||||
Rectangle2D::Double *box = getBoundsOfNode(tree);
|
||||
// draw the box in the background
|
||||
if (isHighlighted(tree) || boxColor != nullptr || dynamic_cast<ErrorNode*>(tree) != nullptr) {
|
||||
if (isHighlighted(tree)) {
|
||||
g->setColor(highlightedBoxColor);
|
||||
} else if (dynamic_cast<ErrorNode*>(tree) != nullptr) {
|
||||
g->setColor(LIGHT_RED);
|
||||
} else {
|
||||
g->setColor(boxColor);
|
||||
}
|
||||
g->fillRoundRect(static_cast<int>(box->x), static_cast<int>(box->y), static_cast<int>(box->width) - 1, static_cast<int>(box->height) - 1, arcSize, arcSize);
|
||||
}
|
||||
if (borderColor != nullptr) {
|
||||
g->setColor(borderColor);
|
||||
g->drawRoundRect(static_cast<int>(box->x), static_cast<int>(box->y), static_cast<int>(box->width) - 1, static_cast<int>(box->height) - 1, arcSize, arcSize);
|
||||
}
|
||||
|
||||
// draw the text on top of the box (possibly multiple lines)
|
||||
g->setColor(textColor);
|
||||
std::wstring s = getText(tree);
|
||||
//JAVA TO C++ CONVERTER WARNING: Since the array size is not known in this declaration, Java to C++ Converter has converted this array to a pointer. You will need to call 'delete[]' where appropriate:
|
||||
//ORIGINAL LINE: String[] lines = s.split("\n");
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no direct native C++ equivalent to the Java String 'split' method:
|
||||
std::wstring *lines = s.split(L"\n");
|
||||
FontMetrics *m = getFontMetrics(font);
|
||||
int x = static_cast<int>(box->x) + arcSize / 2 + nodeWidthPadding;
|
||||
int y = static_cast<int>(box->y) + m->getAscent() + m->getLeading() + 1 + nodeHeightPadding;
|
||||
for (int i = 0; i < lines->length; i++) {
|
||||
text(g, lines[i], x, y);
|
||||
y += m->getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
void TreeViewer::text(Graphics *g, const std::wstring &s, int x, int y) {
|
||||
// System.out.println("drawing '"+s+"' @ "+x+","+y);
|
||||
s = Utils::escapeWhitespace(s, true);
|
||||
g->drawString(s, x, y);
|
||||
}
|
||||
|
||||
void TreeViewer::paint(Graphics *g) {
|
||||
JComponent::paint(g);
|
||||
|
||||
Graphics2D *g2 = static_cast<Graphics2D*>(g);
|
||||
// anti-alias the lines
|
||||
g2->setRenderingHint(RenderingHints::KEY_ANTIALIASING, RenderingHints::VALUE_ANTIALIAS_ON);
|
||||
|
||||
// Anti-alias the text
|
||||
g2->setRenderingHint(RenderingHints::KEY_TEXT_ANTIALIASING, RenderingHints::VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
// AffineTransform at = g2.getTransform();
|
||||
// g2.scale(
|
||||
// (double) this.getWidth() / 400,
|
||||
// (double) this.getHeight() / 400);
|
||||
//
|
||||
// g2.setTransform(at);
|
||||
|
||||
paintEdges(g, getTree()->getRoot());
|
||||
|
||||
// paint the boxes
|
||||
for (org.antlr::v4::runtime::tree::Tree *org : treeLayout->getNodeBounds()->keySet()) {
|
||||
paintBox(g, org.antlr::v4::runtime::tree::Tree);
|
||||
}
|
||||
}
|
||||
|
||||
Graphics *TreeViewer::getComponentGraphics(Graphics *g) {
|
||||
Graphics2D *g2d = static_cast<Graphics2D*>(g);
|
||||
g2d->scale(scale, scale);
|
||||
return JComponent::getComponentGraphics(g2d);
|
||||
}
|
||||
|
||||
JDialog *TreeViewer::showInDialog(TreeViewer *const viewer) {
|
||||
JDialog * const dialog = new JDialog();
|
||||
dialog->setTitle(L"Parse Tree Inspector");
|
||||
|
||||
// Make new content panes
|
||||
Container * const mainPane = new JPanel(new BorderLayout(5,5));
|
||||
Container * const contentPane = new JPanel(new BorderLayout(0,0));
|
||||
contentPane->setBackground(Color::white);
|
||||
|
||||
// Wrap viewer in scroll pane
|
||||
JScrollPane *scrollPane = new JScrollPane(viewer);
|
||||
// Make the scrollpane (containing the viewer) the center component
|
||||
contentPane->add(scrollPane, BorderLayout::CENTER);
|
||||
|
||||
JPanel *wrapper = new JPanel(new FlowLayout());
|
||||
|
||||
// Add button to bottom
|
||||
JPanel *bottomPanel = new JPanel(new BorderLayout(0,0));
|
||||
contentPane->add(bottomPanel, BorderLayout::SOUTH);
|
||||
|
||||
JButton *ok = new JButton(L"OK");
|
||||
ok->addActionListener(new ActionListenerAnonymousInnerClassHelper(dialog)
|
||||
);
|
||||
wrapper->add(ok);
|
||||
|
||||
// Add an export-to-png button right of the "OK" button
|
||||
JButton *png = new JButton(L"png");
|
||||
png->addActionListener(new ActionListenerAnonymousInnerClassHelper2(viewer, dialog)
|
||||
);
|
||||
wrapper->add(png);
|
||||
|
||||
bottomPanel->add(wrapper, BorderLayout::SOUTH);
|
||||
|
||||
// Add scale slider
|
||||
int sliderValue = static_cast<int>((viewer->getScale() - 1.0) * 1000);
|
||||
JSlider * const scaleSlider = new JSlider(JSlider::HORIZONTAL, -999,1000,sliderValue);
|
||||
scaleSlider->addChangeListener(new ChangeListenerAnonymousInnerClassHelper(viewer, scaleSlider)
|
||||
);
|
||||
bottomPanel->add(scaleSlider, BorderLayout::CENTER);
|
||||
|
||||
// Add a JTree representing the parser tree of the input.
|
||||
JPanel *treePanel = new JPanel(new BorderLayout(5, 5));
|
||||
|
||||
// An "empty" icon that will be used for the JTree's nodes.
|
||||
Icon *empty = new EmptyIcon();
|
||||
|
||||
UIManager::put(L"Tree.closedIcon", empty);
|
||||
UIManager::put(L"Tree.openIcon", empty);
|
||||
UIManager::put(L"Tree.leafIcon", empty);
|
||||
|
||||
Tree *parseTreeRoot = viewer->getTree()->getRoot();
|
||||
TreeNodeWrapper *nodeRoot = new TreeNodeWrapper(parseTreeRoot, viewer);
|
||||
fillTree(nodeRoot, parseTreeRoot, viewer);
|
||||
JTree * const tree = new JTree(nodeRoot);
|
||||
tree->getSelectionModel()->setSelectionMode(TreeSelectionModel::SINGLE_TREE_SELECTION);
|
||||
|
||||
tree->addTreeSelectionListener(new TreeSelectionListenerAnonymousInnerClassHelper(viewer));
|
||||
|
||||
treePanel->add(new JScrollPane(tree));
|
||||
|
||||
// Create the pane for both the JTree and the AST
|
||||
JSplitPane *splitPane = new JSplitPane(JSplitPane::HORIZONTAL_SPLIT, treePanel, contentPane);
|
||||
|
||||
mainPane->add(splitPane, BorderLayout::CENTER);
|
||||
|
||||
dialog->setContentPane(mainPane);
|
||||
|
||||
// make viz
|
||||
dialog->setDefaultCloseOperation(JFrame::DISPOSE_ON_CLOSE);
|
||||
dialog->setPreferredSize(new Dimension(600, 500));
|
||||
dialog->pack();
|
||||
|
||||
// After pack(): set the divider at 1/3 of the frame.
|
||||
splitPane->setDividerLocation(0.33);
|
||||
|
||||
dialog->setLocationRelativeTo(nullptr);
|
||||
dialog->setVisible(true);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
TreeViewer::ActionListenerAnonymousInnerClassHelper::ActionListenerAnonymousInnerClassHelper(JDialog *dialog) {
|
||||
this->dialog = dialog;
|
||||
}
|
||||
|
||||
void TreeViewer::ActionListenerAnonymousInnerClassHelper::actionPerformed(ActionEvent *e) {
|
||||
dialog->setVisible(false);
|
||||
dialog->dispose();
|
||||
}
|
||||
|
||||
TreeViewer::ActionListenerAnonymousInnerClassHelper2::ActionListenerAnonymousInnerClassHelper2(org::antlr::v4::runtime::tree::gui::TreeViewer *viewer, JDialog *dialog) {
|
||||
this->viewer = viewer;
|
||||
this->dialog = dialog;
|
||||
}
|
||||
|
||||
void TreeViewer::ActionListenerAnonymousInnerClassHelper2::actionPerformed(ActionEvent *e) {
|
||||
generatePNGFile(viewer, dialog);
|
||||
}
|
||||
|
||||
TreeViewer::ChangeListenerAnonymousInnerClassHelper::ChangeListenerAnonymousInnerClassHelper(org::antlr::v4::runtime::tree::gui::TreeViewer *viewer, JSlider *scaleSlider) {
|
||||
this->viewer = viewer;
|
||||
this->scaleSlider = scaleSlider;
|
||||
}
|
||||
|
||||
void TreeViewer::ChangeListenerAnonymousInnerClassHelper::stateChanged(ChangeEvent *e) {
|
||||
int v = scaleSlider->getValue();
|
||||
viewer->setScale(v / 1000.0 + 1.0);
|
||||
}
|
||||
|
||||
TreeViewer::TreeSelectionListenerAnonymousInnerClassHelper::TreeSelectionListenerAnonymousInnerClassHelper(org::antlr::v4::runtime::tree::gui::TreeViewer *viewer) {
|
||||
this->viewer = viewer;
|
||||
}
|
||||
|
||||
void TreeViewer::TreeSelectionListenerAnonymousInnerClassHelper::valueChanged(TreeSelectionEvent *e) {
|
||||
|
||||
JTree *selectedTree = static_cast<JTree*>(e->getSource());
|
||||
TreePath *path = selectedTree->getSelectionPath();
|
||||
TreeNodeWrapper *treeNode = static_cast<TreeNodeWrapper*>(path->getLastPathComponent());
|
||||
|
||||
// Set the clicked AST.
|
||||
viewer->treeLayout = new TreeLayout<Tree*>(new TreeLayoutAdaptor(static_cast<Tree*>(treeNode->getUserObject())), new TreeViewer::VariableExtentProvide(viewer), new DefaultConfiguration<Tree*>(viewer->gapBetweenLevels, viewer->gapBetweenNodes), true);
|
||||
|
||||
// Let the UI display this new AST.
|
||||
viewer->updatePreferredSize();
|
||||
}
|
||||
|
||||
void TreeViewer::generatePNGFile(TreeViewer *viewer, JDialog *dialog) {
|
||||
BufferedImage *bi = new BufferedImage(viewer->getSize()->width, viewer->getSize()->height, BufferedImage::TYPE_INT_ARGB);
|
||||
Graphics *g = bi->createGraphics();
|
||||
viewer->paint(g);
|
||||
g->dispose();
|
||||
|
||||
try {
|
||||
File *suggestedFile = generateNonExistingPngFile();
|
||||
JFileChooser *fileChooser = new JFileChooserConfirmOverwrite();
|
||||
fileChooser->setCurrentDirectory(suggestedFile->getParentFile());
|
||||
fileChooser->setSelectedFile(suggestedFile);
|
||||
FileFilter *pngFilter = new FileFilterAnonymousInnerClassHelper();
|
||||
|
||||
fileChooser->addChoosableFileFilter(pngFilter);
|
||||
fileChooser->setFileFilter(pngFilter);
|
||||
|
||||
int returnValue = fileChooser->showSaveDialog(dialog);
|
||||
if (returnValue == JFileChooser::APPROVE_OPTION) {
|
||||
File *pngFile = fileChooser->getSelectedFile();
|
||||
ImageIO::write(bi, L"png", pngFile);
|
||||
|
||||
try {
|
||||
// Try to open the parent folder using the OS' native file manager.
|
||||
Desktop::getDesktop()->open(pngFile->getParentFile());
|
||||
} catch (std::exception &ex) {
|
||||
// We could not launch the file manager: just show a popup that we
|
||||
// succeeded in saving the PNG file.
|
||||
JOptionPane::showMessageDialog(dialog, std::wstring(L"Saved PNG to: ") + pngFile->getAbsolutePath());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (std::exception &ex) {
|
||||
JOptionPane::showMessageDialog(dialog, std::wstring(L"Could not export to PNG: ") + ex.what(), L"Error", JOptionPane::ERROR_MESSAGE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
TreeViewer::FileFilterAnonymousInnerClassHelper::FileFilterAnonymousInnerClassHelper() {
|
||||
}
|
||||
|
||||
bool TreeViewer::FileFilterAnonymousInnerClassHelper::accept(File *pathname) {
|
||||
if (pathname->isFile()) {
|
||||
//JAVA TO C++ CONVERTER TODO TASK: There is no direct native C++ equivalent to the Java String 'endsWith' method:
|
||||
return pathname->getName()->toLowerCase()->endsWith(L".png");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::wstring TreeViewer::FileFilterAnonymousInnerClassHelper::getDescription() {
|
||||
return L"PNG Files (*.png)";
|
||||
}
|
||||
|
||||
File *TreeViewer::generateNonExistingPngFile() {
|
||||
|
||||
const std::wstring parent = L".";
|
||||
const std::wstring name = L"antlr4_parse_tree";
|
||||
const std::wstring extension = L".png";
|
||||
|
||||
File *pngFile = new File(parent, name + extension);
|
||||
|
||||
int counter = 1;
|
||||
|
||||
// Keep looping until we create a File that does not yet exist.
|
||||
while (pngFile->exists()) {
|
||||
pngFile = new File(parent, name + std::wstring(L"_") + StringConverterHelper::toString(counter) + extension);
|
||||
counter++;
|
||||
}
|
||||
|
||||
return pngFile;
|
||||
}
|
||||
|
||||
void TreeViewer::fillTree(TreeNodeWrapper *node, Tree *tree, TreeViewer *viewer) {
|
||||
|
||||
if (tree == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < tree->getChildCount(); i++) {
|
||||
|
||||
Tree *childTree = tree->getChild(i);
|
||||
TreeNodeWrapper *childNode = new TreeNodeWrapper(childTree, viewer);
|
||||
|
||||
node->add(childNode);
|
||||
|
||||
fillTree(childNode, childTree, viewer);
|
||||
}
|
||||
}
|
||||
|
||||
Dimension *TreeViewer::getScaledTreeSize() {
|
||||
Dimension *scaledTreeSize = treeLayout->getBounds()->getBounds()->getSize();
|
||||
scaledTreeSize = new Dimension(static_cast<int>(scaledTreeSize->width*scale), static_cast<int>(scaledTreeSize->height*scale));
|
||||
return scaledTreeSize;
|
||||
}
|
||||
|
||||
Future<JDialog*> *TreeViewer::open() {
|
||||
TreeViewer * const viewer = this;
|
||||
viewer->setScale(1.5);
|
||||
Callable<JDialog*> *callable = new CallableAnonymousInnerClassHelper(this, viewer);
|
||||
|
||||
ExecutorService *executor = Executors::newSingleThreadExecutor();
|
||||
|
||||
try {
|
||||
return executor->submit(callable);
|
||||
} finally {
|
||||
executor->shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
TreeViewer::CallableAnonymousInnerClassHelper::CallableAnonymousInnerClassHelper(TreeViewer *outerInstance, org::antlr::v4::runtime::tree::gui::TreeViewer *viewer) {
|
||||
this->outerInstance = outerInstance;
|
||||
this->viewer = viewer;
|
||||
}
|
||||
|
||||
JDialog *TreeViewer::CallableAnonymousInnerClassHelper::call() throw(std::exception) {
|
||||
SwingUtilities::invokeAndWait(new RunnableAnonymousInnerClassHelper(this));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
TreeViewer::CallableAnonymousInnerClassHelper::RunnableAnonymousInnerClassHelper::RunnableAnonymousInnerClassHelper(CallableAnonymousInnerClassHelper *outerInstance) {
|
||||
this->outerInstance = outerInstance;
|
||||
}
|
||||
|
||||
void TreeViewer::CallableAnonymousInnerClassHelper::RunnableAnonymousInnerClassHelper::run() {
|
||||
result = showInDialog(outerInstance->viewer);
|
||||
}
|
||||
|
||||
void TreeViewer::save(const std::wstring &fileName) throw(IOException, PrintException) {
|
||||
JDialog *dialog = new JDialog();
|
||||
Container *contentPane = dialog->getContentPane();
|
||||
(static_cast<JComponent*>(contentPane))->setBorder(BorderFactory::createEmptyBorder(10, 10, 10, 10));
|
||||
contentPane->add(this);
|
||||
contentPane->setBackground(Color::white);
|
||||
dialog->pack();
|
||||
dialog->setLocationRelativeTo(nullptr);
|
||||
dialog->dispose();
|
||||
GraphicsSupport::saveImage(this, fileName);
|
||||
}
|
||||
|
||||
Rectangle2D::Double *TreeViewer::getBoundsOfNode(Tree *node) {
|
||||
return treeLayout->getNodeBounds()->get(node);
|
||||
}
|
||||
|
||||
std::wstring TreeViewer::getText(Tree *tree) {
|
||||
std::wstring s = treeTextProvider->getText(tree);
|
||||
s = Utils::escapeWhitespace(s, true);
|
||||
return s;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::tree::gui::TreeTextProvider *TreeViewer::getTreeTextProvider() {
|
||||
return treeTextProvider;
|
||||
}
|
||||
|
||||
void TreeViewer::setTreeTextProvider(TreeTextProvider *treeTextProvider) {
|
||||
this->treeTextProvider = treeTextProvider;
|
||||
}
|
||||
|
||||
void TreeViewer::setFontSize(int sz) {
|
||||
fontSize = sz;
|
||||
font = new Font(fontName, fontStyle, fontSize);
|
||||
}
|
||||
|
||||
void TreeViewer::setFontName(const std::wstring &name) {
|
||||
fontName = name;
|
||||
font = new Font(fontName, fontStyle, fontSize);
|
||||
}
|
||||
|
||||
void TreeViewer::addHighlightedNodes(Collection<Tree*> *nodes) {
|
||||
highlightedNodes = std::vector<Tree*>();
|
||||
highlightedNodes.addAll(nodes);
|
||||
}
|
||||
|
||||
void TreeViewer::removeHighlightedNodes(Collection<Tree*> *nodes) {
|
||||
if (highlightedNodes.size() > 0) {
|
||||
// only remove exact objects defined by ==, not equals()
|
||||
for (auto t : nodes) {
|
||||
int i = getHighlightedNodeIndex(t);
|
||||
if (i >= 0) {
|
||||
highlightedNodes.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TreeViewer::isHighlighted(Tree *node) {
|
||||
return getHighlightedNodeIndex(node) >= 0;
|
||||
}
|
||||
|
||||
int TreeViewer::getHighlightedNodeIndex(Tree *node) {
|
||||
if (highlightedNodes.empty()) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < highlightedNodes.size(); i++) {
|
||||
Tree *t = highlightedNodes[i];
|
||||
if (t == node) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Font *TreeViewer::getFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
void TreeViewer::setFont(Font *font) {
|
||||
this->font = font;
|
||||
}
|
||||
|
||||
int TreeViewer::getArcSize() {
|
||||
return arcSize;
|
||||
}
|
||||
|
||||
void TreeViewer::setArcSize(int arcSize) {
|
||||
this->arcSize = arcSize;
|
||||
}
|
||||
|
||||
Color *TreeViewer::getBoxColor() {
|
||||
return boxColor;
|
||||
}
|
||||
|
||||
void TreeViewer::setBoxColor(Color *boxColor) {
|
||||
this->boxColor = boxColor;
|
||||
}
|
||||
|
||||
Color *TreeViewer::getHighlightedBoxColor() {
|
||||
return highlightedBoxColor;
|
||||
}
|
||||
|
||||
void TreeViewer::setHighlightedBoxColor(Color *highlightedBoxColor) {
|
||||
this->highlightedBoxColor = highlightedBoxColor;
|
||||
}
|
||||
|
||||
Color *TreeViewer::getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
void TreeViewer::setBorderColor(Color *borderColor) {
|
||||
this->borderColor = borderColor;
|
||||
}
|
||||
|
||||
Color *TreeViewer::getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
|
||||
void TreeViewer::setTextColor(Color *textColor) {
|
||||
this->textColor = textColor;
|
||||
}
|
||||
|
||||
TreeForTreeLayout<Tree*> *TreeViewer::getTree() {
|
||||
return treeLayout->getTree();
|
||||
}
|
||||
|
||||
double TreeViewer::getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
void TreeViewer::setScale(double scale) {
|
||||
if (scale <= 0) {
|
||||
scale = 1;
|
||||
}
|
||||
this->scale = scale;
|
||||
updatePreferredSize();
|
||||
}
|
||||
|
||||
void TreeViewer::InitializeInstanceFields() {
|
||||
fontName = L"Helvetica";
|
||||
fontStyle = java::awt::Font::PLAIN;
|
||||
fontSize = 11;
|
||||
font = new java::awt::Font(fontName, fontStyle, fontSize);
|
||||
gapBetweenLevels = 17;
|
||||
gapBetweenNodes = 7;
|
||||
nodeWidthPadding = 2;
|
||||
nodeHeightPadding = 0;
|
||||
arcSize = 0;
|
||||
scale = 1.0;
|
||||
boxColor = 0;
|
||||
highlightedBoxColor = java::awt::Color::lightGray;
|
||||
borderColor = 0;
|
||||
textColor = java::awt::Color::black;
|
||||
useCurvedEdges = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,333 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "TreeTextProvider.h"
|
||||
#include "Java/src/org/antlr/v4/runtime/tree/Tree.h"
|
||||
#include "TreePostScriptGenerator.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include "stringconverter.h"
|
||||
|
||||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
namespace runtime {
|
||||
namespace tree {
|
||||
namespace gui {
|
||||
|
||||
using org::abego::treelayout::NodeExtentProvider;
|
||||
using org::abego::treelayout::TreeForTreeLayout;
|
||||
using org::abego::treelayout::TreeLayout;
|
||||
using org::abego::treelayout::util::DefaultConfiguration;
|
||||
using org::antlr::v4::runtime::misc::GraphicsSupport;
|
||||
using org::antlr::v4::runtime::misc::JFileChooserConfirmOverwrite;
|
||||
using org::antlr::v4::runtime::misc::NotNull;
|
||||
using org::antlr::v4::runtime::misc::Nullable;
|
||||
using org::antlr::v4::runtime::misc::Utils;
|
||||
using org::antlr::v4::runtime::tree::ErrorNode;
|
||||
using org::antlr::v4::runtime::tree::Tree;
|
||||
using org::antlr::v4::runtime::tree::Trees;
|
||||
|
||||
|
||||
class TreeViewer : public JComponent {
|
||||
public:
|
||||
class DefaultTreeTextProvider : public TreeTextProvider {
|
||||
private:
|
||||
const std::vector<std::wstring> ruleNames;
|
||||
|
||||
public:
|
||||
DefaultTreeTextProvider(std::vector<std::wstring> &ruleNames);
|
||||
|
||||
virtual std::wstring getText(Tree *node) override;
|
||||
};
|
||||
|
||||
public:
|
||||
class VariableExtentProvide : public NodeExtentProvider<Tree*> {
|
||||
public:
|
||||
TreeViewer *viewer;
|
||||
VariableExtentProvide(TreeViewer *viewer);
|
||||
virtual double getWidth(Tree *tree) override;
|
||||
|
||||
virtual double getHeight(Tree *tree) override;
|
||||
};
|
||||
|
||||
private:
|
||||
class TreeNodeWrapper : public DefaultMutableTreeNode {
|
||||
|
||||
public:
|
||||
TreeViewer *const viewer;
|
||||
|
||||
TreeNodeWrapper(Tree *tree, TreeViewer *viewer);
|
||||
|
||||
virtual std::wstring toString() override;
|
||||
};
|
||||
|
||||
private:
|
||||
class EmptyIcon : public Icon {
|
||||
|
||||
public:
|
||||
virtual int getIconWidth() override;
|
||||
|
||||
virtual int getIconHeight() override;
|
||||
|
||||
virtual void paintIcon(Component *c, Graphics *g, int x, int y) override;
|
||||
};
|
||||
public:
|
||||
static Color *const LIGHT_RED;
|
||||
|
||||
protected:
|
||||
TreeTextProvider *treeTextProvider;
|
||||
TreeLayout<Tree*> *treeLayout;
|
||||
std::vector<Tree*> highlightedNodes;
|
||||
|
||||
std::wstring fontName; //Font.SANS_SERIF;
|
||||
int fontStyle;
|
||||
int fontSize;
|
||||
Font *font;
|
||||
|
||||
double gapBetweenLevels;
|
||||
double gapBetweenNodes;
|
||||
int nodeWidthPadding; // added to left/right
|
||||
int nodeHeightPadding; // added above/below
|
||||
int arcSize; // make an arc in node outline?
|
||||
|
||||
double scale;
|
||||
|
||||
Color *boxColor; // set to a color to make it draw background
|
||||
|
||||
Color *highlightedBoxColor;
|
||||
Color *borderColor;
|
||||
Color *textColor;
|
||||
|
||||
public:
|
||||
TreeViewer(std::vector<std::wstring> &ruleNames, Tree *tree);
|
||||
|
||||
private:
|
||||
void updatePreferredSize();
|
||||
|
||||
// ---------------- PAINT -----------------------------------------------
|
||||
|
||||
bool useCurvedEdges;
|
||||
|
||||
public:
|
||||
virtual bool getUseCurvedEdges();
|
||||
|
||||
virtual void setUseCurvedEdges(bool useCurvedEdges);
|
||||
|
||||
protected:
|
||||
virtual void paintEdges(Graphics *g, Tree *parent);
|
||||
|
||||
virtual void paintBox(Graphics *g, Tree *tree);
|
||||
|
||||
public:
|
||||
virtual void text(Graphics *g, const std::wstring &s, int x, int y);
|
||||
|
||||
virtual void paint(Graphics *g) override;
|
||||
|
||||
protected:
|
||||
virtual Graphics *getComponentGraphics(Graphics *g) override;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
static JDialog *showInDialog(TreeViewer *const viewer);
|
||||
|
||||
private:
|
||||
class ActionListenerAnonymousInnerClassHelper : public ActionListener {
|
||||
private:
|
||||
JDialog *dialog;
|
||||
|
||||
public:
|
||||
ActionListenerAnonymousInnerClassHelper(JDialog *dialog);
|
||||
|
||||
virtual void actionPerformed(ActionEvent *e) override;
|
||||
};
|
||||
|
||||
private:
|
||||
class ActionListenerAnonymousInnerClassHelper2 : public ActionListener {
|
||||
private:
|
||||
org::antlr::v4::runtime::tree::gui::TreeViewer *viewer;
|
||||
JDialog *dialog;
|
||||
|
||||
public:
|
||||
ActionListenerAnonymousInnerClassHelper2(org::antlr::v4::runtime::tree::gui::TreeViewer *viewer, JDialog *dialog);
|
||||
|
||||
virtual void actionPerformed(ActionEvent *e) override;
|
||||
};
|
||||
|
||||
private:
|
||||
class ChangeListenerAnonymousInnerClassHelper : public ChangeListener {
|
||||
private:
|
||||
org::antlr::v4::runtime::tree::gui::TreeViewer *viewer;
|
||||
JSlider *scaleSlider;
|
||||
|
||||
public:
|
||||
ChangeListenerAnonymousInnerClassHelper(org::antlr::v4::runtime::tree::gui::TreeViewer *viewer, JSlider *scaleSlider);
|
||||
|
||||
virtual void stateChanged(ChangeEvent *e) override;
|
||||
};
|
||||
|
||||
private:
|
||||
class TreeSelectionListenerAnonymousInnerClassHelper : public TreeSelectionListener {
|
||||
private:
|
||||
org::antlr::v4::runtime::tree::gui::TreeViewer *viewer;
|
||||
|
||||
public:
|
||||
TreeSelectionListenerAnonymousInnerClassHelper(org::antlr::v4::runtime::tree::gui::TreeViewer *viewer);
|
||||
|
||||
virtual void valueChanged(TreeSelectionEvent *e) override;
|
||||
};
|
||||
|
||||
private:
|
||||
static void generatePNGFile(TreeViewer *viewer, JDialog *dialog);
|
||||
|
||||
private:
|
||||
class FileFilterAnonymousInnerClassHelper : public FileFilter {
|
||||
public:
|
||||
FileFilterAnonymousInnerClassHelper();
|
||||
|
||||
|
||||
virtual bool accept(File *pathname) override;
|
||||
|
||||
virtual std::wstring getDescription() override;
|
||||
};
|
||||
|
||||
private:
|
||||
static File *generateNonExistingPngFile();
|
||||
|
||||
static void fillTree(TreeNodeWrapper *node, Tree *tree, TreeViewer *viewer);
|
||||
|
||||
Dimension *getScaledTreeSize();
|
||||
|
||||
public:
|
||||
virtual Future<JDialog*> *open();
|
||||
|
||||
private:
|
||||
class CallableAnonymousInnerClassHelper : public Callable<JDialog*> {
|
||||
private:
|
||||
TreeViewer *const outerInstance;
|
||||
|
||||
org::antlr::v4::runtime::tree::gui::TreeViewer *viewer;
|
||||
|
||||
public:
|
||||
CallableAnonymousInnerClassHelper(TreeViewer *outerInstance, org::antlr::v4::runtime::tree::gui::TreeViewer *viewer);
|
||||
|
||||
JDialog *result;
|
||||
|
||||
virtual JDialog *call() throw(std::exception) override;
|
||||
|
||||
private:
|
||||
class RunnableAnonymousInnerClassHelper : public Runnable {
|
||||
private:
|
||||
CallableAnonymousInnerClassHelper *const outerInstance;
|
||||
|
||||
public:
|
||||
RunnableAnonymousInnerClassHelper(CallableAnonymousInnerClassHelper *outerInstance);
|
||||
|
||||
virtual void run() override;
|
||||
};
|
||||
};
|
||||
|
||||
public:
|
||||
virtual void save(const std::wstring &fileName) throw(IOException, PrintException);
|
||||
|
||||
// ---------------------------------------------------
|
||||
|
||||
protected:
|
||||
virtual Rectangle2D::Double *getBoundsOfNode(Tree *node);
|
||||
|
||||
virtual std::wstring getText(Tree *tree);
|
||||
|
||||
public:
|
||||
virtual TreeTextProvider *getTreeTextProvider();
|
||||
|
||||
virtual void setTreeTextProvider(TreeTextProvider *treeTextProvider);
|
||||
|
||||
virtual void setFontSize(int sz);
|
||||
|
||||
virtual void setFontName(const std::wstring &name);
|
||||
|
||||
/// <summary>
|
||||
/// Slow for big lists of highlighted nodes </summary>
|
||||
virtual void addHighlightedNodes(Collection<Tree*> *nodes);
|
||||
|
||||
virtual void removeHighlightedNodes(Collection<Tree*> *nodes);
|
||||
|
||||
protected:
|
||||
virtual bool isHighlighted(Tree *node);
|
||||
|
||||
virtual int getHighlightedNodeIndex(Tree *node);
|
||||
|
||||
public:
|
||||
virtual Font *getFont() override;
|
||||
|
||||
virtual void setFont(Font *font) override;
|
||||
|
||||
virtual int getArcSize();
|
||||
|
||||
virtual void setArcSize(int arcSize);
|
||||
|
||||
virtual Color *getBoxColor();
|
||||
|
||||
virtual void setBoxColor(Color *boxColor);
|
||||
|
||||
virtual Color *getHighlightedBoxColor();
|
||||
|
||||
virtual void setHighlightedBoxColor(Color *highlightedBoxColor);
|
||||
|
||||
virtual Color *getBorderColor();
|
||||
|
||||
virtual void setBorderColor(Color *borderColor);
|
||||
|
||||
virtual Color *getTextColor();
|
||||
|
||||
virtual void setTextColor(Color *textColor);
|
||||
|
||||
protected:
|
||||
virtual TreeForTreeLayout<Tree*> *getTree();
|
||||
|
||||
public:
|
||||
virtual double getScale();
|
||||
|
||||
virtual void setScale(double scale);
|
||||
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -118,7 +118,12 @@ ParseTreePattern ParseTreePatternMatcher::compile(const std::wstring &pattern, i
|
|||
parserInterp.setErrorHandler(std::make_shared<BailErrorStrategy>());
|
||||
tree = parserInterp.parse(patternRuleIndex);
|
||||
} catch (ParseCancellationException &e) {
|
||||
std::rethrow_if_nested(e);
|
||||
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026
|
||||
// rethrow_if_nested is not available before VS 2015.
|
||||
throw e;
|
||||
#else
|
||||
std::rethrow_if_nested(e); // Unwrap the nested exception.
|
||||
#endif
|
||||
} catch (RecognitionException &re) {
|
||||
throw re;
|
||||
} catch (std::exception &e) {
|
||||
|
@ -126,7 +131,7 @@ ParseTreePattern ParseTreePatternMatcher::compile(const std::wstring &pattern, i
|
|||
// throw_with_nested is not available before VS 2015.
|
||||
throw e;
|
||||
#else
|
||||
std::throw_with_nested("Cannot invoke start rule");
|
||||
std::throw_with_nested("Cannot invoke start rule"); // Wrap any other exception. We should however probably use one of the ANTLR exceptions here.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue