Commit Graph

270 Commits

Author SHA1 Message Date
Chris Lattner b16f455e8c Type::isSignedInteger() and isUnsignedInteger() did not properly account for
'char', which varies based on the target.

Instead of spreading target knowledge throughout the compiler, bifurcate char
into Char_S and Char_U, and have ASTContext create the right one based on the
target, when it starts up.

llvm-svn: 39577
2007-06-03 07:25:34 +00:00
Bill Wendling 5d107662f0 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Added a method to determine if two types, where at least one is a
  reference, are compatible. That is you can assign the RHS to the LHS.

llvm-svn: 39566
2007-06-02 23:27:35 +00:00
Chris Lattner 226d419e21 trivial simplification
llvm-svn: 39563
2007-06-02 22:47:37 +00:00
Chris Lattner b4522b4dec Pretty print storage classes for vardecls.
llvm-svn: 39556
2007-06-02 05:27:01 +00:00
Chris Lattner 238cbc58c3 Modify Expr::isConstantExpr and friends take a pointer to a SourceLoc instead
of one by reference, making it optional.

llvm-svn: 39552
2007-06-02 04:48:48 +00:00
Chris Lattner e0c4ae1f24 Generalize this to support printing any valuedecl, e.g. function definitions.
We now print:
  extern void blah();
as:
  void (blah)();

Strange, but ok :)

llvm-svn: 39549
2007-06-02 03:38:08 +00:00
Steve Naroff 6a0675f8a4 Bug #:
Submitted by:
Reviewed by:
Add implemention file for GCC attributes

llvm-svn: 39542
2007-06-01 21:54:34 +00:00
Steve Naroff 0f2fe17ff1 Bug #:
Submitted by:
Reviewed by:
Implement support for GCC __attribute__.

- Implement "TODO" in Parser::ParseAttributes. Changed the return type from
void to Parser::DeclTy. Changed all call sites to accept the return value.
- Added Action::ParseAttribute and Sema::ParseAttribute to return an
appropriate AST node. Added new node AttributeDecl to Decl.h.

Still to do...hook up to the Decl...

llvm-svn: 39539
2007-06-01 17:11:19 +00:00
Chris Lattner a076fde1e3 more minor improvements to pretty printer.
llvm-svn: 39538
2007-05-31 18:21:33 +00:00
Chris Lattner b4619481e6 add some ;'s
llvm-svn: 39537
2007-05-31 06:00:14 +00:00
Chris Lattner df3cafb796 fix a small printer bug, to emit:
a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }
  int e;

instead of:

  a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }  int e;

llvm-svn: 39535
2007-05-31 05:08:56 +00:00
Chris Lattner fc068c15d9 pretty print exprs in stmt contexts with a trailing semicolon.
llvm-svn: 39531
2007-05-30 17:57:36 +00:00
Steve Naroff 9992bbab14 Bug #:
Submitted by:
Reviewed by:
- ParseForStatement(): Put back a test/assignment. My removal of
ParseExprStmt() was a bit over zealous:-(thanks to Chris for pointing it out)
- Add assert to VisitDeclStmt().
- Removed an out-of-date FIXME
- Added some curlies for a couple multi-line calls to Diag().

llvm-svn: 39528
2007-05-30 16:27:15 +00:00
Chris Lattner d5322cd27e Don't print billions of spaces for a label with no indent.
llvm-svn: 39521
2007-05-29 23:49:07 +00:00
Steve Naroff 2a8ad18e71 Bug #:
Submitted by:
Reviewed by:
Implement some FIXME's that stand in the way of fully typechecking "for"
statements. This involved:

- Adding a DeclStmt AST node (with statement visitor). The DeclStmt
printer is preliminary.
- Added a ParseDeclStmt action, called from Parser::ParseForStatement()
and Parser::ParseStatementOrDeclaration(). DID NOT add to
Parser::ParseIdentifierStatement()...probably could have, however didn't
really understand the context of this rule (will speak with Chris).
- Removed ParseExprStmt (and it's clients)...it was vestigial.

llvm-svn: 39518
2007-05-29 22:59:26 +00:00
Chris Lattner eefa10e78a implement full sema support for the GCC address-of-label extension.
llvm-svn: 39510
2007-05-28 06:56:27 +00:00
Chris Lattner e2473068d4 Change GotoStmt's to have a pointer to the LabelStmt instead of a pointer to
the label identifier.  Handle fwd references etc.  This allows us to detect
uses of undefined labels and label redefinitions, such as:

t.c:2:12: error: redefinition of label 'abc'
  abc: ;   abc:
           ^
t.c:2:3: error: previous definition is here
  abc: ;   abc:
  ^
t.c:12:12: error: use of undeclared label 'hijl'
      goto hijl;
           ^

llvm-svn: 39509
2007-05-28 06:28:18 +00:00
Chris Lattner 2f6ac263ef Null pointers in the ast are no longer considered to be the null stmt.
llvm-svn: 39507
2007-05-28 01:47:47 +00:00
Chris Lattner 012a6cf1de add a NullStmt ast node.
llvm-svn: 39505
2007-05-28 01:41:58 +00:00
Steve Naroff 9358c715da Bug #:
Submitted by:
Reviewed by:
- Added type checking to Sema::ParseReturnStmt (still under construction).
- Improved Expr::isLvalue() and Expr::isModifiableLvalue() to return more
info. Used the info in Sema::CheckAssignmentOperands() to produce more
descriptive diagnostics. Added FIXME to other clients of isLvalue()/etc.
- Added a SourceLocation slot to MemberExpr...changed the implementation
of getSourceRange().
- Added getResultType() helper to FunctionDecl.
- Changed many Diag calls to use the SourceRange support (now that it's
a big hit...we better milk it:-).

llvm-svn: 39501
2007-05-27 23:58:33 +00:00
Bill Wendling c5fc5f197d Bug #:
Submitted by: Bill Wendling
Reviewed by:

- Can do just a 'cast<>()' because we're checking that it's Tagged.

llvm-svn: 39500
2007-05-27 23:36:18 +00:00
Bill Wendling 229f243f5f Bug #:
Submitted by: Bill Wendling
Reviewed by: Steve Naroff

- Steve suggested avoiding the dyn_cast by using the "Tagged" type class
  and having the "default" just return false.

llvm-svn: 39499
2007-05-27 23:31:02 +00:00
Bill Wendling 21862c3fbd Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Rework the isDerivedType method so that if a language doesn't support
  references, it won't have to pay the price for them. This inlines the
  checks for derived types and turns it into a switch statement instead.

llvm-svn: 39498
2007-05-27 22:46:14 +00:00
Bill Wendling 3708c18559 Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Initial support for C++ references. Adding to the AST and Parser.
  Skeletal support added in the semantic analysis portion. Full semantic
  analysis is to be done soon.

llvm-svn: 39496
2007-05-27 10:15:43 +00:00
Chris Lattner 7eef919d82 Accept parenthesized expressions like ((void*)0) and (void*)(0) as null pointer
constants.

llvm-svn: 39493
2007-05-24 01:23:49 +00:00
Chris Lattner a5490953d1 correct printout, enums are separate.
llvm-svn: 39492
2007-05-24 01:09:39 +00:00
Chris Lattner f95211394a implement printer support for C++ bool literals
llvm-svn: 39489
2007-05-24 00:50:25 +00:00
Chris Lattner 24e0d6cf40 Implement a fixme
llvm-svn: 39488
2007-05-24 00:47:01 +00:00
Chris Lattner fc234de388 silence a bunch of warnings, fix some funky indentation.
llvm-svn: 39487
2007-05-24 00:40:54 +00:00
Steve Naroff f84d11f9d7 Bug #:
Submitted by:
Reviewed by:
Added "global" statistics gathering for Decls/Stmts/Exprs.
Very useful for working with a single file. When we start compiling
multiple files, will need to enhance this to collect stats on a per-module
basis.

llvm-svn: 39485
2007-05-23 21:48:04 +00:00
Bill Wendling 48fbdd0302 Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Changed "std::cerr" to "OS" stream to be consistent with the other
  outputs in the method.

llvm-svn: 39483
2007-05-23 08:04:21 +00:00
Chris Lattner d1654ef0ed Split the AST library into two libraries: libast and libsema.
llvm-svn: 39477
2007-05-21 17:34:19 +00:00
Chris Lattner e6b0f626bb minor simplification
llvm-svn: 39476
2007-05-21 05:58:35 +00:00
Chris Lattner 0643041f6c In the yet-another-crazy-idea department, we now print the actual *value* of
integer constants, whoa! :)

