Merge pull request #1491 from mike-lischke/master

Fix for multithreading issues
This commit is contained in:
Terence Parr 2016-12-13 11:35:11 -08:00 committed by GitHub
commit f35576a7f2
32 changed files with 786 additions and 89 deletions

View File

@ -1,8 +1,5 @@
# Integrating ANTLR into Development Systems
The Java target is the reference implementation mirrored by other targets. The following pages help you integrate ANTLR into development environments and build systems appropriate for your target language. As of January 2015, we have Java, C#, Python 2, Python 3, and JavaScript targets.
The Java target is the reference implementation mirrored by other targets. The following pages help you integrate ANTLR into development environments and build systems appropriate for your target language. As of December 2016, we have Java, C#, Python 2, Python 3, JavaScript, Go, C++, and Swift targets.
The easiest thing is probably just to use an [ANTLR plug-in](http://www.antlr.org/tools.html) for your favorite development environment.
Java IDE Integration
C# IDE Integration

View File

@ -0,0 +1,362 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug DLL|Win32">
<Configuration>Debug DLL</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug DLL|x64">
<Configuration>Debug DLL</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug Static|Win32">
<Configuration>Debug Static</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug Static|x64">
<Configuration>Debug Static</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release DLL|Win32">
<Configuration>Release DLL</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release DLL|x64">
<Configuration>Release DLL</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Static|Win32">
<Configuration>Release Static</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Static|x64">
<Configuration>Release Static</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{24EC5104-7402-4C76-B66B-27ADBE062D68}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>antlr4cppdemo</RootNamespace>
<ProjectName>antlr4cpp-demo</ProjectName>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\vs-2015\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>ANTLR4CPP_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>ANTLR4CPP_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>ANTLR4CPP_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>ANTLR4CPP_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\generated;$(SolutionDir)..\..\runtime\src;$(SolutionDir)..\..\runtime\src\atn;$(SolutionDir)..\..\runtime\src\dfa;$(SolutionDir)..\..\runtime\src\misc;$(SolutionDir)..\..\runtime\src\support;$(SolutionDir)..\..\runtime\src\tree;$(SolutionDir)..\..\runtime\src\tree\xpath;$(SolutionDir)..\..\runtime\src\tree\pattern;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\generated\TLexer.cpp" />
<ClCompile Include="..\..\generated\TParser.cpp" />
<ClCompile Include="..\..\generated\TParserBaseListener.cpp" />
<ClCompile Include="..\..\generated\TParserBaseVisitor.cpp" />
<ClCompile Include="..\..\generated\TParserListener.cpp" />
<ClCompile Include="..\..\generated\TParserVisitor.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\generated\TLexer.h" />
<ClInclude Include="..\..\generated\TParser.h" />
<ClInclude Include="..\..\generated\TParserBaseListener.h" />
<ClInclude Include="..\..\generated\TParserBaseVisitor.h" />
<ClInclude Include="..\..\generated\TParserListener.h" />
<ClInclude Include="..\..\generated\TParserVisitor.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\runtime\antlr4cpp-vs2015.vcxproj">
<Project>{a9762991-1b57-4dce-90c0-ee42b96947be}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="generated">
<UniqueIdentifier>{ef397b7b-1192-4d44-93ed-fadaec7622e8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\generated\TParser.cpp">
<Filter>generated</Filter>
</ClCompile>
<ClCompile Include="..\..\generated\TParserBaseListener.cpp">
<Filter>generated</Filter>
</ClCompile>
<ClCompile Include="..\..\generated\TParserBaseVisitor.cpp">
<Filter>generated</Filter>
</ClCompile>
<ClCompile Include="..\..\generated\TParserListener.cpp">
<Filter>generated</Filter>
</ClCompile>
<ClCompile Include="..\..\generated\TParserVisitor.cpp">
<Filter>generated</Filter>
</ClCompile>
<ClCompile Include="..\..\generated\TLexer.cpp">
<Filter>generated</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\generated\TLexer.h">
<Filter>generated</Filter>
</ClInclude>
<ClInclude Include="..\..\generated\TParser.h">
<Filter>generated</Filter>
</ClInclude>
<ClInclude Include="..\..\generated\TParserBaseListener.h">
<Filter>generated</Filter>
</ClInclude>
<ClInclude Include="..\..\generated\TParserBaseVisitor.h">
<Filter>generated</Filter>
</ClInclude>
<ClInclude Include="..\..\generated\TParserListener.h">
<Filter>generated</Filter>
</ClInclude>
<ClInclude Include="..\..\generated\TParserVisitor.h">
<Filter>generated</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -30,16 +30,12 @@ int main(int argc, const char * argv[]) {
CommonTokenStream tokens(&lexer);
TParser parser(&tokens);
tree::ParseTree* tree = parser.main();
tree::ParseTree *tree = parser.main();
std::wstring s = antlrcpp::s2ws(tree->toStringTree(&parser)) + L"\n";
// Unfortunately, there is no way of showing the Unicode output properly in either the Intermediate Window in VS
// (when using OutputDebugString), nor in a terminal (when using wcout). Instead set a breakpoint and view the
// content of s in the debugger, which works fine.
OutputDebugString(s.data());
std::wcout << "Parse Tree: " << s << std::endl;
OutputDebugString(s.data()); // Only works properly since VS 2015.
//std::wcout << "Parse Tree: " << s << std::endl; Unicode output in the console is very limited.
return 0;
}

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "antlr4cpp-vs2015", "..\..\runtime\antlr4cpp-vs2015.vcxproj", "{A9762991-1B57-4DCE-90C0-EE42B96947BE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "antlr4cpp-demo", "antlr4-cpp-demo\antlr4-cpp-demo-vs2015.vcxproj", "{24EC5104-7402-4C76-B66B-27ADBE062D68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug DLL|x64 = Debug DLL|x64
@ -33,6 +35,22 @@ Global
{A9762991-1B57-4DCE-90C0-EE42B96947BE}.Release Static|x64.Build.0 = Release Static|x64
{A9762991-1B57-4DCE-90C0-EE42B96947BE}.Release Static|x86.ActiveCfg = Release Static|Win32
{A9762991-1B57-4DCE-90C0-EE42B96947BE}.Release Static|x86.Build.0 = Release Static|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug DLL|x64.ActiveCfg = Debug DLL|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug DLL|x64.Build.0 = Debug DLL|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug DLL|x86.ActiveCfg = Debug DLL|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug DLL|x86.Build.0 = Debug DLL|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug Static|x64.ActiveCfg = Debug Static|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug Static|x64.Build.0 = Debug Static|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug Static|x86.ActiveCfg = Debug Static|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Debug Static|x86.Build.0 = Debug Static|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release DLL|x64.ActiveCfg = Release DLL|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release DLL|x64.Build.0 = Release DLL|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release DLL|x86.ActiveCfg = Release DLL|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release DLL|x86.Build.0 = Release DLL|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release Static|x64.ActiveCfg = Release Static|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release Static|x64.Build.0 = Release Static|x64
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release Static|x86.ActiveCfg = Release Static|Win32
{24EC5104-7402-4C76-B66B-27ADBE062D68}.Release Static|x86.Build.0 = Release Static|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -6,7 +6,7 @@
:: Download the ANLTR jar and place it in the same folder as this script (or adjust the LOCATION var accordingly).
set LOCATION=antlr4-4.5.4-SNAPSHOT.jar
set LOCATION=antlr-4.6-complete.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

View File

@ -3,7 +3,7 @@
# Zip it
rm -f antlr4-cpp-runtime-source.zip
zip -r antlr4-cpp-runtime-source.zip "README.md" "cmake" "demo" "runtime" "CMakeLists.txt" "License.txt" "deploy-macos.sh" "deploy-source.sh" "deploy-windows.cmd" "VERSION" \
-X -x "*.DS_Store*" "antlrcpp.xcodeproj/xcuserdata/*" "*Build*" "*DerivedData*" "*.jar" "demo/generated/*" "*.vscode*"
-X -x "*.DS_Store*" "antlrcpp.xcodeproj/xcuserdata/*" "*Build*" "*DerivedData*" "*.jar" "demo/generated/*" "*.vscode*" "runtime/build/*"
# Deploy
#cp antlr4-cpp-runtime-source.zip ~/antlr/sites/website-antlr4/download

View File

@ -74,7 +74,7 @@ install(TARGETS antlr4_static
ARCHIVE DESTINATION lib)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/runtime/src/"
DESTINATION "include"
DESTINATION "include/antlr4-runtime"
COMPONENT dev
FILES_MATCHING PATTERN "*.h"
)

View File

@ -173,13 +173,15 @@
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>ANTLR4CPP_DLL;ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -197,6 +199,8 @@
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -207,13 +211,15 @@
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>ANTLR4CPP_DLL;ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -231,6 +237,8 @@
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -250,6 +258,7 @@
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -271,6 +280,7 @@
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -292,6 +302,7 @@
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -313,6 +324,7 @@
<ForcedIncludeFiles>
</ForcedIncludeFiles>
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -430,6 +442,7 @@
<ClCompile Include="src\TokenStream.cpp" />
<ClCompile Include="src\TokenStreamRewriter.cpp" />
<ClCompile Include="src\tree\ErrorNodeImpl.cpp" />
<ClCompile Include="src\tree\IterativeParseTreeWalker.cpp" />
<ClCompile Include="src\tree\ParseTree.cpp" />
<ClCompile Include="src\tree\ParseTreeWalker.cpp" />
<ClCompile Include="src\tree\pattern\ParseTreeMatch.cpp" />
@ -584,6 +597,7 @@
<ClInclude Include="src\tree\AbstractParseTreeVisitor.h" />
<ClInclude Include="src\tree\ErrorNode.h" />
<ClInclude Include="src\tree\ErrorNodeImpl.h" />
<ClInclude Include="src\tree\IterativeParseTreeWalker.h" />
<ClInclude Include="src\tree\ParseTree.h" />
<ClInclude Include="src\tree\ParseTreeListener.h" />
<ClInclude Include="src\tree\ParseTreeProperty.h" />
@ -601,7 +615,6 @@
<ClInclude Include="src\tree\SyntaxTree.h" />
<ClInclude Include="src\tree\TerminalNode.h" />
<ClInclude Include="src\tree\TerminalNodeImpl.h" />
<ClInclude Include="src\tree\Tree.h" />
<ClInclude Include="src\tree\Trees.h" />
<ClInclude Include="src\tree\xpath\XPath.h" />
<ClInclude Include="src\tree\xpath\XPathElement.h" />

View File

@ -393,9 +393,6 @@
<ClInclude Include="src\tree\TerminalNodeImpl.h">
<Filter>Header Files\tree</Filter>
</ClInclude>
<ClInclude Include="src\tree\Tree.h">
<Filter>Header Files\tree</Filter>
</ClInclude>
<ClInclude Include="src\tree\Trees.h">
<Filter>Header Files\tree</Filter>
</ClInclude>
@ -540,6 +537,9 @@
<ClInclude Include="src\support\Any.h">
<Filter>Source Files\support</Filter>
</ClInclude>
<ClInclude Include="src\tree\IterativeParseTreeWalker.h">
<Filter>Header Files\tree</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\ANTLRFileStream.cpp">
@ -938,5 +938,8 @@
<ClCompile Include="src\tree\ParseTree.cpp">
<Filter>Source Files\tree</Filter>
</ClCompile>
<ClCompile Include="src\tree\IterativeParseTreeWalker.cpp">
<Filter>Source Files\tree</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -812,6 +812,12 @@
27B36AC91DACE7AF0069C868 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27B36AC51DACE7AF0069C868 /* RuleContextWithAltNum.h */; };
27B36ACA1DACE7AF0069C868 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27B36AC51DACE7AF0069C868 /* RuleContextWithAltNum.h */; };
27B36ACB1DACE7AF0069C868 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27B36AC51DACE7AF0069C868 /* RuleContextWithAltNum.h */; };
27D414521DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27D414501DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp */; };
27D414531DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27D414501DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp */; };
27D414541DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27D414501DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp */; };
27D414551DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h in Headers */ = {isa = PBXBuildFile; fileRef = 27D414511DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h */; };
27D414561DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h in Headers */ = {isa = PBXBuildFile; fileRef = 27D414511DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h */; };
27D414571DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h in Headers */ = {isa = PBXBuildFile; fileRef = 27D414511DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h */; };
27DB449D1D045537007E790B /* XPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27DB448B1D045537007E790B /* XPath.cpp */; };
27DB449E1D045537007E790B /* XPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 27DB448C1D045537007E790B /* XPath.h */; };
27DB449F1D045537007E790B /* XPathElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27DB448D1D045537007E790B /* XPathElement.cpp */; };
@ -1090,7 +1096,7 @@
276E5CE51CDB57AA003FF4B4 /* Arrays.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Arrays.cpp; sourceTree = "<group>"; };
276E5CE61CDB57AA003FF4B4 /* Arrays.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Arrays.h; sourceTree = "<group>"; };
276E5CE71CDB57AA003FF4B4 /* BitSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitSet.h; sourceTree = "<group>"; };
276E5CE81CDB57AA003FF4B4 /* CPPUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPPUtils.cpp; sourceTree = "<group>"; };
276E5CE81CDB57AA003FF4B4 /* CPPUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPPUtils.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5CE91CDB57AA003FF4B4 /* CPPUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = CPPUtils.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
276E5CEA1CDB57AA003FF4B4 /* Declarations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Declarations.h; sourceTree = "<group>"; };
276E5CEB1CDB57AA003FF4B4 /* guid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = guid.cpp; sourceTree = "<group>"; };
@ -1150,6 +1156,8 @@
27AC52CF1CE773A80093AAAB /* antlr4-runtime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "antlr4-runtime.h"; sourceTree = "<group>"; };
27B36AC41DACE7AF0069C868 /* RuleContextWithAltNum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuleContextWithAltNum.cpp; sourceTree = "<group>"; };
27B36AC51DACE7AF0069C868 /* RuleContextWithAltNum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuleContextWithAltNum.h; sourceTree = "<group>"; };
27D414501DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IterativeParseTreeWalker.cpp; sourceTree = "<group>"; };
27D414511DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IterativeParseTreeWalker.h; sourceTree = "<group>"; };
27DB448B1D045537007E790B /* XPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XPath.cpp; sourceTree = "<group>"; wrapsLines = 0; };
27DB448C1D045537007E790B /* XPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPath.h; sourceTree = "<group>"; wrapsLines = 0; };
27DB448D1D045537007E790B /* XPathElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XPathElement.cpp; sourceTree = "<group>"; wrapsLines = 0; };
@ -1499,6 +1507,8 @@
276E5CFB1CDB57AA003FF4B4 /* ErrorNode.h */,
276E5CFC1CDB57AA003FF4B4 /* ErrorNodeImpl.cpp */,
276E5CFD1CDB57AA003FF4B4 /* ErrorNodeImpl.h */,
27D414501DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp */,
27D414511DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h */,
276566DF1DA93BFB000869BE /* ParseTree.cpp */,
276E5CFE1CDB57AA003FF4B4 /* ParseTree.h */,
276E5D001CDB57AA003FF4B4 /* ParseTreeListener.h */,
@ -1721,6 +1731,7 @@
276E5E411CDB57AA003FF4B4 /* NotSetTransition.h in Headers */,
276E5E891CDB57AA003FF4B4 /* RangeTransition.h in Headers */,
27DB44D21D0463DB007E790B /* XPathRuleElement.h in Headers */,
27D414571DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h in Headers */,
276E601B1CDB57AA003FF4B4 /* ParseTreePattern.h in Headers */,
276E5DFC1CDB57AA003FF4B4 /* LexerCustomAction.h in Headers */,
276E5FE81CDB57AA003FF4B4 /* TokenStreamRewriter.h in Headers */,
@ -1795,6 +1806,7 @@
276E5EA01CDB57AA003FF4B4 /* SemanticContext.h in Headers */,
276E5F5D1CDB57AA003FF4B4 /* ListTokenSource.h in Headers */,
276E5F8D1CDB57AA003FF4B4 /* ParserInterpreter.h in Headers */,
27D414561DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h in Headers */,
276E5DDD1CDB57AA003FF4B4 /* LexerActionExecutor.h in Headers */,
276E5F4B1CDB57AA003FF4B4 /* Lexer.h in Headers */,
276E5F631CDB57AA003FF4B4 /* Interval.h in Headers */,
@ -2046,6 +2058,7 @@
276E5E3F1CDB57AA003FF4B4 /* NotSetTransition.h in Headers */,
276E5E871CDB57AA003FF4B4 /* RangeTransition.h in Headers */,
276E60191CDB57AA003FF4B4 /* ParseTreePattern.h in Headers */,
27D414551DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.h in Headers */,
276E5DFA1CDB57AA003FF4B4 /* LexerCustomAction.h in Headers */,
276E5FE61CDB57AA003FF4B4 /* TokenStreamRewriter.h in Headers */,
276E5DEE1CDB57AA003FF4B4 /* LexerATNSimulator.h in Headers */,
@ -2263,6 +2276,7 @@
27B36AC81DACE7AF0069C868 /* RuleContextWithAltNum.cpp in Sources */,
276E5F101CDB57AA003FF4B4 /* DFASerializer.cpp in Sources */,
276E5F2E1CDB57AA003FF4B4 /* FailedPredicateException.cpp in Sources */,
27D414541DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp in Sources */,
276E5F8B1CDB57AA003FF4B4 /* ParserInterpreter.cpp in Sources */,
276E5D4E1CDB57AA003FF4B4 /* AmbiguityInfo.cpp in Sources */,
276E5F161CDB57AA003FF4B4 /* DFAState.cpp in Sources */,
@ -2402,6 +2416,7 @@
27B36AC71DACE7AF0069C868 /* RuleContextWithAltNum.cpp in Sources */,
276E5F0F1CDB57AA003FF4B4 /* DFASerializer.cpp in Sources */,
276E5F2D1CDB57AA003FF4B4 /* FailedPredicateException.cpp in Sources */,
27D414531DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp in Sources */,
276E5F8A1CDB57AA003FF4B4 /* ParserInterpreter.cpp in Sources */,
276E5D4D1CDB57AA003FF4B4 /* AmbiguityInfo.cpp in Sources */,
276E5F151CDB57AA003FF4B4 /* DFAState.cpp in Sources */,
@ -2541,6 +2556,7 @@
27B36AC61DACE7AF0069C868 /* RuleContextWithAltNum.cpp in Sources */,
276E5F0E1CDB57AA003FF4B4 /* DFASerializer.cpp in Sources */,
276E5F2C1CDB57AA003FF4B4 /* FailedPredicateException.cpp in Sources */,
27D414521DEB0D3D00D0F3F9 /* IterativeParseTreeWalker.cpp in Sources */,
27DB44A71D045537007E790B /* XPathTokenAnywhereElement.cpp in Sources */,
276E5F891CDB57AA003FF4B4 /* ParserInterpreter.cpp in Sources */,
276E5D4C1CDB57AA003FF4B4 /* AmbiguityInfo.cpp in Sources */,

