2 changes: 2 additions & 0 deletions src/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "dsymbol.h"
#include "declaration.h"
#include "objc.h"

class Identifier;
class Type;
Expand Down Expand Up @@ -266,6 +267,7 @@ class ClassDeclaration : public AggregateDeclaration
bool isabstract; // true if abstract class
int inuse; // to prevent recursive attempts
Baseok baseok; // set the progress of base classes resolving
Objc_ClassDeclaration objc;

ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses, bool inObject = false);
Dsymbol *syntaxCopy(Dsymbol *s);
Expand Down
2 changes: 1 addition & 1 deletion src/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ void UserAttributeDeclaration::semantic2(Scope *sc)
if (atts && atts->dim && scope)
{
scope = NULL;
arrayExpressionSemantic(atts, sc); // run semantic
arrayExpressionSemantic(atts, sc, true); // run semantic
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "expression.h"
#include "statement.h"
#include "template.h"
#include "objc.h"

/********************************* ClassDeclaration ****************************/

Expand Down Expand Up @@ -233,6 +234,7 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
isabstract = false;
inuse = 0;
baseok = BASEOKnone;
objc.objc = false;
}

Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s)
Expand Down Expand Up @@ -320,6 +322,8 @@ void ClassDeclaration::semantic(Scope *sc)

if (sc->linkage == LINKcpp)
cpp = true;
if (sc->linkage == LINKobjc)
objc_ClassDeclaration_semantic_PASSinit_LINKobjc(this);
}
else if (symtab && !scx)
{
Expand Down Expand Up @@ -1383,6 +1387,7 @@ void InterfaceDeclaration::semantic(Scope *sc)

if (!baseclasses->dim && sc->linkage == LINKcpp)
cpp = true;
objc_InterfaceDeclaration_semantic_objcExtern(this, sc);

// Check for errors, handle forward references
for (size_t i = 0; i < baseclasses->dim; )
Expand Down Expand Up @@ -1551,6 +1556,8 @@ void InterfaceDeclaration::semantic(Scope *sc)
sc2->linkage = LINKwindows;
else if (cpp)
sc2->linkage = LINKcpp;
else if (this->objc.isInterface())
sc->linkage = LINKobjc;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
Expand Down
2 changes: 2 additions & 0 deletions src/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "dsymbol.h"
#include "mtype.h"
#include "objc.h"

class Expression;
class Statement;
Expand Down Expand Up @@ -526,6 +527,7 @@ class FuncDeclaration : public Declaration
// scopes from having the same name
VarDeclaration *vthis; // 'this' parameter (member and nested)
VarDeclaration *v_arguments; // '_arguments' parameter
Objc_FuncDeclaration objc;
#ifdef IN_GCC
VarDeclaration *v_argptr; // '_argptr' variable
#endif
Expand Down
16 changes: 14 additions & 2 deletions src/e2ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ void genTypeInfo(Type *t, Scope *sc);
int callSideEffectLevel(FuncDeclaration *f);
int callSideEffectLevel(Type *t);

void objc_callfunc_setupMethodSelector(Type *tret, FuncDeclaration *fd, Type *t, elem *ehidden, elem **esel);
void objc_callfunc_setupMethodCall(elem **ec, elem *ehidden, elem *ethis, TypeFunction *tf);
void objc_callfunc_setupEp(elem *esel, elem **ep, int reverse);

#define el_setLoc(e,loc) ((e)->Esrcpos.Sfilename = (char *)(loc).filename, \
(e)->Esrcpos.Slinnum = (loc).linnum, \
(e)->Esrcpos.Scharnum = (loc).charnum)
Expand Down Expand Up @@ -121,7 +125,8 @@ elem *callfunc(Loc loc,
FuncDeclaration *fd, // if !=NULL, this is the function being called
Type *t, // TypeDelegate or TypeFunction for this function
elem *ehidden, // if !=NULL, this is the 'hidden' argument
Expressions *arguments)
Expressions *arguments,
elem *esel = NULL) // selector for Objective-C methods (when not provided by fd)
{
elem *ep;
elem *e;
Expand Down Expand Up @@ -235,6 +240,9 @@ elem *callfunc(Loc loc,
}
}

objc_callfunc_setupMethodSelector(tret, fd, t, ehidden, &esel);
objc_callfunc_setupEp(esel, &ep, reverse);

