Commit Graph

111 Commits

Author SHA1 Message Date
Fariborz Jahanian 797f24cd7e Encoding for objectiive-c methods.
llvm-svn: 43481
2007-10-29 22:57:28 +00:00
Chris Lattner 1159f065be Fix a major bug in the Type::getAs*Type methods: they didn't strip off
typeof(type) and typeof(expr) correctly.  Now provide a single point of
contact (Type::getDesugaredType) for doing the shallow stripping we need.

llvm-svn: 43432
2007-10-29 03:41:11 +00:00
Anders Carlsson 7080597adf Add BuiltinType::Char_S to Type::isCharType
llvm-svn: 43428
2007-10-29 02:52:18 +00:00
Steve Naroff 32e44c0032 Move type compatibility predicates from Type to ASTContext. In addition, the predicates are now instance methods (they were previously static class methods on Type).
This allowed me to fix the following hack from this weekend...

// FIXME: Devise a way to do this without using strcmp.
// Would like to say..."return getAsStructureType() == IdStructType;", but
// we don't have a pointer to ASTContext.
bool Type::isObjcIdType() const {
  if (const RecordType *RT = getAsStructureType())
    return !strcmp(RT->getDecl()->getName(), "objc_object");
  return false;
}

...which is now...

bool isObjcIdType(QualType T) const {
  return T->getAsStructureType() == IdStructType;
}

Side notes:

- I had to remove a convenience function from the TypesCompatibleExpr class.

int typesAreCompatible() const {return Type::typesAreCompatible(Type1,Type2);}

Which required a couple clients get a little more verbose...

-    Result = TCE->typesAreCompatible();
+    Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());

Overall, I think this change also makes sense for a couple reasons...

1) Since ASTContext vends types, it makes sense for the type compatibility API to be there.
2) This allows the type compatibility predeciates to refer to data not strictly present in the AST (which I have found problematic on several occasions).

llvm-svn: 43009
2007-10-15 20:41:53 +00:00
Steve Naroff 66e9f331ba Added ASTContext::setObjcIdType/getObjcIdType(), set by Sema.
Also noticed ASTContext::BuiltinVaListType wasn't being initialized to the null type (so I set it).

llvm-svn: 42983
2007-10-15 14:41:52 +00:00
Steve Naroff 271643620b Teach the type checker about "id". This removes the following bogus warning...
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang t.m
t.m:29:18: warning: incompatible pointer types assigning 'id' to 'NSString *'
    resultString = [[NSString alloc] initWithFormat:0 arguments:0];
    ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

llvm-svn: 42975
2007-10-15 03:14:16 +00:00
Steve Naroff 5d15254496 - Teach ObjcInterfaceDecl::lookupInstance/ClassMethod to look through protocols.
- Start looking up methods in the global method pools (for "id").
- Start integrating interface types into the type system.

llvm-svn: 42971
2007-10-14 23:13:51 +00:00
Fariborz Jahanian d797113659 Implemented parsing of objctive-c protocol conforming type used in
an identifier statement. Fixed up pretty priting to print this type 
correctly.

llvm-svn: 42866
2007-10-11 18:08:47 +00:00
Fariborz Jahanian 70e8f1024a Patch to create protocol conforming class types.
llvm-svn: 42856
2007-10-11 00:55:41 +00:00
Chris Lattner ef6b136781 move IdentifierTable.h from liblex to libbasic.
llvm-svn: 42730
2007-10-07 08:58:51 +00:00
Steve Naroff 67391b8a54 Move ObjC decls to DeclObjC.h, a new AST header.
Update clients and add to project file.

llvm-svn: 42494
2007-10-01 19:00:59 +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
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
Steve Naroff 09b0fd24a7 Diff is self small & self explanatory...
llvm-svn: 41621
2007-08-30 18:45:57 +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 1e43547a53 fix a bug that is causing CodeGen/complex.c to be grumpy.
llvm-svn: 41603
2007-08-30 06:19:11 +00:00
Steve Naroff 5c13180a27 Fix the following redefinition errors submitted by Keith Bauer...
[dylan:~/llvm/tools/clang] admin% cat tentative_decls.c 
// incorrectly generates redefinition error
extern int array[3];
int array[3];

