Skip to content

Commit

Permalink
Make Array a templated struct, and merge with ArrayBase
Browse files Browse the repository at this point in the history
  • Loading branch information
yebblies committed May 20, 2013
1 parent deb6d26 commit 8bdbc66
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 321 deletions.
60 changes: 30 additions & 30 deletions src/arraytypes.h
Expand Up @@ -18,63 +18,63 @@

#include "root.h"

typedef ArrayBase<class TemplateParameter> TemplateParameters;
typedef Array<class TemplateParameter> TemplateParameters;

typedef ArrayBase<class Expression> Expressions;
typedef Array<class Expression> Expressions;

typedef ArrayBase<class Statement> Statements;
typedef Array<class Statement> Statements;

typedef ArrayBase<class BaseClass> BaseClasses;
typedef Array<class BaseClass> BaseClasses;

typedef ArrayBase<class ClassDeclaration> ClassDeclarations;
typedef Array<class ClassDeclaration> ClassDeclarations;

typedef ArrayBase<class Dsymbol> Dsymbols;
typedef Array<class Dsymbol> Dsymbols;

typedef ArrayBase<class Object> Objects;
typedef Array<class Object> Objects;

typedef ArrayBase<class FuncDeclaration> FuncDeclarations;
typedef Array<class FuncDeclaration> FuncDeclarations;

typedef ArrayBase<class Parameter> Parameters;
typedef Array<class Parameter> Parameters;

typedef ArrayBase<class Identifier> Identifiers;
typedef Array<class Identifier> Identifiers;

typedef ArrayBase<class Initializer> Initializers;
typedef Array<class Initializer> Initializers;

typedef ArrayBase<class VarDeclaration> VarDeclarations;
typedef Array<class VarDeclaration> VarDeclarations;

typedef ArrayBase<class Type> Types;
typedef Array<class Type> Types;

typedef ArrayBase<class ScopeDsymbol> ScopeDsymbols;
typedef Array<class ScopeDsymbol> ScopeDsymbols;

typedef ArrayBase<class Catch> Catches;
typedef Array<class Catch> Catches;

typedef ArrayBase<class StaticDtorDeclaration> StaticDtorDeclarations;
typedef Array<class StaticDtorDeclaration> StaticDtorDeclarations;

typedef ArrayBase<class SharedStaticDtorDeclaration> SharedStaticDtorDeclarations;
typedef Array<class SharedStaticDtorDeclaration> SharedStaticDtorDeclarations;

typedef ArrayBase<class AliasDeclaration> AliasDeclarations;
typedef Array<class AliasDeclaration> AliasDeclarations;

typedef ArrayBase<class Module> Modules;
typedef Array<class Module> Modules;

typedef ArrayBase<class File> Files;
typedef Array<class File> Files;

typedef ArrayBase<class CaseStatement> CaseStatements;
typedef Array<class CaseStatement> CaseStatements;

typedef ArrayBase<class CompoundStatement> CompoundStatements;
typedef Array<class CompoundStatement> CompoundStatements;

typedef ArrayBase<class GotoCaseStatement> GotoCaseStatements;
typedef Array<class GotoCaseStatement> GotoCaseStatements;

typedef ArrayBase<class ReturnStatement> ReturnStatements;
typedef Array<class ReturnStatement> ReturnStatements;

typedef ArrayBase<class TemplateInstance> TemplateInstances;
typedef Array<class TemplateInstance> TemplateInstances;

//typedef ArrayBase<char> Strings;
//typedef Array<char> Strings;

typedef ArrayBase<void> Voids;
typedef Array<void> Voids;

typedef ArrayBase<struct block> Blocks;
typedef Array<struct block> Blocks;

typedef ArrayBase<struct Symbol> Symbols;
typedef Array<struct Symbol> Symbols;

typedef ArrayBase<struct dt_t> Dts;
typedef Array<struct dt_t> Dts;
#endif
2 changes: 1 addition & 1 deletion src/doc.c
Expand Up @@ -70,7 +70,7 @@ class MacroSection : public Section
void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf);
};

typedef ArrayBase<Section> Sections;
typedef Array<Section> Sections;

