Fixed endian specifier not applying
This commit is contained in:
parent
750f7463cc
commit
205f3a327e
@ -461,6 +461,8 @@ namespace hex::lang {
|
|||||||
if (!node->getName().empty())
|
if (!node->getName().empty())
|
||||||
pattern->setTypeName(node->getName().data());
|
pattern->setTypeName(node->getName().data());
|
||||||
|
|
||||||
|
pattern->setEndian(this->getCurrentEndian());
|
||||||
|
|
||||||
this->m_endianStack.pop_back();
|
this->m_endianStack.pop_back();
|
||||||
|
|
||||||
return pattern;
|
return pattern;
|
||||||
@ -490,7 +492,6 @@ namespace hex::lang {
|
|||||||
throwEvaluateError("ASTNodeVariableDecl had an invalid type. This is a bug!", 1);
|
throwEvaluateError("ASTNodeVariableDecl had an invalid type. This is a bug!", 1);
|
||||||
|
|
||||||
pattern->setVariableName(node->getName().data());
|
pattern->setVariableName(node->getName().data());
|
||||||
pattern->setEndian(this->getCurrentEndian());
|
|
||||||
|
|
||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
@ -605,18 +606,24 @@ namespace hex::lang {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PatternData *sizeType;
|
PatternData *sizeType;
|
||||||
if (auto builtinTypeNode = dynamic_cast<ASTNodeBuiltinType*>(node->getSizeType()); builtinTypeNode != nullptr) {
|
|
||||||
|
auto underlyingType = dynamic_cast<ASTNodeTypeDecl*>(node->getSizeType());
|
||||||
|
if (underlyingType == nullptr)
|
||||||
|
throwEvaluateError("underlying type is not ASTNodeTypeDecl. This is a bug", node->getLineNumber());
|
||||||
|
|
||||||
|
if (auto builtinTypeNode = dynamic_cast<ASTNodeBuiltinType*>(underlyingType->getType()); builtinTypeNode != nullptr) {
|
||||||
sizeType = evaluateBuiltinType(builtinTypeNode);
|
sizeType = evaluateBuiltinType(builtinTypeNode);
|
||||||
} else
|
} else
|
||||||
throwEvaluateError("Pointer size is not a builtin type", node->getLineNumber());
|
throwEvaluateError("pointer size is not a builtin type", node->getLineNumber());
|
||||||
|
|
||||||
size_t pointerSize = sizeType->getSize();
|
size_t pointerSize = sizeType->getSize();
|
||||||
delete sizeType;
|
|
||||||
|
|
||||||
u128 pointedAtOffset = 0;
|
u128 pointedAtOffset = 0;
|
||||||
this->m_provider->read(pointerOffset, &pointedAtOffset, pointerSize);
|
this->m_provider->read(pointerOffset, &pointedAtOffset, pointerSize);
|
||||||
|
this->m_currOffset = hex::changeEndianess(pointedAtOffset, pointerSize, underlyingType->getEndian().value_or(this->m_defaultDataEndian));
|
||||||
|
|
||||||
|
delete sizeType;
|
||||||
|
|
||||||
this->m_currOffset = hex::changeEndianess(pointedAtOffset, 1, this->getCurrentEndian());
|
|
||||||
|
|
||||||
if (this->m_currOffset > this->m_provider->getActualSize())
|
if (this->m_currOffset > this->m_provider->getActualSize())
|
||||||
throwEvaluateError("pointer points past the end of the data", 1);
|
throwEvaluateError("pointer points past the end of the data", 1);
|
||||||
|
@ -315,14 +315,13 @@ namespace hex::lang {
|
|||||||
|
|
||||||
// using Identifier = (parseType)
|
// using Identifier = (parseType)
|
||||||
ASTNode* Parser::parseUsingDeclaration() {
|
ASTNode* Parser::parseUsingDeclaration() {
|
||||||
auto *temporaryType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-1));
|
auto *type = dynamic_cast<ASTNodeTypeDecl *>(parseType(-1));
|
||||||
if (temporaryType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
if (type == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryType; );
|
|
||||||
|
|
||||||
if (peekOptional(KEYWORD_BE) || peekOptional(KEYWORD_LE))
|
if (peekOptional(KEYWORD_BE) || peekOptional(KEYWORD_LE))
|
||||||
return new ASTNodeTypeDecl(getValue<std::string>(-4), temporaryType->getType()->clone(), temporaryType->getEndian());
|
return new ASTNodeTypeDecl(getValue<std::string>(-4), type, type->getEndian());
|
||||||
else
|
else
|
||||||
return new ASTNodeTypeDecl(getValue<std::string>(-3), temporaryType->getType()->clone(), temporaryType->getEndian());
|
return new ASTNodeTypeDecl(getValue<std::string>(-3), type, type->getEndian());
|
||||||
}
|
}
|
||||||
|
|
||||||
// padding[(parseMathematicalExpression)]
|
// padding[(parseMathematicalExpression)]
|
||||||
@ -339,18 +338,16 @@ namespace hex::lang {
|
|||||||
|
|
||||||
// (parseType) Identifier
|
// (parseType) Identifier
|
||||||
ASTNode* Parser::parseMemberVariable() {
|
ASTNode* Parser::parseMemberVariable() {
|
||||||
auto temporaryType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-2));
|
auto type = dynamic_cast<ASTNodeTypeDecl *>(parseType(-2));
|
||||||
if (temporaryType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
if (type == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryType; );
|
|
||||||
|
|
||||||
return new ASTNodeVariableDecl(getValue<std::string>(-1), temporaryType->getType()->clone());
|
return new ASTNodeVariableDecl(getValue<std::string>(-1), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (parseType) Identifier[(parseMathematicalExpression)]
|
// (parseType) Identifier[(parseMathematicalExpression)]
|
||||||
ASTNode* Parser::parseMemberArrayVariable() {
|
ASTNode* Parser::parseMemberArrayVariable() {
|
||||||
auto temporaryType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-3));
|
auto type = dynamic_cast<ASTNodeTypeDecl *>(parseType(-3));
|
||||||
if (temporaryType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
if (type == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryType; );
|
|
||||||
|
|
||||||
auto name = getValue<std::string>(-2);
|
auto name = getValue<std::string>(-2);
|
||||||
|
|
||||||
@ -366,25 +363,23 @@ namespace hex::lang {
|
|||||||
|
|
||||||
sizeCleanup.release();
|
sizeCleanup.release();
|
||||||
|
|
||||||
return new ASTNodeArrayVariableDecl(name, temporaryType->getType()->clone(), size);
|
return new ASTNodeArrayVariableDecl(name, type, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (parseType) *Identifier : (parseType)
|
// (parseType) *Identifier : (parseType)
|
||||||
ASTNode* Parser::parseMemberPointerVariable() {
|
ASTNode* Parser::parseMemberPointerVariable() {
|
||||||
auto name = getValue<std::string>(-2);
|
auto name = getValue<std::string>(-2);
|
||||||
|
|
||||||
auto temporaryPointerType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-4));
|
auto pointerType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-4));
|
||||||
if (temporaryPointerType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
if (pointerType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryPointerType; );
|
|
||||||
|
|
||||||
if (!MATCHES((optional(KEYWORD_BE), optional(KEYWORD_LE)) && sequence(VALUETYPE_UNSIGNED)))
|
if (!MATCHES((optional(KEYWORD_BE), optional(KEYWORD_LE)) && sequence(VALUETYPE_UNSIGNED)))
|
||||||
throwParseError("expected unsigned builtin type as size", -1);
|
throwParseError("expected unsigned builtin type as size", -1);
|
||||||
|
|
||||||
auto temporarySizeType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-1));
|
auto sizeType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-1));
|
||||||
if (temporarySizeType == nullptr) throwParseError("invalid type used for pointer size", -1);
|
if (sizeType == nullptr) throwParseError("invalid type used for pointer size", -1);
|
||||||
SCOPE_EXIT( delete temporarySizeType; );
|
|
||||||
|
|
||||||
return new ASTNodePointerVariableDecl(name, temporaryPointerType->getType()->clone(), temporarySizeType->getType()->clone());
|
return new ASTNodePointerVariableDecl(name, pointerType, sizeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [(parsePadding)|(parseMemberVariable)|(parseMemberArrayVariable)|(parseMemberPointerVariable)]
|
// [(parsePadding)|(parseMemberVariable)|(parseMemberArrayVariable)|(parseMemberPointerVariable)]
|
||||||
@ -450,10 +445,8 @@ namespace hex::lang {
|
|||||||
else
|
else
|
||||||
typeName = getValue<std::string>(-4);
|
typeName = getValue<std::string>(-4);
|
||||||
|
|
||||||
auto temporaryTypeDecl = dynamic_cast<ASTNodeTypeDecl*>(parseType(-2));
|
auto underlyingType = dynamic_cast<ASTNodeTypeDecl*>(parseType(-2));
|
||||||
if (temporaryTypeDecl == nullptr) throwParseError("failed to parse type", -2);
|
if (underlyingType == nullptr) throwParseError("failed to parse type", -2);
|
||||||
auto underlyingType = dynamic_cast<ASTNodeBuiltinType*>(temporaryTypeDecl->getType());
|
|
||||||
if (underlyingType == nullptr) throwParseError("underlying type is not a built-in type", -2);
|
|
||||||
|
|
||||||
const auto enumNode = new ASTNodeEnum(underlyingType);
|
const auto enumNode = new ASTNodeEnum(underlyingType);
|
||||||
ScopeExit enumGuard([&]{ delete enumNode; });
|
ScopeExit enumGuard([&]{ delete enumNode; });
|
||||||
@ -524,18 +517,16 @@ namespace hex::lang {
|
|||||||
|
|
||||||
// (parseType) Identifier @ Integer
|
// (parseType) Identifier @ Integer
|
||||||
ASTNode* Parser::parseVariablePlacement() {
|
ASTNode* Parser::parseVariablePlacement() {
|
||||||
auto temporaryType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-3));
|
auto type = dynamic_cast<ASTNodeTypeDecl *>(parseType(-3));
|
||||||
if (temporaryType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
if (type == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryType; );
|
|
||||||
|
|
||||||
return new ASTNodeVariableDecl(getValue<std::string>(-2), temporaryType->getType()->clone(), parseMathematicalExpression());
|
return new ASTNodeVariableDecl(getValue<std::string>(-2), type, parseMathematicalExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
// (parseType) Identifier[[(parseMathematicalExpression)]] @ Integer
|
// (parseType) Identifier[[(parseMathematicalExpression)]] @ Integer
|
||||||
ASTNode* Parser::parseArrayVariablePlacement() {
|
ASTNode* Parser::parseArrayVariablePlacement() {
|
||||||
auto temporaryType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-3));
|
auto type = dynamic_cast<ASTNodeTypeDecl *>(parseType(-3));
|
||||||
if (temporaryType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
if (type == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryType; );
|
|
||||||
|
|
||||||
auto name = getValue<std::string>(-2);
|
auto name = getValue<std::string>(-2);
|
||||||
|
|
||||||
@ -554,7 +545,7 @@ namespace hex::lang {
|
|||||||
|
|
||||||
sizeCleanup.release();
|
sizeCleanup.release();
|
||||||
|
|
||||||
return new ASTNodeArrayVariableDecl(name, temporaryType->getType()->clone(), size, parseMathematicalExpression());
|
return new ASTNodeArrayVariableDecl(name, type, size, parseMathematicalExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
// (parseType) *Identifier : (parseType) @ Integer
|
// (parseType) *Identifier : (parseType) @ Integer
|
||||||
@ -563,19 +554,17 @@ namespace hex::lang {
|
|||||||
|
|
||||||
auto temporaryPointerType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-4));
|
auto temporaryPointerType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-4));
|
||||||
if (temporaryPointerType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
if (temporaryPointerType == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryPointerType; );
|
|
||||||
|
|
||||||
if (!MATCHES((optional(KEYWORD_BE), optional(KEYWORD_LE)) && sequence(VALUETYPE_UNSIGNED)))
|
if (!MATCHES((optional(KEYWORD_BE), optional(KEYWORD_LE)) && sequence(VALUETYPE_UNSIGNED)))
|
||||||
throwParseError("expected unsigned builtin type as size", -1);
|
throwParseError("expected unsigned builtin type as size", -1);
|
||||||
|
|
||||||
auto temporaryPointerSizeType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-1));
|
auto temporaryPointerSizeType = dynamic_cast<ASTNodeTypeDecl *>(parseType(-1));
|
||||||
if (temporaryPointerSizeType == nullptr) throwParseError("invalid size type used in pointer declaration", -1);
|
if (temporaryPointerSizeType == nullptr) throwParseError("invalid size type used in pointer declaration", -1);
|
||||||
SCOPE_EXIT( delete temporaryPointerSizeType; );
|
|
||||||
|
|
||||||
if (!MATCHES(sequence(OPERATOR_AT)))
|
if (!MATCHES(sequence(OPERATOR_AT)))
|
||||||
throwParseError("expected placement instruction", -1);
|
throwParseError("expected placement instruction", -1);
|
||||||
|
|
||||||
return new ASTNodePointerVariableDecl(name, temporaryPointerType->getType()->clone(), temporaryPointerSizeType->getType()->clone(), parseMathematicalExpression());
|
return new ASTNodePointerVariableDecl(name, temporaryPointerType, temporaryPointerSizeType, parseMathematicalExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user