// incorrectly generates a redefinition error
extern void nup(int a[3]);
void nup(int a[3]) {}

It turns out that this exposed a fairly major flaw in the type system,
array types were never getting uniqued! This is because all array types
contained an expression, which aren't unique.

To solve this, we now have 2 array types, ConstantArrayType and
VariableArrayType. ConstantArrayType's are unique, VAT's aren't.

This is a fairly extensive set of fundamental changes. Fortunately,
all the tests pass. Nevertheless, there may be some collateral damage:-)
If so, let me know!

llvm-svn: 41592
2007-08-30 01:06:46 +00:00
Chris Lattner 8a241f9359 Teach Type::is[un]SignedIntegerType about enum decls. This allows the code generator
to emit signed comparisons when needed for enum decl references.  This implements
test/CodeGen/enum.c.  I think enums should be good now.

llvm-svn: 41572
2007-08-29 17:48:46 +00:00
Steve Naroff 808eb8fe88 Add Type::getAsBuiltinType() and Type::builtinTypesAreCompatible().
Modified Type::typesAreCompatible() to use the above.

This fixes the following bug submitted by Keith Bauer (thanks!).

int equal(char *a, const char *b)
{
    return a == b;
}

Also tweaked Sema::CheckCompareOperands() to ignore the qualifiers when
comparing two pointer types (though it doesn't relate directly to this bug).

llvm-svn: 41476
2007-08-27 04:08:11 +00:00
Chris Lattner f78c30f75d add getAsComplexType() for consistency
llvm-svn: 41229
2007-08-21 16:54:08 +00:00
Chris Lattner cbe4f77c9e add a new AST dumper interface (E->dump()). This dumps out
the AST in a structural, non-pretty, form useful for understanding
the AST.  It isn't quite done yet, but is already somewhat useful.

For this example:

int test(short X, long long Y) {
  return X < ((100));
}

we get (with -parse-ast-dump):

int test(short X, long long Y)
(CompoundStmt 0x2905ce0
  (ReturnStmt 0x2905cd0
    (BinaryOperator 0x2905cb0 '<'
      (ImplicitCastExpr 0x2905ca0
        (DeclRefExpr 0x2905c20 Decl='X' 0x2905bb0))
      (ParenExpr 0x2905c80
        (ParenExpr 0x2905c60
          (IntegerLiteral 0x2905c40 100))))))

llvm-svn: 40954
2007-08-08 22:51:59 +00:00
Steve Naroff 12b0447bc6 Finish implementing __builtin_classify_type()...
llvm-svn: 40951
2007-08-08 22:15:55 +00:00
Steve Naroff 04e8bc8e35 Remove a space from "typeof" printing. It was causing the following error...
[dylan:clang/test/Parser] admin% ../../../../Debug/bin/clang -parse-ast-check typeof.c 
Warnings expected but not seen:
  Line 21: incompatible types assigning 'typeof(*pi) const' to 'int *'
Warnings seen but not expected:
  Line 21: incompatible types assigning 'typeof(*pi)  const' to 'int *'

Also corrected a typo from my previous commit.

llvm-svn: 40832
2007-08-05 03:24:45 +00:00
Steve Naroff 788d864d6c - Finish hooking up support for __builtin_types_compatible_p().
- Fix type printing code for recently added TypeOfExpr/TypeOfType.

llvm-svn: 40700
2007-08-01 23:45:51 +00:00
Steve Naroff 236becbbc3 Two typeof() related changes...
- Changed the name of ASTContext::getTypeOfType(Expr*)->getTypeOfExpr().
- Remove FIXME for TypeOfExpr::getAsStringInternal(). This will work fine for printing the AST. It isn't ideal
for error diagnostics (since it's more natural to display the expressions type). 

One "random" (or at least delayed:-) change...

- Changed all "ext_typecheck_*" diagnostics from EXTENSION->WARNING. Reason: Since -pedantic is now
off (by default), these diagnostics were never being emitted (which is bad). With this change, clang will
emit the warning all the time. The only downside (wrt GCC compatibility) is -pedantic-errors will not turn
this diagnostics into errors (a "feature" of making tagging them with EXTENSION). When/if this becomes
an issue, we can revisit.

llvm-svn: 40676
2007-08-01 17:20:42 +00:00
Chris Lattner 0ddc7ba2e5 move trivial type predicates inline.
llvm-svn: 40651
2007-07-31 21:13:58 +00:00
Chris Lattner 4197796f65 split the rest of the type predicates into pure predicates:
there is now an isXXXType and a getAsXXXType

llvm-svn: 40646
2007-07-31 19:29:30 +00:00
Chris Lattner cd1d086b5a rename isReferenceType to follow the new scheme.
llvm-svn: 40640
2007-07-31 16:56:34 +00:00
Chris Lattner c996b176e8 make isPointerType() a pure predicate, rename the
existing one to getAsPointerType()

llvm-svn: 40639
2007-07-31 16:53:04 +00:00
Steve Naroff ad373bdcfe Add parsing and AST support for GNU "typeof".
Many small changes to lot's of files.
Still some FIXME's, however the basic support is in place.

llvm-svn: 40631
2007-07-31 12:34:36 +00:00
Steve Naroff f7a5da17d9 Added a new expression, OCUVectorComponent.
llvm-svn: 40577
2007-07-28 23:10:27 +00:00
Steve Naroff c701ace221 Add Type::isOCUVectorType().
Convert isFunctionType(), isStructureType(), and isUnionType() to the new API.

llvm-svn: 40541
2007-07-26 18:32:01 +00:00
Steve Naroff 62b35d41cd Forgot a return stmt (oops).
llvm-svn: 40509
2007-07-26 03:18:02 +00:00
Steve Naroff 185616f293 Various improvements to Sema::ParseMemberReferenceExpr().
- Added source range support to Diag's.
- Used the new type predicate API to remove dealing with the canonical
type explicitly.
- Added Type::isRecordType().
- Removed some casts.
- Removed a const qualifier from RecordType::getDecl(). 

llvm-svn: 40508
2007-07-26 03:11:44 +00:00
Steve Naroff 44fd8ff400 Fix Sema::ParseCallExpr()...it wasn't doing the default array/function promotions on it's argument types.
This resulted in the following errors when compiling promote_types_in_proto.c test...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang test/Parser/promote_types_in_proto.c 
test/Parser/promote_types_in_proto.c:7:24: error: incompatible types passing 'char *[]' to function expecting 'char *const []'
        arrayPromotion(argv);
        ~~~~~~~~~~~~~~ ^~~~
test/Parser/promote_types_in_proto.c:8:27: error: incompatible types passing 'void (char *const [])' to function expecting 'void (char *const [])'
        functionPromotion(arrayPromotion);
        ~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~
2 diagnostics generated.

When fixing this, noticed that both ParseCallExpr() and ParseReturnStmt() were prematurely comparing types for
equivalence. This is incorrect (since the expr. promotions haven't been done yet). To fix this, I moved the
check "down" to Sema::CheckAssignmentConstraints().

I also converted Type::isArrayType() to the modern API (since I needed it). Still more Type predicates to 
convert.

llvm-svn: 40475
2007-07-24 21:46:40 +00:00
Chris Lattner 9802144709 Fix a valgrind error noticed by Benoit Boissinot
llvm-svn: 40113
2007-07-20 18:48:28 +00:00
Bill Wendling ee673372ef Return the correct type from isReferenceType().
llvm-svn: 39956
2007-07-17 04:47:36 +00:00
Bill Wendling 354fb2678d Change dyn_cast for reference types to be more like pointers and not need the canonical type. Also fix so that we're not expecting a return value from a void function
llvm-svn: 39954
2007-07-17 04:16:47 +00:00
Chris Lattner 96d423ef37 In the final step for preserving typedef info better in the AST, upgrade
isPointerType and isVectorType to only look through a single level of typedef
when one is present.  For this invalid code:

typedef float float4 __attribute__((vector_size(16)));
typedef int int4 __attribute__((vector_size(16)));
typedef int4* int4p;
void test(float4 a, int4p result, int i) {
    result[i] = a;
}

we now get:

t.c:5:15: error: incompatible types assigning 'float4' to 'int4'
    result[i] = a;
    ~~~~~~~~~ ^ ~

instead of:

t.c:5:15: error: incompatible types assigning 'float4' to 'int  __attribute__((vector_size(16)))'
    result[i] = a;
    ~~~~~~~~~ ^ ~

The rest of the type predicates should be upgraded to do the same thing.

llvm-svn: 39932
2007-07-16 22:05:22 +00:00
Chris Lattner aee0cfd486 Now that isPointerType can return a pointer type, avoid stripping off typedef
information in the common case.  On this invalid code:

typedef float float4 __attribute__((vector_size(16)));
typedef int int4 __attribute__((vector_size(16)));
void test(float4 a, int4 *result, int i) {
    result[i] = a;
}

we now generate:
  t.c:5:15: error: incompatible types assigning 'float4' to 'int4'
instead of:
  t.c:5:15: error: incompatible types assigning 'float4' to 'int  __attribute__((vector_size(16)))'

This implements test/Sema/typedef-retain.c

llvm-svn: 39892
2007-07-16 00:23:25 +00:00
Chris Lattner 68ebef886a as a very useful feature, make isVectorType and isPointerType return
the actual vectortype or pointertype when they return success.

llvm-svn: 39890
2007-07-16 00:13:25 +00:00
Chris Lattner 0e9d6226ca Refactor code so that isIntegerConstantExpr has an ASTContext available.
llvm-svn: 39884
2007-07-15 23:26:56 +00:00
Chris Lattner 983a8bbbb2 Move getSize() out of type, into ASTContext, where it has target info, and
where ASTContext can manage caches for struct layout, etc.

llvm-svn: 39835
2007-07-13 22:13:22 +00:00
Chris Lattner 2ce5dd4c98 remove some extraneous spaces, no functionality change.
llvm-svn: 39832
2007-07-13 21:01:17 +00:00
Chris Lattner d2b88ab313 Implement codegen for + and - with pointers. Patch contributed by
Keith Bauer.

llvm-svn: 39793
2007-07-13 03:05:23 +00:00
Anton Korobeynikov b6719478b9 Workaround gcc 3.4.x bug
llvm-svn: 39792
2007-07-13 00:48:55 +00:00
Steve Naroff 1c8b7d36e6 Two changes...
- Teach all the integer/float predicates on Type about Vectors.
- Disallow bitwise compliment on float vectors. For example...

typedef float __attribute__(( vector_size(16) )) float4;

float4 float4_return()
{
    float4 xx;

    return ~xx;
}

...now emits the following diagnostic...

[administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang bug.c
bug.c:8:12: error: invalid argument type to unary expression 'float4'
    return ~xx;
           ^
1 diagnostic generated.

llvm-svn: 39791
2007-07-12 21:46:55 +00:00
Steve Naroff 84ff4b44b0 Bug #:
Submitted by:
Reviewed by:
Typechecking support for vectors...

- Added CheckVectorOperands(). Called from CheckAdditionOperands,
CheckMultiplyDivideOperands, CheckSubstractionOperands, and CheckBitwiseOperands.
- Added diagnostic for converting vector values of different size.
- Modified Type::isArithmeticType to include vectors.

Sould be ready for Chris to add code generation. I will continue testing/refining.

llvm-svn: 39717
2007-07-09 21:31:10 +00:00
Steve Naroff 4ae0ac6a06 Bug #:
Submitted by:
Reviewed by:
- Finished semantic analysis for vectors, added some diagnostics.
- Added AST for vectors (instantiation, installation into the decl).
- Fixed bug in ParseArraySubscriptExpr()...this crasher was introduced by me
when we added the range support.
- Turned pedantic off by default. Since vectors are gcc extensions, having
pedantic on by default was annoying. Turning it off by default is  also
consistent with gcc (but this wasn't my primary motivation).
- Tweaked some comments and diagnostics.

Note: The type checking code is still under construction (for vectors). This
will be my next check-in.

llvm-svn: 39715
2007-07-06 23:09:18 +00:00
Chris Lattner c6395936ae Split complex types out from being members of BuiltinType to being their own
types.

llvm-svn: 39672
2007-06-22 20:56:16 +00:00