-
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
11 changed files
with
184 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "constant_node.h" | ||
|
||
#include <Parser/lex_token.h> | ||
#include "parser.tab.h" | ||
|
||
ConstantNode::ConstantNode( int code, int line, QString value, int type_code, int base ) : | ||
Node( code, line, value ), | ||
_typeCode( type_code ), | ||
_base( base ) | ||
{ | ||
if ( type_code < 0 ) | ||
{ | ||
if ( value.contains('.')) | ||
_typeCode = F64; | ||
else | ||
_typeCode = I32; | ||
} | ||
} | ||
|
||
int ConstantNode::typeCode() | ||
{ | ||
return _typeCode; | ||
} | ||
|
||
int ConstantNode::base() | ||
{ | ||
return _base; | ||
} |
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,20 @@ | ||
#ifndef CONSTANTNODE_H | ||
#define CONSTANTNODE_H | ||
|
||
#include "node.h" | ||
|
||
class ConstantNode : public Node | ||
{ | ||
private: | ||
int _typeCode = -1; | ||
int _base = 10; | ||
|
||
public: | ||
ConstantNode( int code, int line, QString value, int type_code = -1, int base = 10 ); | ||
|
||
int typeCode(); | ||
|
||
int base(); | ||
}; | ||
|
||
#endif // CONSTANTNODE_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "expression_node.h" | ||
|
||
#include "constant_node.h" | ||
|
||
#include <Parser/lex_token.h> | ||
#include "parser.tab.h" | ||
|
||
ExpressionNode::ExpressionNode( int code, int line, QString label ) : | ||
Node( code, line, label ), | ||
_typeName("Unknown") | ||
{ | ||
} | ||
|
||
QString ExpressionNode::getTypeName( Context* context ) | ||
{ | ||
if ( !_calculated && Children.count() > 0 ) | ||
calculateType( context, Children.last() ); | ||
_calculated = true; | ||
|
||
return _typeName; | ||
} | ||
|
||
int ExpressionNode::getTypeCode( Context* context ) | ||
{ | ||
if ( !_calculated ) | ||
calculateType( context, Children.last() ); | ||
_calculated = true; | ||
|
||
return _typeCode; | ||
} | ||
|
||
void ExpressionNode::calculateType( Context* context, Node* node ) | ||
{ | ||
if ( node->tokenType() == IDENT) | ||
{ | ||
} | ||
else | ||
{ | ||
auto cn = dynamic_cast<ConstantNode*>(node); | ||
_typeCode = cn->typeCode(); | ||
switch ( _typeCode ) | ||
{ | ||
case I8: _typeName = "char"; break; | ||
case I16: _typeName = "short"; break; | ||
case I32: _typeName = "int"; break; | ||
case I64: _typeName = "long"; break; | ||
case I128: _typeName = "long long"; break; | ||
|
||
case U8: _typeName = "unsigned char"; break; | ||
case U16: _typeName = "unsigned short"; break; | ||
case U32: _typeName = "unsigned int"; break; | ||
case U64: _typeName = "unsigned long"; break; | ||
case U128: _typeName = "unsigned long long"; break; | ||
|
||
case F32: _typeName = "float"; break; | ||
case F64: _typeName = "double"; break; | ||
|
||
case BOOL: _typeName = "bool"; break; | ||
case STR: _typeName = "QString"; break; | ||
|
||
default: | ||
_typeName = "Error"; | ||
break; | ||
} | ||
} | ||
} |
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,25 @@ | ||
#ifndef EXPRESSIONNODE_H | ||
#define EXPRESSIONNODE_H | ||
|
||
#include "node.h" | ||
|
||
#include <QString> | ||
|
||
class ExpressionNode : public Node | ||
{ | ||
private: | ||
bool _calculated = false; | ||
int _typeCode = -1; | ||
QString _typeName; | ||
|
||
public: | ||
ExpressionNode( int code, int line, QString label ); | ||
|
||
QString getTypeName( Context* context ); | ||
|
||
int getTypeCode( Context* context ); | ||
|
||
void calculateType( Context* context, Node* node ); | ||
}; | ||
|
||
#endif // EXPRESSIONNODE_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