if (retmethod == RETstack)
{
if (!ehidden)
Expand Down Expand Up @@ -294,7 +302,11 @@ elem *callfunc(Loc loc,
}
Symbol *sfunc = toSymbol(fd);

if (!fd->isVirtual() ||
if (esel)
{
objc_callfunc_setupMethodCall(&ec, ehidden, ethis, tf);
}
else if (!fd->isVirtual() ||
directcall || // BUG: fix
fd->isFinalFunc()
/* Future optimization: || (whole program analysis && not overridden)
Expand Down
4 changes: 2 additions & 2 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ Expression *resolveUFCSProperties(Scope *sc, Expression *e1, Expression *e2 = NU
* Perform semantic() on an array of Expressions.
*/

bool arrayExpressionSemantic(Expressions *exps, Scope *sc)
bool arrayExpressionSemantic(Expressions *exps, Scope *sc, bool preserveErrors)
{
bool err = false;
if (exps)
Expand All @@ -949,7 +949,7 @@ bool arrayExpressionSemantic(Expressions *exps, Scope *sc)
e = e->semantic(sc);
if (e->op == TOKerror)
err = true;
else
if (preserveErrors || e->op != TOKerror)
(*exps)[i] = e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TupleDeclaration *isAliasThisTuple(Expression *e);
int expandAliasThisTuples(Expressions *exps, size_t starti = 0);
FuncDeclaration *hasThis(Scope *sc);
Expression *fromConstInitializer(int result, Expression *e);
bool arrayExpressionSemantic(Expressions *exps, Scope *sc);
bool arrayExpressionSemantic(Expressions *exps, Scope *sc, bool preserveErrors = false);
TemplateDeclaration *getFuncTemplateDecl(Dsymbol *s);
Expression *valueNoDtor(Expression *e);
int modifyFieldVar(Loc loc, Scope *sc, VarDeclaration *var, Expression *e1);
Expand Down
14 changes: 14 additions & 0 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "parse.h"
#include "rmem.h"
#include "visitor.h"
#include "objc.h"

Expression *addInvariant(Loc loc, Scope *sc, AggregateDeclaration *ad, VarDeclaration *vthis, bool direct);

Expand Down Expand Up @@ -273,6 +274,7 @@ class NrvoWalker : public StatementRewriteWalker
FuncDeclaration::FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageClass storage_class, Type *type)
: Declaration(id)
{
objc = Objc_FuncDeclaration(this);
//printf("FuncDeclaration(id = '%s', type = %p)\n", id->toChars(), type);
//printf("storage_class = x%x\n", storage_class);
this->storage_class = storage_class;
Expand Down Expand Up @@ -1218,6 +1220,18 @@ void FuncDeclaration::semantic(Scope *sc)

void FuncDeclaration::semantic2(Scope *sc)
{
if (semanticRun >= PASSsemantic2done)
return;
assert(semanticRun <= PASSsemantic2);
semanticRun = PASSsemantic2;

objc_FuncDeclaration_semantic_setSelector(this, sc);
objc_FuncDeclaration_semantic_validateSelector(this);

if (ClassDeclaration *cd = parent->isClassDeclaration())
{
objc_FuncDeclaration_semantic_checkLinkage(this);
}
}

// Do the semantic analysis on the internals of the function.
Expand Down
1 change: 1 addition & 0 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ enum LINK
LINKcpp,
LINKwindows,
LINKpascal,
LINKobjc,
};

enum DYNCAST
Expand Down
1 change: 1 addition & 0 deletions src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ unsigned totym(Type *tx)

case LINKc:
case LINKcpp:
case LINKobjc:
Lc:
t = TYnfunc;
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
Expand Down
2 changes: 2 additions & 0 deletions src/hdrgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ class PrettyPrintVisitor : public Visitor
case LINKcpp: p = "C++"; break;
case LINKwindows: p = "Windows"; break;
case LINKpascal: p = "Pascal"; break;
case LINKobjc: p = "Objective-C"; break;
default:
assert(0);
break;
Expand Down Expand Up @@ -3177,6 +3178,7 @@ const char *linkageToChars(LINK linkage)
case LINKcpp: return "C++";
case LINKwindows: return "Windows";
case LINKpascal: return "Pascal";
case LINKobjc: return "Objective-C";
default: assert(0);
}
return NULL; // never reached
Expand Down
5 changes: 5 additions & 0 deletions src/idgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Msgtable[] msgtable =
{ "Windows" },
{ "Pascal" },
{ "System" },
{ "Objective" },

{ "exit" },
{ "success" },
Expand Down Expand Up @@ -294,6 +295,7 @@ Msgtable[] msgtable =
// Builtin functions
{ "std" },
{ "core" },
{ "attribute" },
{ "math" },
{ "sin" },
{ "cos" },
Expand Down Expand Up @@ -362,6 +364,9 @@ Msgtable[] msgtable =
{ "basic_ostream" },
{ "basic_iostream" },
{ "char_traits" },

// Compiler recognized UDA's
{ "udaSelector", "selector" },
];


Expand Down
41 changes: 41 additions & 0 deletions src/magicport.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"tokens.c", "tokens.h",
"globals.c", "globals.h",
"escape.c",
"objc.c", "objc.h",
"root/aav.h", "root/aav.c",
"root/filename.h", "root/filename.c",
"root/file.h", "root/file.c",
Expand Down Expand Up @@ -109,6 +110,43 @@
"function setValue"
]
},
{
"module" : "objc",
"package" : "",
"imports" : [
"arraytypes",
"cond",
"dclass",
"dmangle",
"dmodule",
"dscope",
"dstruct",
"expression",
"func",
"globals",
"id",
"identifier",
"mtype",
"root.outbuffer",
"root.stringtable"
],
"members" : [
"struct ObjcSelector",
"struct Objc_ClassDeclaration",
"struct Objc_FuncDeclaration",
"function objc_ClassDeclaration_semantic_PASSinit_LINKobjc",
"function objc_InterfaceDeclaration_semantic_objcExtern",
"function objc_FuncDeclaration_semantic_setSelector",
"function objc_isUdaSelector",
"function objc_FuncDeclaration_semantic_validateSelector",
"function objc_FuncDeclaration_semantic_checkLinkage",
"function objc_tryMain_dObjc",
"function objc_tryMain_init"
],
"extra" : [
"extern(C++) void objc_initSymbols();"
]
},
{
"module" : "dclass",
"package" : "",
Expand All @@ -132,6 +170,7 @@
"identifier",
"globals",
"mtype",
"objc",
"root.outbuffer",
"root.rmem",
"root.rootobject",
Expand Down Expand Up @@ -1443,6 +1482,7 @@
"globals",
"mtype",
"nogc",
"objc",
"opover",
"root.filename",
"root.outbuffer",
Expand Down Expand Up @@ -2519,6 +2559,7 @@
"lib",
"link",
"mtype",
"objc",
"parse",
"root.file",
"root.filename",
Expand Down
2 changes: 1 addition & 1 deletion src/magicport/typenames.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ bool lookup(bool[string] aa, string n)
return p !is null;
}

