forked from qt-creator/qt-creator
Evaluate the expression's attributes.
This commit is contained in:
@@ -38,8 +38,8 @@ using namespace GLSL;
|
|||||||
|
|
||||||
Semantic::Semantic(Engine *engine)
|
Semantic::Semantic(Engine *engine)
|
||||||
: _engine(engine)
|
: _engine(engine)
|
||||||
, _type(0)
|
|
||||||
, _scope(0)
|
, _scope(0)
|
||||||
|
, _type(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +54,13 @@ Scope *Semantic::switchScope(Scope *scope)
|
|||||||
return previousScope;
|
return previousScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::expression(ExpressionAST *ast)
|
Semantic::ExprResult Semantic::expression(ExpressionAST *ast)
|
||||||
{
|
{
|
||||||
|
Semantic::ExprResult r(_engine->undefinedType());
|
||||||
|
std::swap(_expr, r);
|
||||||
accept(ast);
|
accept(ast);
|
||||||
|
std::swap(_expr, r);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::statement(StatementAST *ast)
|
void Semantic::statement(StatementAST *ast)
|
||||||
@@ -152,46 +156,45 @@ bool Semantic::visit(LiteralExpressionAST *ast)
|
|||||||
|
|
||||||
bool Semantic::visit(BinaryExpressionAST *ast)
|
bool Semantic::visit(BinaryExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->left);
|
ExprResult left = expression(ast->left);
|
||||||
expression(ast->right);
|
ExprResult right = expression(ast->right);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(UnaryExpressionAST *ast)
|
bool Semantic::visit(UnaryExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
ExprResult expr = expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(TernaryExpressionAST *ast)
|
bool Semantic::visit(TernaryExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->first);
|
ExprResult first = expression(ast->first);
|
||||||
expression(ast->second);
|
ExprResult second = expression(ast->second);
|
||||||
expression(ast->third);
|
ExprResult third = expression(ast->third);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(AssignmentExpressionAST *ast)
|
bool Semantic::visit(AssignmentExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->variable);
|
ExprResult variable = expression(ast->variable);
|
||||||
expression(ast->value);
|
ExprResult value = expression(ast->value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(MemberAccessExpressionAST *ast)
|
bool Semantic::visit(MemberAccessExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
ExprResult expr = expression(ast->expr);
|
||||||
// ast->field
|
// ast->field
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(FunctionCallExpressionAST *ast)
|
bool Semantic::visit(FunctionCallExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
ExprResult expr = expression(ast->expr);
|
||||||
functionIdentifier(ast->id);
|
functionIdentifier(ast->id);
|
||||||
for (List<ExpressionAST *> *it = ast->arguments; it; it = it->next) {
|
for (List<ExpressionAST *> *it = ast->arguments; it; it = it->next) {
|
||||||
ExpressionAST *arg = it->value;
|
ExprResult arg = expression(it->value);
|
||||||
expression(arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -202,7 +205,7 @@ bool Semantic::visit(DeclarationExpressionAST *ast)
|
|||||||
const Type *ty = type(ast->type);
|
const Type *ty = type(ast->type);
|
||||||
Q_UNUSED(ty);
|
Q_UNUSED(ty);
|
||||||
// ast->name
|
// ast->name
|
||||||
expression(ast->initializer);
|
ExprResult initializer = expression(ast->initializer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +213,7 @@ bool Semantic::visit(DeclarationExpressionAST *ast)
|
|||||||
// statements
|
// statements
|
||||||
bool Semantic::visit(ExpressionStatementAST *ast)
|
bool Semantic::visit(ExpressionStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
ExprResult expr = expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +230,7 @@ bool Semantic::visit(CompoundStatementAST *ast)
|
|||||||
|
|
||||||
bool Semantic::visit(IfStatementAST *ast)
|
bool Semantic::visit(IfStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->condition);
|
ExprResult condition = expression(ast->condition);
|
||||||
statement(ast->thenClause);
|
statement(ast->thenClause);
|
||||||
statement(ast->elseClause);
|
statement(ast->elseClause);
|
||||||
return false;
|
return false;
|
||||||
@@ -235,7 +238,7 @@ bool Semantic::visit(IfStatementAST *ast)
|
|||||||
|
|
||||||
bool Semantic::visit(WhileStatementAST *ast)
|
bool Semantic::visit(WhileStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->condition);
|
ExprResult condition = expression(ast->condition);
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -243,15 +246,15 @@ bool Semantic::visit(WhileStatementAST *ast)
|
|||||||
bool Semantic::visit(DoStatementAST *ast)
|
bool Semantic::visit(DoStatementAST *ast)
|
||||||
{
|
{
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
expression(ast->condition);
|
ExprResult condition = expression(ast->condition);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(ForStatementAST *ast)
|
bool Semantic::visit(ForStatementAST *ast)
|
||||||
{
|
{
|
||||||
statement(ast->init);
|
statement(ast->init);
|
||||||
expression(ast->condition);
|
ExprResult condition = expression(ast->condition);
|
||||||
expression(ast->increment);
|
ExprResult increment = expression(ast->increment);
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -264,20 +267,20 @@ bool Semantic::visit(JumpStatementAST *ast)
|
|||||||
|
|
||||||
bool Semantic::visit(ReturnStatementAST *ast)
|
bool Semantic::visit(ReturnStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
ExprResult expr = expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(SwitchStatementAST *ast)
|
bool Semantic::visit(SwitchStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
ExprResult expr = expression(ast->expr);
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(CaseLabelStatementAST *ast)
|
bool Semantic::visit(CaseLabelStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
ExprResult expr = expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +530,7 @@ bool Semantic::visit(ArrayTypeAST *ast)
|
|||||||
{
|
{
|
||||||
const Type *elementType = type(ast->elementType);
|
const Type *elementType = type(ast->elementType);
|
||||||
Q_UNUSED(elementType);
|
Q_UNUSED(elementType);
|
||||||
expression(ast->size);
|
ExprResult size = expression(ast->size);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,7 +581,7 @@ bool Semantic::visit(VariableDeclarationAST *ast)
|
|||||||
{
|
{
|
||||||
const Type *ty = type(ast->type);
|
const Type *ty = type(ast->type);
|
||||||
Q_UNUSED(ty);
|
Q_UNUSED(ty);
|
||||||
expression(ast->initializer);
|
ExprResult initializer = expression(ast->initializer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,18 @@ public:
|
|||||||
Semantic(Engine *engine);
|
Semantic(Engine *engine);
|
||||||
virtual ~Semantic();
|
virtual ~Semantic();
|
||||||
|
|
||||||
void expression(ExpressionAST *ast);
|
struct ExprResult {
|
||||||
|
ExprResult(const Type *type = 0, bool isConstant = false)
|
||||||
|
: type(type), isConstant(isConstant) {}
|
||||||
|
|
||||||
|
bool isValid() const { return type != 0; }
|
||||||
|
operator bool() const { return type != 0; }
|
||||||
|
|
||||||
|
const Type *type;
|
||||||
|
bool isConstant;
|
||||||
|
};
|
||||||
|
|
||||||
|
ExprResult expression(ExpressionAST *ast);
|
||||||
void statement(StatementAST *ast);
|
void statement(StatementAST *ast);
|
||||||
const Type *type(TypeAST *ast);
|
const Type *type(TypeAST *ast);
|
||||||
void declaration(DeclarationAST *ast);
|
void declaration(DeclarationAST *ast);
|
||||||
@@ -98,8 +109,9 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Engine *_engine;
|
Engine *_engine;
|
||||||
const Type *_type;
|
|
||||||
Scope *_scope;
|
Scope *_scope;
|
||||||
|
const Type *_type;
|
||||||
|
ExprResult _expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GLSL
|
} // namespace GLSL
|
||||||
|
|||||||
Reference in New Issue
Block a user