Distinguish between dereferencing pointers and references.

We now have separate Expr implementations for dereferencing pointers
and automatically dereferencing references.  This is in particular
necessary so that we can detect attempts to dereference references
with the '*' operator in programs and issue an error in that case.

Fixes issue #192.
This commit is contained in:
Matt Pharr
2012-03-22 06:48:02 -07:00
parent 10c5ba140c
commit 20044f5749
7 changed files with 173 additions and 75 deletions

40
expr.h
View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2010-2011, Intel Corporation
Copyright (c) 2010-2012, Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -530,26 +530,48 @@ public:
};
/** @brief Expression that represents dereferencing a reference to get its
value. */
class DereferenceExpr : public Expr {
/** @brief Common base class that provides shared functionality for
PtrDerefExpr and RefDerefExpr. */
class DerefExpr : public Expr {
public:
DereferenceExpr(Expr *e, SourcePos p);
DerefExpr(Expr *e, SourcePos p);
llvm::Value *GetValue(FunctionEmitContext *ctx) const;
llvm::Value *GetLValue(FunctionEmitContext *ctx) const;
const Type *GetType() const;
const Type *GetLValueType() const;
Symbol *GetBaseSymbol() const;
void Print() const;
Expr *TypeCheck();
Expr *Optimize();
int EstimateCost() const;
Expr *expr;
};
/** @brief Expression that represents dereferencing a pointer to get its
value. */
class PtrDerefExpr : public DerefExpr {
public:
PtrDerefExpr(Expr *e, SourcePos p);
const Type *GetType() const;
void Print() const;
Expr *TypeCheck();
int EstimateCost() const;
};
/** @brief Expression that represents dereferencing a reference to get its
value. */
class RefDerefExpr : public DerefExpr {
public:
RefDerefExpr(Expr *e, SourcePos p);
const Type *GetType() const;
void Print() const;
Expr *TypeCheck();
int EstimateCost() const;
};
/** Expression that represents taking the address of an expression. */
class AddressOfExpr : public Expr {
public: