Commit Graph

451 Commits

Author SHA1 Message Date
Steve Naroff 73d534a2e0 Add support for ObjC keyword selectors.
- Add SelectorInfo/SelectorTable classes, modeled after IdentifierInfo/IdentifierTable.
- Add SelectorTable instance to ASTContext, created lazily through ASTContext::getSelectorInfo().
- Add SelectorInfo slot to ObjcMethodDecl.
- Add helper function to derive a SelectorInfo from ObjcKeywordInfo.

Misc: Got the Decl stats stuff up and running again...it was missing support for ObjC AST's.
llvm-svn: 42023
2007-09-17 14:16:13 +00:00
Chris Lattner 93c7f855e5 remove some obsolete interfaces.
llvm-svn: 42014
2007-09-16 19:47:56 +00:00
Steve Naroff 2f742085f5 Fixes/tweaks that prevent "defaults-i.m" from compiling.
- Allow classnames as the receiver (removing a FIXME from ParseObjCMessageExpression).
- Added a FIXME to ParseObjCMessageExpression()...we need to return a message expr AST node!

llvm-svn: 42001
2007-09-16 16:16:00 +00:00
Steve Naroff 66356bda5d Rename statement actions (from Parse-prefix to ActOn-prefix).
llvm-svn: 42000
2007-09-16 14:56:35 +00:00
Steve Naroff 83895f7888 Rename expression actions (from Parse-prefix to ActOn-prefix).
llvm-svn: 41997
2007-09-16 03:34:24 +00:00
Hartmut Kaiser 0a6b11db24 Updated VC++ build system.
Silenced a couple of VC++ warnings.

llvm-svn: 41994
2007-09-16 00:04:22 +00:00
Chris Lattner 75e0c8cf4c add a new ASTConsumer consumer to simplify stuff in the driver.
Switch -parse-ast over to it.

llvm-svn: 41991
2007-09-15 22:56:56 +00:00
Steve Naroff 30d242c99f Start converting Action methods from Parse-prefix to ActOn-prefix.
The previous naming scheme was confusing, since it resulted in both the Parser and Action modules having methods with the same name. In addition, the Action module never does any parsing...

llvm-svn: 41986
2007-09-15 18:49:24 +00:00
Steve Naroff 2e688fde14 Rename Action::ParseRecordBody() to ProcessFieldDecls(), and add a visibility argument.
Remove Action::ObjcAddVisibilityToIvars(). No need for an extra API when it is trivial to add this info to the previous hook.

In general, I want to start migrating away from having Actions prefixed with "Parse" (which is confusing, since the Action API doesn't do any parsing, per se).

llvm-svn: 41973
2007-09-14 23:09:53 +00:00
Steve Naroff db47ee203a Several improvement to Sema::ParseRecordBody()...
- Adding a safer prologue. The previous prologue would accept a null and therefore assume we had an interface (which was incorrect).
- Fixed FieldDecl's classof method. This allowed me to simplify some unnecessary casting.
- When diagnosing errors, make sure the FieldDecl/EnclosingDecl are marked as invalid. In addition, don't delete the field...rather, add all fields to the enclosing decl. Memory management can/should be done elsewhere. This code was never "upgraded" to the recently added invalid decl strategy.

llvm-svn: 41964
2007-09-14 22:20:54 +00:00
Fariborz Jahanian f3287bf871 Patch to store ivars into interface class object.
llvm-svn: 41961
2007-09-14 21:08:27 +00:00
Fariborz Jahanian aefb23092c Semantic analysis for objective-c ivars.
llvm-svn: 41954
2007-09-14 16:27:55 +00:00
Steve Naroff 1d4b5eaeab Now that the dust has settled on the Decl refactoring, I noticed FieldDecl didn't need NextDeclarator. As a result, I'm removing it.
Removing both slots (NextDeclarator/Next) end up reducing the size of fields/ivars by 40%.

llvm-svn: 41948
2007-09-14 02:20:46 +00:00
Steve Naroff a23cc79654 Move Decl::NextDeclarator (w/ setters/getters) down to ScopedDecl/FieldDecl.
Decl is now svelte:-)

llvm-svn: 41935
2007-09-13 23:52:58 +00:00
Steve Naroff 9def2b15c1 Phase 2 of making the Decl class more lightweight...
Move Identifier/Loc instance variables (and associated getters/setters) down from Decl to ScopedDecl/FieldDecl.

Objc AST's can now inherit from Decl without getting instance variables and types that are C specific. For now, I am keeping NextDeclarator, since I believe it may be useful to ObjC. If not, it can be moved later.

llvm-svn: 41934
2007-09-13 21:41:19 +00:00
Fariborz Jahanian 6812cbb230 Patch for collecting ivars before running action on them.
llvm-svn: 41932
2007-09-13 20:56:13 +00:00
Steve Naroff 9324db12b2 Add "ScopedDecl" AST, used by ValueDecl and TypeDecl.
This allows us to sink the "Next" field, which isn't used by FieldDecl and ObjcIvarDecl.

llvm-svn: 41931
2007-09-13 18:10:37 +00:00
Steve Naroff 437b4d8bda Remove a FIXME. Replace a couple asserts with an appropriate error
diagnostic for illegal initializers.

llvm-svn: 41889
2007-09-12 20:13:48 +00:00
Fariborz Jahanian cfb31fab5e Patch for building method declaration nodes. Also fixed a segfault in cocoa.m due
to use of @property.

llvm-svn: 41880
2007-09-12 18:23:47 +00:00
Steve Naroff 6109140b00 Fix the following bug submitted by Ted Kremenek:
void func() {
int xx = xx; // incorrectly diagnosed 'xx' as an undeclared identifier.
}

This smallish bug resulted in a largish fix. Here are some highlights:

- Needed to make sure ParseDeclarator is called *before* parsing any
initializer. Removed the "Init" argument to ParseDeclarator.
- Added AddInitializerToDecl() to the Action & Sema classes.
In Sema, this hook is responsible for validating the initializer and
installing it into the respective decl.
- Moved several semantic checks from ParseDeclarator() to 
FinalizeDeclaratorGroup(). Previously, this hook was only responsible for 
reversing a list. Now it plays a much larger semantic role. 

All of the above changes ended up simplifying ParseDeclarator(), which
is goodness...

llvm-svn: 41877
2007-09-12 14:07:44 +00:00
Steve Naroff f2fb4ad08e - Add an ObjcIvarDecl AST node (a subclass of FieldDecl).
- Instantiate the node in Sema::ParseField(), based on the type of the TagDecl.
- Add Sema::ObjcAddInstanceVariable(), responsible for adorning/adding the ObjcIvarDecl.

llvm-svn: 41864
2007-09-11 21:17:26 +00:00
Steve Naroff 4292bde14f Fix the following bug submitted by Justin Handville.
int main(int argc, char* argv[])
{
  return 0;
}

After speaking briefly with Chris, we decided this should be a front-end fix.

The fix...have Sema::GetTypeForDeclarator() do the default function/array conversion, as
I outlined in the 9/9 email on this topic.

Since this conversion is done before Sema::ParseParamDeclarator(), I thought I could
remove the conversion from Sema::ParseParamDeclarator(). Unfortunately, this didn't work.
The conversion apparently needs to be done in both places (which doesn't make sense to me).

Will investigate.

llvm-svn: 41811
2007-09-10 22:17:00 +00:00
Steve Naroff acb1e7478f Some small tweaks to the recent Objc support...
llvm-svn: 41803
2007-09-10 20:51:04 +00:00
Fariborz Jahanian 33d037441e Early patch to collect objective-c methods inserts them in
class object.

llvm-svn: 41801
2007-09-10 20:33:04 +00:00
Steve Naroff 09bf815f89 The goal of this commit is to get just enough Sema support to recognize Objective-C classes
as types. That said, the AST nodes ObjcInterfaceDecl, ObjcInterfaceType, and ObjcClassDecl are *very*
preliminary.

The good news is we no longer need -parse-noop (aka MinimalActions) to parse cocoa.m.

llvm-svn: 41752
2007-09-06 21:24:23 +00:00
Ted Kremenek 73c18e0362 Added LabelLoc to GotoStmt to record the source location of the label token
in the actual GotoStmt.

Fixed bug where GotoStmt::getSourceRange incorrectly used the target LabelStmt
to compute its extent.

llvm-svn: 41745
2007-09-06 17:11:52 +00:00
Steve Naroff 67ae443954 Simplified initializer semantic analysis by adding the following 2 methods:
- ArrayType::getBaseType(), and 
- ConstantArrayType::getMaximumElements().

Wanted to do this cleanup before adding structure support, which will add more complexity.

llvm-svn: 41715
2007-09-04 21:13:33 +00:00
Steve Naroff 77b97002e9 Make sure initializer type promotions get propagated.
This fixes a recent regression with Codegen/mandel.c.

llvm-svn: 41696
2007-09-04 14:36:54 +00:00
Chris Lattner 9cf21c5a2c Silence VC++ warnings, patch by Hartmut Kaiser
llvm-svn: 41693
2007-09-04 02:45:27 +00:00
Steve Naroff ac074b4df4 More fun with initializers!
- Fixed many bugs, enhanced test case considerably, added a diagnostic, etc.
- Refactored CheckInitList() into CheckVariableInitList()/CheckConstantInitList().
- Added CheckInitExpr().
- Support for multi-dimensional arrays looking good.

llvm-svn: 41690
2007-09-04 02:20:04 +00:00
Chris Lattner 1463cca1cc Add a method required by the VC++ STL, patch by Hartmut Kaiser!
llvm-svn: 41687
2007-09-03 18:31:57 +00:00
Steve Naroff 7d2c5ed92e Finish getting "array-init.c" to work properly.
Array scalar initialization is now is reasonable shape.

Next step, structure and array of structure initializers.

llvm-svn: 41681
2007-09-03 01:24:23 +00:00
Steve Naroff b03f5940d1 More progress on array initializers.
- Added Expr::isConstantExpr().
- Added type checking for InitListExpr elements.
- Added diagnostic for trying to initialize a variable sized object.

llvm-svn: 41674
2007-09-02 20:30:18 +00:00
Steve Naroff f33527a1aa More semantic analysis of initializers.
Added 2 errors and one warning, updated test case.

llvm-svn: 41672
2007-09-02 15:34:30 +00:00
Steve Naroff 2fea13926f Start implementing semantic analysis for C initializers.
Step 1: Start instantiating InitListExpr's.
Step 2: Call newly added function Sema::CheckInitializer() from Sema::ParseDeclarator().
Step 3: Give InitListExpr's a preliminary type.
Step 4: Start emitting diagnostics for simple assignments.

Note:

As a result of step 1, the CodeGen/mandel.c test asserts "Unimplemented agg expr!", which is expected.

As a result of step 4, the test below now fails. This isn't expected and needs to be investigated (it appears type checking for C++ references is flawed in some way).

******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************
Command: 
 clang -fsyntax-only Sema/cxx-references.cpp
Output:
Sema/cxx-references.cpp:8:12: warning: incompatible pointer types assigning 'int &*' to 'int *'
  int *p = &r;
           ^~
Sema/cxx-references.cpp:10:20: error: incompatible types assigning 'int (int)' to 'int (&)(int)'
  int (&rg)(int) = g;
                   ^
Sema/cxx-references.cpp:13:18: error: incompatible types assigning 'int [3]' to 'int (&)[3]'
  int (&ra)[3] = a;
                 ^
Sema/cxx-references.cpp:16:14: error: incompatible types assigning 'int *' to 'int *&'
  int *& P = Q;
             ^
4 diagnostics generated.
******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************

llvm-svn: 41671
2007-09-02 02:04:30 +00:00
Steve Naroff 42a350a18a Finish converting SwitchStmt AST to source ranges.
Move DumpSourceRange() to DumpStmt().

Now -parse-ast-dump will display source range info for all stmts/exprs.

One day we should implement the source range protocol for Decls.

llvm-svn: 41670
2007-09-01 21:08:38 +00:00
Steve Naroff dc9f36e6c4 Convert more statments over to SourceRanges...
llvm-svn: 41666
2007-08-31 23:49:30 +00:00
Steve Naroff 33f3d05081 Move SourceRange protocol from Expr->Stmt.
Converted many of the statements over. Still a hanful left...

llvm-svn: 41663
2007-08-31 23:28:33 +00:00
Chris Lattner cac27a5478 Fix a bug/missing-feature Ted noticed: the 'unused' warning should not
warn about the last stmt in a stmtexpr, f.e. there should be no warning for:

int maxval_stmt_expr(int x, int y) {
  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
}

llvm-svn: 41655
2007-08-31 21:49:55 +00:00
Chris Lattner 78502cf4c9 diagnose extended uses of offsetof
llvm-svn: 41653
2007-08-31 21:49:13 +00:00
Steve Naroff 096dd942cf Removed Sema::VerifyConstantArrayType(). With the new Array/ConstantArray/VariableArray nodes, this
routine was causing more trouble than it was worth. Anders/Chris noticed that it could return an error code
without emiting a diagnostic (which results in an silent invalid decl, which should *never* happen). In addition,
this routine didn't work well for typedefs and field decls. Lastly, it didn't consider that initializers aren't
in place yet.

Added Type::getAsConstantArrayType(), Type::getAsVariableArrayType(), Type::getAsVariablyModifiedType(),
and Type::isVariablyModifiedType();

Modified Sema::ParseDeclarator() and Sema::ParseField() to use the new predicates. Also added a FIXME for
the initializer omission. Also added a missing test for "static" @ file scope.

llvm-svn: 41647
2007-08-31 17:20:07 +00:00
Anders Carlsson 4692db0e7e Add InitListExpr class.
llvm-svn: 41636
2007-08-31 04:56:16 +00:00
Chris Lattner 57c523f50c add actions for deleting expr/stmt nodes.
llvm-svn: 41635
2007-08-31 04:53:24 +00:00
Steve Naroff 43b8f7fa4f Sema::ParseCastExpr() missing call to UsualUnaryConversions().
The following case now works...

void empty(void * a ) {}

void test()
{
    unsigned char A[4]; 
    empty( (void *) A); 
}

Thanks to Patrick Flannery for finding this...

llvm-svn: 41630
2007-08-31 00:32:44 +00:00
Steve Naroff d57fa94148 Final phase of array cleanup (for now), removing a FIXME from yesterday.
Moved several array constraints checks from Sema::VerifyConstantArrayType() to
Sema::GetTypeForDeclarator(). VerifyConstantArrayType() is now very simple, and
could be removed eventually.

Now, we get the following (correct) messages for BlockVarDecls:-)

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -pedantic
x.c:4:20: error: size of array has non-integer type 'float'
  int size_not_int[f];
                   ^