llvm-svn: 39475
2007-05-21 05:45:03 +00:00
Chris Lattner 67ca9252f8 Implement Sema::ParseNumericConstant for integer constants in terms of APInt
and correctly in terms of C99 6.4.4.1p5.

llvm-svn: 39473
2007-05-21 01:08:44 +00:00
Chris Lattner 4dc8a6f1e7 add ASTContext::getIntegerBitwidth method.
llvm-svn: 39472
2007-05-20 23:50:58 +00:00
Chris Lattner 073926e39a pretty print switch/if stmts whose bodies are compound stmts.
llvm-svn: 39469
2007-05-20 23:04:55 +00:00
Chris Lattner b9eb5a1cec Pretty print labels and case stmts better. This leads to output like this:
void foo() {
abc:
def:
hij:
case 1:
case 1:
  goto abc
baz:
  goto def
}

instead of:

void foo() {
  abc:
    def:
      hij:
        case 1:
          case 1:
            goto abc
  baz:
    goto def
}

llvm-svn: 39468
2007-05-20 22:52:15 +00:00
Chris Lattner 3bbe7bed39 Don't "optimize" empty or unit compound exprs away.
llvm-svn: 39467
2007-05-20 22:47:04 +00:00
Steve Naroff 30d1fbc803 Bug #:
Submitted by:
Reviewed by:
Bozo bug in last checkin. Needed to move the check for null pointers
up (and out of the pointer/pointer clause).

llvm-svn: 39466
2007-05-20 19:46:53 +00:00
Steve Naroff ada7d4298b Bug #:
Submitted by:
Reviewed by:
Fix two bugs...

- Sema::CheckConditionalOperands(). Needed to move the check for
null pointer constants up to the clause dealing with two pointers types.
The previous code would never get executed.
- Expr::isNullPointerConstant(). This predicate was much too naive...it
should have had a FIXME (my bad). It now deals with "void *" cast expressions.
It still has one major bug...it needs to evaluate the expression to correctly
determine if it is a null pointer constant (e.g. 7-7 should pass).

llvm-svn: 39464
2007-05-20 17:54:12 +00:00
Chris Lattner db5ac601e7 eliminate an extraneous space when printing qualified types in some cases.
llvm-svn: 39461
2007-05-20 04:21:51 +00:00
Chris Lattner 84e160a7a8 fix some indentation funkiness
llvm-svn: 39457
2007-05-19 07:03:17 +00:00
Steve Naroff 71ce2e061d Bug #:
Submitted by:
Reviewed by:
An important, but truly mind numbing change.

Added 6 flavors of Sema::Diag() that take 1 or two SourceRanges. Considered
adding 3 flavors (using default args), however this wasn't as clear.

Removed 2 flavors of Sema::Diag() that took LexerToken's (they weren't used).

Changed all the typechecking routines to pass the appropriate range(s).

Hacked the diagnostic machinery and driver to acccommodate the new data.

What's left? A FIXME in clang.c to use the ranges. Chris offered to do the
honors:-) Which includes taking us to the end of an identifier:-)

llvm-svn: 39456
2007-05-18 22:53:50 +00:00
Steve Naroff e845e272ba Bug #:
Submitted by:
Reviewed by:
More tweaks to error diagnostics (adding types, using the new hooks on expr).
Still more to do...

llvm-svn: 39455
2007-05-18 01:06:45 +00:00
Steve Naroff 72cada0ad9 Bug #:
Submitted by:
Reviewed by:
Extended Expr's constant expression predicates to return a source location
if the predicate returns false. This enables us to position the cursor
exactly were the error occurred (simple pleasures:-).

constant.c:9:9: error: enumerator value for 'E2' is not an integer constant
  E2 = (aconst + 1), // illegal
        ^
constant.c:10:8: error: enumerator value for 'E3' is not an integer constant
  E3 = "abc",
       ^
constant.c:12:12: error: enumerator value for 'E5' is not an integer constant
  E5 = 0?7:printf("xx"), // illegal
           ^
constant.c:13:12: error: enumerator value for 'E6' is not an integer constant
  E6 = 1?7:printf("xx"), // legal
           ^