View File

@ -358,18 +358,17 @@ std::string BufferedTokenStream::getSourceName() const
}
std::string BufferedTokenStream::getText() {
lazyInit();
fill();
return getText(misc::Interval(0U, size() - 1));
}
std::string BufferedTokenStream::getText(const misc::Interval &interval) {
lazyInit();
fill();
size_t start = interval.a;
size_t stop = interval.b;
if (start == INVALID_INDEX || stop == INVALID_INDEX) {
return "";
}
lazyInit();
if (stop >= _tokens.size()) {
stop = _tokens.size() - 1;
}

View File

@ -212,7 +212,7 @@ const atn::ATN& Parser::getATNWithBypassAlts() {
throw UnsupportedOperationException("The current parser does not support an ATN with bypass alternatives.");
}
std::lock_guard<std::recursive_mutex> lck(_mutex);
std::lock_guard<std::mutex> lck(_mutex);
// XXX: using the entire serialized ATN as key into the map is a big resource waste.
// How large can that thing become?
@ -544,7 +544,7 @@ std::vector<std::string> Parser::getRuleInvocationStack(RuleContext *p) {
std::vector<std::string> Parser::getDFAStrings() {
atn::ParserATNSimulator *simulator = getInterpreter<atn::ParserATNSimulator>();
if (!simulator->decisionToDFA.empty()) {
std::lock_guard<std::recursive_mutex> lck(_mutex);
std::lock_guard<std::mutex> lck(_mutex);
std::vector<std::string> s;
for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) {
@ -559,7 +559,7 @@ std::vector<std::string> Parser::getDFAStrings() {
void Parser::dumpDFA() {
atn::ParserATNSimulator *simulator = getInterpreter<atn::ParserATNSimulator>();
if (!simulator->decisionToDFA.empty()) {
std::lock_guard<std::recursive_mutex> lck(_mutex);
std::lock_guard<std::mutex> lck(_mutex);
bool seenOne = false;
for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) {
dfa::DFA &dfa = simulator->decisionToDFA[d];

View File

@ -35,7 +35,7 @@ dfa::Vocabulary const& Recognizer::getVocabulary() const {
std::map<std::string, size_t> Recognizer::getTokenTypeMap() {
const dfa::Vocabulary& vocabulary = getVocabulary();
std::lock_guard<std::recursive_mutex> lck(_mutex);
std::lock_guard<std::mutex> lck(_mutex);
std::map<std::string, size_t> result;
auto iterator = _tokenTypeMapCache.find(&vocabulary);
if (iterator != _tokenTypeMapCache.end()) {
@ -65,7 +65,7 @@ std::map<std::string, size_t> Recognizer::getRuleIndexMap() {
throw "The current recognizer does not provide a list of rule names.";
}
std::lock_guard<std::recursive_mutex> lck(_mutex);
std::lock_guard<std::mutex> lck(_mutex);
std::map<std::string, size_t> result;
auto iterator = _ruleIndexMapCache.find(ruleNames);
if (iterator != _ruleIndexMapCache.end()) {

View File

@ -142,7 +142,7 @@ namespace antlr4 {
atn::ATNSimulator *_interpreter; // Set and deleted in descendants (or the profiler).
// Mutex to manage synchronized access for multithreading.
std::recursive_mutex _mutex;
std::mutex _mutex;
private:
static std::map<const dfa::Vocabulary*, std::map<std::string, size_t>> _tokenTypeMapCache;

View File

@ -360,7 +360,6 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
// WALK INSERTS
for (size_t i = 0; i < rewrites.size(); i++) {
RewriteOperation *op = rewrites[i];
InsertBeforeOp *iop = dynamic_cast<InsertBeforeOp *>(rewrites[i]);
if (iop == nullptr)
continue;

View File

@ -32,6 +32,7 @@
#include <mutex>
#include <exception>
#include <bitset>
#include <condition_variable>
// Defines for the Guid class and other platform dependent stuff.
#ifdef _WIN32
@ -58,21 +59,17 @@
typedef std::basic_string<__int32> i32string;
#endif
#ifdef ANTLR4CPP_DLL
#define SHARED_LIB 1
#ifdef ANTLR4CPP_EXPORTS
#define ANTLR4CPP_PUBLIC __declspec(dllexport)
#define EXPIMP_TEMPLATE
#ifdef ANTLR4CPP_EXPORTS
#define ANTLR4CPP_PUBLIC __declspec(dllexport)
#else
#ifdef ANTLR4CPP_STATIC
#define ANTLR4CPP_PUBLIC
#else
#define ANTLR4CPP_PUBLIC __declspec(dllimport)
#define EXPIMP_TEMPLATE extern
#endif
#else
#define ANTLR4CPP_PUBLIC
#define EXPIMP_TEMPLATE
#endif
EXPIMP_TEMPLATE class ANTLR4CPP_PUBLIC std::exception; // Needed for VS 2015.
class ANTLR4CPP_PUBLIC std::exception; // Needed for VS 2015.
#elif __APPLE__
#define GUID_CFUUID

View File

@ -16,6 +16,8 @@ using namespace antlr4::dfa;
using namespace antlr4::atn;
const Ref<DFAState> ATNSimulator::ERROR = std::make_shared<DFAState>(INT32_MAX);
antlrcpp::SingleWriteMultipleReadLock ATNSimulator::_stateLock;
antlrcpp::SingleWriteMultipleReadLock ATNSimulator::_edgeLock;
ATNSimulator::ATNSimulator(const ATN &atn, PredictionContextCache &sharedContextCache)
: atn(atn), _sharedContextCache(sharedContextCache) {
@ -30,7 +32,8 @@ PredictionContextCache& ATNSimulator::getSharedContextCache() {
}
Ref<PredictionContext> ATNSimulator::getCachedContext(Ref<PredictionContext> const& context) {
std::lock_guard<std::recursive_mutex> lck(_mutex);
// This function requires a lock as it might modify the cache, however the only path so far where it is called from
// (addDFAState -> optimizeConfigs) already has _stateLock aquired. Adding another lock here would then deadlock.
std::map<Ref<PredictionContext>, Ref<PredictionContext>> visited;
return PredictionContext::getCachedContext(context, _sharedContextCache, visited);
}

View File

@ -7,6 +7,7 @@
#include "atn/ATN.h"
#include "misc/IntervalSet.h"
#include "support/CPPUtils.h"
#include "atn/PredictionContext.h"
namespace antlr4 {
@ -55,8 +56,8 @@ namespace atn {
static ATNState *stateFactory(int type, int ruleIndex);
protected:
// Mutex to manage synchronized access for multithreading.
std::recursive_mutex _mutex;
static antlrcpp::SingleWriteMultipleReadLock _stateLock; // Lock for DFA states.
static antlrcpp::SingleWriteMultipleReadLock _edgeLock; // Lock for the sparse edge map in DFA states.
/// <summary>
/// The context cache maps all PredictionContext objects that are equals()

View File

@ -183,14 +183,19 @@ dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, size_
return nullptr;
}
dfa::DFAState *target = s->edges[t - MIN_DFA_EDGE];
_edgeLock.readLock();
auto iterator = s->edges.find(t - MIN_DFA_EDGE);
#if DEBUG_ATN == 1
if (target != nullptr) {
std::cout << std::string("reuse state ") << s->stateNumber << std::string(" edge to ") << target->stateNumber << std::endl;
if (iterator != s->edges.end()) {
std::cout << std::string("reuse state ") << s->stateNumber << std::string(" edge to ") << iterator->second->stateNumber << std::endl;
}
#endif
_edgeLock.readUnlock();
return target;
if (iterator == s->edges.end())
return nullptr;
return iterator->second;
}
dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFAState *s, size_t t) {
@ -525,8 +530,9 @@ void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, size_t t, dfa::DFAState *q)
return;
}
std::lock_guard<std::recursive_mutex> lck(_mutex);
_edgeLock.writeLock();
p->edges[t - MIN_DFA_EDGE] = q; // connect
_edgeLock.writeUnlock();
}
dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
@ -552,22 +558,23 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
dfa::DFA &dfa = _decisionToDFA[_mode];
{
std::lock_guard<std::recursive_mutex> lck(_mutex);
if (!dfa.states.empty()) {
auto iterator = dfa.states.find(proposed);
if (iterator != dfa.states.end()) {
delete proposed;
return *iterator;
}
_stateLock.writeLock();
if (!dfa.states.empty()) {
auto iterator = dfa.states.find(proposed);
if (iterator != dfa.states.end()) {
delete proposed;
_stateLock.writeUnlock();
return *iterator;
}
proposed->stateNumber = (int)dfa.states.size();
proposed->configs->setReadonly(true);
dfa.states.insert(proposed);
return proposed;
}
proposed->stateNumber = (int)dfa.states.size();
proposed->configs->setReadonly(true);
dfa.states.insert(proposed);
_stateLock.writeUnlock();
return proposed;
}
dfa::DFA& LexerATNSimulator::getDFA(size_t mode) {

View File

@ -111,7 +111,7 @@ size_t ParserATNSimulator::adaptivePredict(TokenStream *input, size_t decision,
dfa.s0->configs = std::move(s0_closure); // not used for prediction but useful to know start configs anyway
dfa::DFAState *newState = new dfa::DFAState(applyPrecedenceFilter(dfa.s0->configs.get())); /* mem-check: managed by the DFA or deleted below */
s0 = addDFAState(dfa, newState);
dfa.setPrecedenceStartState(parser->getPrecedence(), s0, _mutex);
dfa.setPrecedenceStartState(parser->getPrecedence(), s0, _edgeLock);
if (s0 != newState) {
delete newState; // If there was already a state with this config set we don't need the new one.
}
@ -246,7 +246,9 @@ size_t ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream
}
dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previousD, size_t t) {
_edgeLock.readLock();
auto iterator = previousD->edges.find(t);
_edgeLock.readUnlock();
if (iterator == previousD->edges.end()) {
return nullptr;
}
@ -1156,8 +1158,9 @@ dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA &dfa, dfa::DFAState *from
}
{
std::lock_guard<std::recursive_mutex> lck(_mutex);
_edgeLock.writeLock();
from->edges[t] = to; // connect
_edgeLock.writeUnlock();
}
#if DEBUG_DFA == 1
@ -1178,26 +1181,28 @@ dfa::DFAState *ParserATNSimulator::addDFAState(dfa::DFA &dfa, dfa::DFAState *D)
return D;
}
{
std::lock_guard<std::recursive_mutex> lck(_mutex);
_stateLock.writeLock();
auto existing = dfa.states.find(D);
if (existing != dfa.states.end()) {
return *existing;
}
auto existing = dfa.states.find(D);
if (existing != dfa.states.end()) {
_stateLock.writeUnlock();
return *existing;
}
D->stateNumber = (int)dfa.states.size();
if (!D->configs->isReadonly()) {
D->configs->optimizeConfigs(this);
D->configs->setReadonly(true);
}
dfa.states.insert(D);
_stateLock.writeUnlock();
D->stateNumber = (int)dfa.states.size();
if (!D->configs->isReadonly()) {
D->configs->optimizeConfigs(this);
D->configs->setReadonly(true);
}
dfa.states.insert(D);
#if DEBUG_DFA == 1
std::cout << "adding new DFA state: " << D << std::endl;
std::cout << "adding new DFA state: " << D << std::endl;
#endif
return D;
}
return D;
}
void ParserATNSimulator::reportAttemptingFullContext(dfa::DFA &dfa, const antlrcpp::BitSet &conflictingAlts,

View File

@ -315,7 +315,7 @@ bool SemanticContext::operator != (const SemanticContext &other) const {
return !(*this == other);
}
Ref<SemanticContext> SemanticContext::evalPrecedence(Recognizer * /*parser*/, RuleContext */*parserCallStack*/) {
Ref<SemanticContext> SemanticContext::evalPrecedence(Recognizer * /*parser*/, RuleContext * /*parserCallStack*/) {
return shared_from_this();
}

View File

@ -71,7 +71,7 @@ DFAState* DFA::getPrecedenceStartState(int precedence) const {
return iterator->second;
}
void DFA::setPrecedenceStartState(int precedence, DFAState *startState, std::recursive_mutex &mutex) {
void DFA::setPrecedenceStartState(int precedence, DFAState *startState, SingleWriteMultipleReadLock &lock) {
if (!isPrecedenceDfa()) {
throw IllegalStateException("Only precedence DFAs may contain a precedence start state.");
}
@ -81,8 +81,9 @@ void DFA::setPrecedenceStartState(int precedence, DFAState *startState, std::rec
}
{
std::unique_lock<std::recursive_mutex> lock(mutex);
lock.writeLock();
s0->edges[precedence] = startState;
lock.writeUnlock();
}
}

View File

@ -7,6 +7,10 @@
#include "dfa/DFAState.h"
namespace antlrcpp {
class SingleWriteMultipleReadLock;
}
namespace antlr4 {
namespace dfa {
@ -62,7 +66,7 @@ namespace dfa {
* @throws IllegalStateException if this is not a precedence DFA.
* @see #isPrecedenceDfa()
*/
void setPrecedenceStartState(int precedence, DFAState *startState, std::recursive_mutex &mutex);
void setPrecedenceStartState(int precedence, DFAState *startState, antlrcpp::SingleWriteMultipleReadLock &lock);
/// Return a list of all states in this DFA, ordered by state number.
virtual std::vector<DFAState *> getStates() const;

View File

@ -166,7 +166,7 @@ namespace antlrcpp {
std::string result;
std::size_t nestCount = 0;
next: {
next: {
try {
std::exception_ptr yeptr;
std::swap(eptr, yeptr);
@ -192,12 +192,52 @@ namespace antlrcpp {
goto next;
}
}
result += std::string(nestCount, ')');
return result;
}
//----------------- FinallyAction ------------------------------------------------------------------------------------
FinalAction finally(std::function<void ()> f) {
return FinalAction(f);
}
//----------------- SingleWriteMultipleRead --------------------------------------------------------------------------
void SingleWriteMultipleReadLock::readLock() {
std::unique_lock<std::mutex> lock(_mutex);
while (_waitingWriters != 0)
_readerGate.wait(lock);
++_activeReaders;
lock.unlock();
}
void SingleWriteMultipleReadLock::readUnlock() {
std::unique_lock<std::mutex> lock(_mutex);
--_activeReaders;
lock.unlock();
_writerGate.notify_one();
}
void SingleWriteMultipleReadLock::writeLock() {
std::unique_lock<std::mutex> lock(_mutex);
++_waitingWriters;
while (_activeReaders != 0 || _activeWriters != 0)
_writerGate.wait(lock);
++_activeWriters;
lock.unlock();
}
void SingleWriteMultipleReadLock::writeUnlock() {
std::unique_lock<std::mutex> lock(_mutex);
--_waitingWriters;
--_activeWriters;
if (_waitingWriters > 0)
_writerGate.notify_one();
else
_readerGate.notify_all();
lock.unlock();
}
} // namespace antlrcpp

View File

@ -59,4 +59,21 @@ namespace antlrcpp {
// Get the error text from an exception pointer or the current exception.
std::string what(std::exception_ptr eptr = std::current_exception());
class SingleWriteMultipleReadLock {
public:
void readLock();
void readUnlock();
void writeLock();
void writeUnlock();
private:
std::condition_variable _readerGate;
std::condition_variable _writerGate;
std::mutex _mutex;
size_t _activeReaders = 0;
size_t _waitingWriters = 0;
size_t _activeWriters = 0;
};
} // namespace antlrcpp

View File

@ -19,14 +19,16 @@ void replaceAll(std::string& str, const std::string& from, const std::string& to
}
}
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string ws2s(const std::wstring &wstr) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string narrow = converter.to_bytes(wstr);
return narrow;
}
std::wstring s2ws(const std::string &str) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wide = converter.from_bytes(str);
return wide;
}

View File

@ -0,0 +1,96 @@
/*
* [The "BSD license"]
* Copyright (c) 2012 Terence Parr
* Copyright (c) 2012 Sam Harwell
* 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.
*/
#include "support/CPPUtils.h"
#include "tree/ParseTreeListener.h"
#include "tree/ParseTree.h"
#include "tree/ErrorNode.h"
#include "IterativeParseTreeWalker.h"
using namespace antlr4::tree;
void IterativeParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const {
std::vector<ParseTree *> nodeStack;
std::vector<size_t> indexStack;
ParseTree *currentNode = t;
size_t currentIndex = 0;
while (currentNode != nullptr) {
// pre-order visit
if (antlrcpp::is<ErrorNode *>(currentNode)) {
listener->visitErrorNode(dynamic_cast<ErrorNode *>(currentNode));
} else if (antlrcpp::is<TerminalNode *>(currentNode)) {
listener->visitTerminal((TerminalNode *)currentNode);
} else {
enterRule(listener, currentNode);
}
// Move down to first child, if it exists.
if (!currentNode->children.empty()) {
nodeStack.push_back(currentNode);
indexStack.push_back(currentIndex);
currentIndex = 0;
currentNode = currentNode->children[0];
continue;
}
// No child nodes, so walk tree.
do {
// post-order visit
if (!antlrcpp::is<TerminalNode *>(currentNode)) {
exitRule(listener, currentNode);
}
// No parent, so no siblings.
if (nodeStack.empty()) {
currentNode = nullptr;
currentIndex = 0;
break;
}
// Move to next sibling if possible.
if (nodeStack.back()->children.size() > ++currentIndex) {
currentNode = nodeStack.back()->children[currentIndex];
break;
}
// No next sibling, so move up.
currentNode = nodeStack.back();
nodeStack.pop_back();
currentIndex = indexStack.back();
indexStack.pop_back();
} while (currentNode != nullptr);
}
}

View File

@ -0,0 +1,53 @@
/*
* [The "BSD license"]
* Copyright (c) 2012 Terence Parr
* Copyright (c) 2012 Sam Harwell
* 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.
*/
#pragma once
#include "antlr4-common.h"
#include "tree/ParseTreeWalker.h"
namespace antlr4 {
namespace tree {
class ParseTreeListener;
/**
* An iterative (read: non-recursive) pre-order and post-order tree walker that
* doesn't use the thread stack but heap-based stacks. Makes it possible to
* process deeply nested parse trees.
*/
class ANTLR4CPP_PUBLIC IterativeParseTreeWalker : public ParseTreeWalker {
public:
virtual void walk(ParseTreeListener *listener, ParseTree *t) const override;
};
} // namespace tree
} // namespace antlr4

View File

@ -5,6 +5,8 @@
#pragma once
#include "antlr4-common.h"
namespace antlr4 {
namespace tree {

View File

@ -8,12 +8,13 @@
#include "tree/ParseTreeListener.h"
#include "support/CPPUtils.h"
#include "tree/IterativeParseTreeWalker.h"
#include "tree/ParseTreeWalker.h"
using namespace antlr4::tree;
using namespace antlrcpp;
ParseTreeWalker ParseTreeWalker::DEFAULT;
ParseTreeWalker ParseTreeWalker::DEFAULT = IterativeParseTreeWalker();
void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const {
if (is<ErrorNode *>(t)) {
@ -26,7 +27,7 @@ void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const {
enterRule(listener, t);
for (auto &child : t->children) {
walk(listener, dynamic_cast<ParseTree *>(child));
walk(listener, child);
}
exitRule(listener, t);
}

View File

@ -5,6 +5,8 @@
#pragma once
#include "antlr4-common.h"
namespace antlr4 {
namespace tree {