forked from jasder/antlr
Changed exception object back in error reporting + removed precompiled headers with cmake.
- Reverted the change from RecognitionException to exception_ptr (and removed the make_exception_ptr() call). This is not needed and only leads to object slicing. Instead we check directly the given exception object for the individual handling in reportError() and use std::current_exception() to get the exception pointer for our contexts. - Removed precompiled header stuff from cmake file for the same reasons as I did in the XCode project (Visual Studio still pending).
This commit is contained in:
parent
cc50675a66
commit
e2d545fb2e
|
@ -79,49 +79,6 @@ else ()
|
|||
endif ()
|
||||
|
||||
|
||||
#==== macro for pch creation
|
||||
# taken from: https://cmake.org/pipermail/cmake/2006-December/012323.html
|
||||
MACRO(ADD_PRECOMPILED_HEADER _targetName _input )
|
||||
GET_FILENAME_COMPONENT(_name ${_input} NAME)
|
||||
SET(_source "${_input}")
|
||||
SET(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch")
|
||||
MAKE_DIRECTORY(${_outdir})
|
||||
SET(_output "${_outdir}/${CMAKE_BUILD_TYPE}.c++")
|
||||
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
|
||||
SET(_compiler_FLAGS ${${_flags_var_name}})
|
||||
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
|
||||
FOREACH(item ${_directory_flags})
|
||||
LIST(APPEND _compiler_FLAGS "-I${item}")
|
||||
ENDFOREACH(item)
|
||||
|
||||
GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
|
||||
LIST(APPEND _compiler_FLAGS ${_directory_flags})
|
||||
|
||||
SEPARATE_ARGUMENTS(_compiler_FLAGS)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT ${_output}
|
||||
COMMAND ${CMAKE_CXX_COMPILER}
|
||||
${_compiler_FLAGS}
|
||||
-x c++-header
|
||||
-o ${_output} ${_source}
|
||||
DEPENDS ${_source} )
|
||||
ADD_CUSTOM_TARGET(${_targetName}_gch DEPENDS ${_output})
|
||||
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch)
|
||||
#SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include ${_name} -Winvalid-pch -H")
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${_name} -Winvalid-pch")
|
||||
GET_TARGET_PROPERTY(old_compile_flags ${_targetName} COMPILE_FLAGS)
|
||||
IF(old_compile_flags STREQUAL "old_compile_flags-NOTFOUND")
|
||||
SET(old_compile_flags "-include ${_name} -Winvalid-pch")
|
||||
ELSE()
|
||||
SET(old_compile_flags "${old_compile_flags} -include ${_name} -Winvalid-pch")
|
||||
ENDIF()
|
||||
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES
|
||||
COMPILE_FLAGS "${old_compile_flags}"
|
||||
)
|
||||
|
||||
ENDMACRO(ADD_PRECOMPILED_HEADER)
|
||||
#==== end of macro for pch creation
|
||||
|
||||
add_subdirectory(runtime)
|
||||
if (WITH_DEMO)
|
||||
add_subdirectory(demo)
|
||||
|
|
|
@ -54,9 +54,6 @@ set_target_properties(antlr4_static
|
|||
OUTPUT_NAME antlr4
|
||||
COMPILE_FLAGS "${disabled_compile_warnings}")
|
||||
|
||||
add_precompiled_header(antlr4_shared ${PROJECT_SOURCE_DIR}/runtime/src/antlrcpp-Prefix.h)
|
||||
add_precompiled_header(antlr4_static ${PROJECT_SOURCE_DIR}/runtime/src/antlrcpp-Prefix.h)
|
||||
|
||||
install(TARGETS antlr4_shared
|
||||
DESTINATION lib)
|
||||
install(TARGETS antlr4_static
|
||||
|
|
|
@ -1050,7 +1050,7 @@
|
|||
276E5CDF1CDB57AA003FF4B4 /* RecognitionException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecognitionException.h; sourceTree = "<group>"; };
|
||||
276E5CE01CDB57AA003FF4B4 /* Recognizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Recognizer.cpp; sourceTree = "<group>"; };
|
||||
276E5CE11CDB57AA003FF4B4 /* Recognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Recognizer.h; sourceTree = "<group>"; };
|
||||
276E5CE21CDB57AA003FF4B4 /* RuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuleContext.cpp; sourceTree = "<group>"; };
|
||||
276E5CE21CDB57AA003FF4B4 /* RuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuleContext.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||
276E5CE31CDB57AA003FF4B4 /* RuleContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuleContext.h; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
|
|
|
@ -143,7 +143,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
/// <param name="e"> the recognition exception to report </param>
|
||||
virtual void reportError(Parser *recognizer, std::exception_ptr e) = 0;
|
||||
virtual void reportError(Parser *recognizer, const RecognitionException &e) = 0;
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
|
|
|
@ -69,7 +69,7 @@ void DefaultErrorStrategy::reportMatch(Parser *recognizer) {
|
|||
endErrorCondition(recognizer);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::reportError(Parser *recognizer, std::exception_ptr e) {
|
||||
void DefaultErrorStrategy::reportError(Parser *recognizer, const RecognitionException &e) {
|
||||
// If we've already reported an error and have not matched a token
|
||||
// yet successfully, don't report any errors.
|
||||
if (inErrorRecoveryMode(recognizer)) {
|
||||
|
@ -77,16 +77,14 @@ void DefaultErrorStrategy::reportError(Parser *recognizer, std::exception_ptr e)
|
|||
}
|
||||
|
||||
beginErrorCondition(recognizer);
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (NoViableAltException &ne) {
|
||||
reportNoViableAlternative(recognizer, ne);
|
||||
} catch (InputMismatchException &ne) {
|
||||
reportInputMismatch(recognizer, ne);
|
||||
} catch (FailedPredicateException &ne) {
|
||||
reportFailedPredicate(recognizer, ne);
|
||||
} catch (RecognitionException &ne) {
|
||||
recognizer->notifyErrorListeners(ne.getOffendingToken(), ne.what(), e);
|
||||
if (is<NoViableAltException>(e)) {
|
||||
reportNoViableAlternative(recognizer, (const NoViableAltException &)e);
|
||||
} else if (is<InputMismatchException>(e)) {
|
||||
reportInputMismatch(recognizer, (const InputMismatchException &)e);
|
||||
} else if (is<FailedPredicateException>(e)) {
|
||||
reportFailedPredicate(recognizer, (const FailedPredicateException &)e);
|
||||
} else if (is<RecognitionException>(e)) {
|
||||
recognizer->notifyErrorListeners(e.getOffendingToken(), e.what(), std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,6 @@ namespace runtime {
|
|||
public:
|
||||
virtual void reportMatch(Parser *recognizer) override;
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
/// <p/>
|
||||
/// The default implementation returns immediately if the handler is already
|
||||
|
@ -126,8 +125,7 @@ namespace runtime {
|
|||
/// <li>All other types: calls <seealso cref="Parser#notifyErrorListeners"/> to report
|
||||
/// the exception</li>
|
||||
/// </ul>
|
||||
/// </summary>
|
||||
virtual void reportError(Parser *recognizer, std::exception_ptr e) override;
|
||||
virtual void reportError(Parser *recognizer, const RecognitionException &e) override;
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc}
|
||||
|
|
|
@ -149,9 +149,8 @@ Ref<ParserRuleContext> ParserInterpreter::parse(int startRuleIndex) {
|
|||
}
|
||||
catch (RecognitionException &e) {
|
||||
setState(_atn.ruleToStopState[p->ruleIndex]->stateNumber);
|
||||
std::exception_ptr ptr = std::make_exception_ptr(e);
|
||||
getContext()->exception = ptr;
|
||||
getErrorHandler()->reportError(this, ptr);
|
||||
getErrorHandler()->reportError(this, e);
|
||||
getContext()->exception = std::current_exception();
|
||||
recover(e);
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ std::string RuleContext::toString(Recognizer *recog) {
|
|||
|
||||
std::string RuleContext::toString(Recognizer *recog, Ref<RuleContext> stop) {
|
||||
if (recog == nullptr)
|
||||
return toString({}, stop);
|
||||
return toString(std::vector<std::string>(), stop); // Don't use an initializer {} here or we end up calling ourselve recursivly.
|
||||
return toString(recog->getRuleNames(), stop);
|
||||
}
|
||||
|
||||
|
|
|
@ -392,7 +392,6 @@ bool PredictionContext::combineCommonParents(std::vector<std::weak_ptr<Predictio
|
|||
|
||||
for (size_t p = 0; p < parents.size(); ++p) {
|
||||
Ref<PredictionContext> parent = parents[p].lock();
|
||||
// ml: it's assumed that the == operator of PredictionContext kicks in here.
|
||||
if (uniqueParents.find(parent) == uniqueParents.end()) { // don't replace
|
||||
uniqueParents.insert(parent);
|
||||
}
|
||||
|
|
|
@ -460,8 +460,8 @@ Ref\<<parser.name>::<currentRule.ctxType>\> <parser.name>::<currentRule.name>(<a
|
|||
<exceptions; separator="\n">
|
||||
<else>
|
||||
catch (RecognitionException &e) {
|
||||
_localctx->exception = std::make_exception_ptr(e);
|
||||
_errHandler->reportError(this, _localctx->exception);
|
||||
_errHandler->reportError(this, e);
|
||||
_localctx->exception = std::current_exception();
|
||||
_errHandler->recover(this, _localctx->exception);
|
||||
}
|
||||
<endif>
|
||||
|
@ -507,8 +507,8 @@ Ref\<<parser.name>::<currentRule.ctxType>\> <parser.name>::<currentRule.name>(in
|
|||
<namedActions.after>
|
||||
}
|
||||
catch (RecognitionException &e) {
|
||||
_localctx->exception = std::make_exception_ptr(e);
|
||||
_errHandler->reportError(this, _localctx->exceptione);
|
||||
_errHandler->reportError(this, e);
|
||||
_localctx->exception = std::current_exception();
|
||||
_errHandler->recover(this, _localctx->exception);
|
||||
}
|
||||
return _localctx;
|
||||
|
@ -756,7 +756,7 @@ testShiftInRange(shiftAmount) ::= <<
|
|||
// produces smaller bytecode only when bits.ttypes contains more than two items
|
||||
bitsetBitfieldComparison(s, bits) ::= <<
|
||||
(<testShiftInRange({<offsetShift(s.varName, bits.shift)>})> &&
|
||||
((1L \<\< <offsetShift(s.varName, bits.shift)>) & (<bits.ttypes: {ttype | (1L \<\< <offsetShift(ttype, bits.shift, true)>)}; separator = " | ">)) != 0)
|
||||
((1L \<\< <offsetShift(s.varName, bits.shift)>) & (<bits.ttypes: {ttype | (1L \<\< <offsetShift(ttype, bits.shift, true)>)}; separator = "\n | ">)) != 0)
|
||||
>>
|
||||
|
||||
isZero ::= [
|
||||
|
@ -770,7 +770,7 @@ offsetShift(shiftAmount, offset, prefix = false) ::= <%
|
|||
|
||||
// produces more efficient bytecode when bits.ttypes contains at most two items
|
||||
bitsetInlineComparison(s, bits) ::= <%
|
||||
<bits.ttypes: {ttype | <s.varName> == <parser.name>::<ttype>}; separator = " || ">
|
||||
<bits.ttypes: {ttype | <s.varName> == <parser.name>::<ttype>}; separator = "\n\n|| ">
|
||||
%>
|
||||
|
||||
cases(ttypes) ::= <<
|
||||
|
|
Loading…
Reference in New Issue