constant.c:16:14: error: enumerator value for 'E9' is not an integer constant
  E9 = E0 || a, // illegal
             ^
constant.c:21:6: error: array has incomplete element type 'void'
void ary[7];
     ^
constant.c:22:28: error: variable length array declared outside of any function
struct { int a; } ary2[1?7:printf("xx")],
                           ^
constant.c:23:34: error: variable length array declared outside of any function
                  aryIllegal[0?7:printf("yy")];
                                 ^
constant.c:25:10: error: variable length array declared outside of any function
int ary3[a]; // illegal
         ^
constant.c:26:17: error: size of array has non-integer type 'float'
typedef int vla[2.0]; // illegal
                ^
constant.c:30:22: error: size of array has non-integer type 'float'
int nonIntegerArray2[1+2.0];
                     ^

llvm-svn: 39454
2007-05-18 00:18:52 +00:00
Steve Naroff 53f07dc54d Bug #:
Submitted by:
Reviewed by:
Refinements to the SourceRange/SourceLocation work.

- Renamed Expr::getSourceLocation() helper function to getLocStart(). Added
Expr::getLocEnd(). Converted all the getSourceRange() methods to use the new helpers.
- Removed many getSourceLocation() accessors. The Expr::getLocStart() helper
is the "right" way to get a source location. If we want to add class specific
getters (for location), then the names should be reflective of the specific class.
For examaple, UnaryOperator::getOpLocation(). For now, I see no reason to have these.
- Fixed StringLiteral.
- Start actually instantiating ParenExpr()!

llvm-svn: 39453
2007-05-17 21:49:33 +00:00
Steve Naroff 509fe025aa Bug #:
Submitted by:
Reviewed by:
- Added a getSourceRange() method to all subclasses of Expr.
- Changed all the constructors and instantiators.
- Only added SourceLocations's when necessary. For example, binary
expression *don't* carry the operator location...it isn't
necessary to implement getSourceRange(). On the other hand, unary
expressions *do* carry the operator location.
- Added trivial SourceRange value class to SourceLocation.

Note: need to talk to Chris about the FIXME for StringLiteral...
llvm-svn: 39452
2007-05-17 01:16:00 +00:00
Steve Naroff a78fe7e3ed Bug #:
Submitted by:
Reviewed by:
- Implement type checking for Sema::CheckConditionalOperands.
- Fixed crasher in Sema::UsualUnaryConversion (incorrect use of cast<>).
- Added a few diagnostics and started passing 2 args! (Thanks Chris!).

Here's some diagnostic output that is much nicer than gcc...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang cond.c
cond.c:12:14: error: used type 'struct foo' where arithmetic or pointer type is required
  result = s ? 1 : 2;
             ^
cond.c:13:14: error: incompatible operand types ('struct foo' and 'struct bar')
  result = a ? s : s2;
             ^
cond.c:14:14: warning: pointer type mismatch ('struct foo *' and 'struct bar *')
  result = a ? ps : ps2;
             ^
cond.c:14:10: warning: assignment makes integer from pointer without a cast
  result = a ? ps : ps2;
         ^
cond.c:15:14: error: incompatible operand types ('struct foo *' and 'struct foo')
  result = a ? ps : s;
             ^
cond.c:16:14: warning: pointer type mismatch ('void (*)(int)' and 'void (*)(int, int)')
  result = a ? func : func2;
             ^
cond.c:16:10: warning: assignment makes integer from pointer without a cast
  result = a ? func : func2;
         ^
7 diagnostics generated.
[dylan:~/llvm/tools/clang] admin% cc -c cond.c
cond.c: In function 'main':
cond.c:12: error: used struct type value where scalar is required
cond.c:13: error: type mismatch in conditional expression
cond.c:14: warning: pointer type mismatch in conditional expression
cond.c:14: warning: assignment makes integer from pointer without a cast
cond.c:15: error: type mismatch in conditional expression
cond.c:16: warning: pointer type mismatch in conditional expression
cond.c:16: warning: assignment makes integer from pointer without a cast

llvm-svn: 39451
2007-05-16 19:47:19 +00:00
Chris Lattner c04bd6ae32 Remove the Sema::Diag helper that takes a type. Convert clients to use
the version that takes a string.

llvm-svn: 39450
2007-05-16 18:09:54 +00:00