-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
258 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* This file is part of the Practical programming langauge. https://github.com/Practical/practical-sa | ||
* | ||
* To the extent header files enjoy copyright protection, this file is file is copyright (C) 2020 by its authors | ||
* You can see the file's authors in the AUTHORS file in the project's home repository. | ||
* | ||
* This is available under the Boost license. The license's text is available under the LICENSE file in the project's | ||
* home directory. | ||
*/ | ||
#include "ast/expression/dereference.h" | ||
|
||
#include "ast/pointers.h" | ||
#include "asserts.h" | ||
|
||
#include <practical/errors.h> | ||
|
||
namespace AST::ExpressionImpl { | ||
|
||
Dereference::Dereference( const NonTerminals::Expression &parserOperand ) : | ||
operand( parserOperand ) | ||
{} | ||
|
||
void Dereference::buildASTImpl( | ||
LookupContext &lookupContext, ExpectedResult expectedResult, ExpressionMetadata &metadata, | ||
Weight &weight, Weight weightLimit | ||
) | ||
{ | ||
ExpectedResult expectedOperandResult; | ||
|
||
if( expectedResult ) { | ||
StaticTypeImpl::CPtr operandExpectedType = | ||
StaticTypeImpl::allocate( PointerTypeImpl( expectedResult.getType() ) ); | ||
|
||
expectedOperandResult = ExpectedResult( std::move(operandExpectedType), expectedResult.isMandatory() ); | ||
} | ||
|
||
operand.buildAST( lookupContext, expectedOperandResult, weight, weightLimit ); | ||
|
||
StaticType::Types resultTypeType = operand.getType()->getType(); | ||
auto resultPointerParent = std::get_if<const StaticType::Pointer *>( &resultTypeType ); | ||
if( !resultPointerParent ) | ||
throw PointerExpected(operand.getType(), operand.getLocation()); | ||
|
||
const PointerTypeImpl *resultPointer = downCast(*resultPointerParent); | ||
ASSERT( resultPointer ); | ||
|
||
metadata.type = downCast( resultPointer->getPointedType()->setFlags( StaticType::Flags::Reference ) ); | ||
|
||
auto operandRange = operand.getValueRange()->downCast< PointerValueRange >(); | ||
if( operandRange->initialized.trueAllowed == false ) { | ||
throw KnownRuntimeViolation( "Dereferencing a pointer known to be null", operand.getLocation() ); | ||
} | ||
metadata.valueRange = operandRange->pointedValueRange; | ||
} | ||
|
||
ExpressionId Dereference::codeGen( PracticalSemanticAnalyzer::FunctionGen *functionGen ) const { | ||
return operand.codeGen( functionGen ); | ||
} | ||
|
||
} // namespace AST::ExpressionImpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* This file is part of the Practical programming langauge. https://github.com/Practical/practical-sa | ||
* | ||
* To the extent header files enjoy copyright protection, this file is file is copyright (C) 2020 by its authors | ||
* You can see the file's authors in the AUTHORS file in the project's home repository. | ||
* | ||
* This is available under the Boost license. The license's text is available under the LICENSE file in the project's | ||
* home directory. | ||
*/ | ||
#ifndef AST_EXPRESSION_DEREFERENCE_H | ||
#define AST_EXPRESSION_DEREFERENCE_H | ||
|
||
#include "ast/expression.h" | ||
|
||
namespace AST::ExpressionImpl { | ||
|
||
class Dereference { | ||
Expression operand; | ||
|
||
public: | ||
explicit Dereference( const NonTerminals::Expression &parserOperand ); | ||
|
||
void buildASTImpl( | ||
LookupContext &lookupContext, ExpectedResult expectedResult, ExpressionMetadata &metadata, | ||
Weight &weight, Weight weightLimit | ||
); | ||
ExpressionId codeGen( PracticalSemanticAnalyzer::FunctionGen *functionGen ) const; | ||
}; | ||
|
||
} // namespace AST::ExpressionImpl | ||
|
||
#endif // AST_EXPRESSION_DEREFERENCE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.