struct DocComment
{
Expand Down
2 changes: 1 addition & 1 deletion src/e2ir.c
Expand Up @@ -45,7 +45,7 @@
static char __file__[] = __FILE__; /* for tassert.h */
#include "tassert.h"

typedef ArrayBase<elem> Elems;
typedef Array<elem> Elems;

elem *addressElem(elem *e, Type *t, bool alwaysCopy = false);
elem *eval_Darray(IRState *irs, Expression *e, bool alwaysCopy = false);
Expand Down
2 changes: 1 addition & 1 deletion src/glue.c
Expand Up @@ -44,7 +44,7 @@ elem *addressElem(elem *e, Type *t, bool alwaysCopy = false);

#define STATICCTOR 0

typedef ArrayBase<symbol> symbols;
typedef Array<symbol> symbols;

elem *eictor;
symbol *ictorlocalgot;
Expand Down
6 changes: 3 additions & 3 deletions src/interpret.c
Expand Up @@ -53,13 +53,13 @@ struct CtfeStack
the stack might not be empty when CTFE begins.
Ctfe Stack addresses are just 0-based integers, but we save
them as 'void *' because ArrayBase can only do pointers.
them as 'void *' because Array can only do pointers.
*/
Expressions values; // values on the stack
VarDeclarations vars; // corresponding variables
ArrayBase<void> savedId; // id of the previous state of that var
Array<void> savedId; // id of the previous state of that var

ArrayBase<void> frames; // all previous frame pointers
Array<void> frames; // all previous frame pointers
Expressions savedThis; // all previous values of localThis

/* Global constants get saved here after evaluation, so we never
Expand Down
4 changes: 2 additions & 2 deletions src/libelf.c
Expand Up @@ -35,8 +35,8 @@ struct ObjSymbol

#include "arraytypes.h"

typedef ArrayBase<ObjModule> ObjModules;
typedef ArrayBase<ObjSymbol> ObjSymbols;
typedef Array<ObjModule> ObjModules;
typedef Array<ObjSymbol> ObjSymbols;

class LibElf : public Library
{
Expand Down
4 changes: 2 additions & 2 deletions src/libmach.c
Expand Up @@ -45,8 +45,8 @@ struct ObjSymbol

#include "arraytypes.h"

typedef ArrayBase<ObjModule> ObjModules;
typedef ArrayBase<ObjSymbol> ObjSymbols;
typedef Array<ObjModule> ObjModules;
typedef Array<ObjSymbol> ObjSymbols;

class LibMach : public Library
{
Expand Down
4 changes: 2 additions & 2 deletions src/libmscoff.c
Expand Up @@ -54,8 +54,8 @@ int ObjSymbol_cmp(const void *p, const void *q)

#include "arraytypes.h"

typedef ArrayBase<ObjModule> ObjModules;
typedef ArrayBase<ObjSymbol> ObjSymbols;
typedef Array<ObjModule> ObjModules;
typedef Array<ObjSymbol> ObjSymbols;

class LibMSCoff : public Library
{
Expand Down
4 changes: 2 additions & 2 deletions src/libomf.c
Expand Up @@ -37,8 +37,8 @@ struct ObjSymbol

#include "arraytypes.h"

typedef ArrayBase<ObjModule> ObjModules;
typedef ArrayBase<ObjSymbol> ObjSymbols;
typedef Array<ObjModule> ObjModules;
typedef Array<ObjSymbol> ObjSymbols;

class LibOMF : public Library
{
Expand Down
6 changes: 3 additions & 3 deletions src/mars.h
Expand Up @@ -122,9 +122,9 @@ void unittests();
class OutBuffer;

// Can't include arraytypes.h here, need to declare these directly.
template <typename TYPE> struct ArrayBase;
typedef ArrayBase<class Identifier> Identifiers;
typedef ArrayBase<char> Strings;
template <typename TYPE> struct Array;
typedef Array<class Identifier> Identifiers;
typedef Array<char> Strings;

// Put command line switches in here
struct Param
Expand Down
7 changes: 2 additions & 5 deletions src/posix.mak
Expand Up @@ -74,7 +74,7 @@ CH= $C/cc.h $C/global.h $C/oper.h $C/code.h $C/type.h \
$C/dt.h $C/cgcv.h $C/el.h $C/obj.h $(TARGET_CH)

DMD_OBJS = \
access.o array.o attrib.o bcomplex.o blockopt.o \
access.o attrib.o bcomplex.o blockopt.o \
cast.o code.o cg.o cgcod.o cgcs.o cgelem.o cgen.o \
cgreg.o class.o cod5.o \
constfold.o irstate.o cond.o debug.o \
Expand Down Expand Up @@ -145,7 +145,7 @@ SRC = win32.mak posix.mak \
$C/ph2.c $C/util2.c \
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
$(ROOT)/root.h $(ROOT)/root.c $(ROOT)/array.c \
$(ROOT)/root.h $(ROOT)/root.c \
$(ROOT)/rmem.h $(ROOT)/rmem.c $(ROOT)/port.h $(ROOT)/port.c \
$(ROOT)/man.c \
$(ROOT)/stringtable.h $(ROOT)/stringtable.c \
Expand Down Expand Up @@ -235,9 +235,6 @@ apply.o: apply.c
argtypes.o: argtypes.c
$(CC) -c $(CFLAGS) $<

array.o: $(ROOT)/array.c
$(CC) -c $(GFLAGS) -I$(ROOT) $<

arrayop.o: arrayop.c
$(CC) -c $(CFLAGS) $<

Expand Down

12 comments on commit 8bdbc66

@WalterBright
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the point of this? Now all the array implementation code gets duplicated a dozen times in the executable.

@ibuclaw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit also breaks gdc build.

@yebblies
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. Any idea why?

@ibuclaw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root.h pulls in rmem.h - which has a few poisoned (by gcc) declarations in the header.
See this error:

In file included from ../../gcc-4.9-20131013/gcc/d/dfrontend/root.h:18:0,
                 from ../../gcc-4.9-20131013/gcc/d/dfrontend/arraytypes.h:19,
                 from ../../gcc-4.9-20131013/gcc/d/d-dmd-gcc.h:28,
                 from ../../gcc-4.9-20131013/gcc/d/d-lang.h:226,
                 from ../../gcc-4.9-20131013/gcc/d/d-lang.cc:27:
../../gcc-4.9-20131013/gcc/d/dfrontend/rmem.h:35:11: error: attempt to use poisoned "strdup"
     char *strdup(const char *s);
           ^
../../gcc-4.9-20131013/gcc/d/dfrontend/rmem.h:36:11: error: attempt to use poisoned "malloc"
     void *malloc(size_t size);
           ^
../../gcc-4.9-20131013/gcc/d/dfrontend/rmem.h:38:11: error: attempt to use poisoned "calloc"
     void *calloc(size_t size, size_t n);
           ^
../../gcc-4.9-20131013/gcc/d/dfrontend/rmem.h:39:11: error: attempt to use poisoned "realloc"
     void *realloc(void *p, size_t size);
           ^

Not easy to get around because the glue relies on arraytypes.h for various tidbits.

@yebblies
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yuck.

I can't think of anything other than rolling back or renaming. I'd really prefer not to roll back. I'm guessing there isn't a way to tell gcc to shut up?

@ibuclaw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no #unpoison directive, no. ;)

@yebblies
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be bypassed by always putting the frontend imports first? ie before the poisoning?

@ibuclaw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not circumvent identifiers that shouldn't be used in gcc. They really do insist that you use the 'x' versions from libiberty in frontends. They aren't too concerned about the D frontend part however, as it is isolated enough from the glue layer that talks with gcc... or at least was before this change.

@yebblies
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh. This rule doesn't seem to make sense for a frontend written in C++, only a C one. After all, these are member functions we're creating, and not overriding the free functions.

@ibuclaw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preprocessor doesn't see it that way. In any case, I'd rather rmem.h be left out of frontend headers and only be pulled in to the sources that require it. This keeps in line with ensuring the front-end implementation isolated from the glue except through the current interfaces in place.

@yebblies
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except the sources that need it are in the headers... I take it you want to roll this back?

@ibuclaw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can't see any other way I'm afraid. By the way - there are uses of malloc and free in Array::toChars should this instead be mem.malloc and mem.free ?

Please sign in to comment.