x.c:5:21: error: array size is negative
  int negative_size[1-2];
                    ^~~
x.c:6:17: warning: zero size arrays are an extension
  int zero_size[0];
                ^
3 diagnostics generated.

llvm-svn: 41624
2007-08-30 22:35:45 +00:00
Steve Naroff 90dfdd5774 Polish yesterday's Array/ConstantArray/VariableArray rewrite, removing a couple FIXME's.
Refactored Array/VariableArray, moving SizeModifier/IndexTypeQuals back up to Array. These
attributes are not specific to VLA's. Most of them are specific to array parameter types.

llvm-svn: 41616
2007-08-30 18:10:14 +00:00
Chris Lattner 98dbf0a3b8 implement pretty printing of offsetof
llvm-svn: 41615
2007-08-30 17:59:59 +00:00
Chris Lattner f17bd423c2 implement initial sema support for __builtin_offsetof
llvm-svn: 41613
2007-08-30 17:45:32 +00:00
Chris Lattner 55343038f4 Fix 80 col violations.
llvm-svn: 41611
2007-08-30 17:08:17 +00:00
Chris Lattner 270228599d Fix a regression on test/Sema/unused-expr.c by fixing the type predicates
to test for the right type class.

llvm-svn: 41601
2007-08-30 06:10:41 +00:00