auto dropdefaultctor = ["Loc", "Token", "HdrGenState", "CtfeStack", "InterState", "BaseClass", "Mem", "StringValue", "OutBuffer", "Scope", "DocComment", "PrefixAttributes", "Prot", "UnionExp"];
auto dropdefaultctor = ["Loc", "Token", "HdrGenState", "CtfeStack", "InterState", "BaseClass", "Mem", "StringValue", "OutBuffer", "Scope", "DocComment", "PrefixAttributes", "Prot", "UnionExp", "Objc_FuncDeclaration"];
2 changes: 2 additions & 0 deletions src/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class Mangler : public Visitor
case LINKwindows: mc = 'W'; break;
case LINKpascal: mc = 'V'; break;
case LINKcpp: mc = 'R'; break;
case LINKobjc: mc = 'Y'; break;
default:
assert(0);
}
Expand Down Expand Up @@ -414,6 +415,7 @@ class Mangler : public Visitor
case LINKc:
case LINKwindows:
case LINKpascal:
case LINKobjc:
buf->writestring(d->ident->toChars());
return;

Expand Down
3 changes: 3 additions & 0 deletions src/mars.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "declaration.h"
#include "hdrgen.h"
#include "doc.h"
#include "objc.h"

bool response_expand(Strings *arguments);

Expand Down Expand Up @@ -1193,6 +1194,7 @@ Language changes listed by -transition=id:\n\
VersionCondition::addPredefinedGlobalIdent("D_NoBoundsChecks");

VersionCondition::addPredefinedGlobalIdent("D_HardFloat");
objc_tryMain_dObjc();

// Initialization
Lexer::initLexer();
Expand All @@ -1201,6 +1203,7 @@ Language changes listed by -transition=id:\n\
Module::init();
Target::init();
Expression::init();
objc_tryMain_init();
initPrecedence();
builtin_init();
initTraitsStringTable();
Expand Down
5 changes: 5 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,11 @@ bool Module::rootImports()
return rootimports == 2;
}

bool Module::isCoreModule(Identifier *ident)
{
return this->ident == ident && parent && parent->ident == Id::core && !parent->parent;
}

/* =========================== ModuleDeclaration ===================== */

ModuleDeclaration::ModuleDeclaration(Loc loc, Identifiers *packages, Identifier *id)
Expand Down
1 change: 1 addition & 0 deletions src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Module : public Package
bool isRoot() { return this->importedFrom == this; }
// true if the module source file is directly
// listed in command line.
bool isCoreModule(Identifier *ident);

// Back end

Expand Down
Loading