Skip to content

Commit 1ed5e04

Browse files
committed
Proposal: Add application hooks
One theme at DConf was the unification of the frontends. ("One frontend to rule them all") One source of differences in the frontend are compiler-specific extensions. An easy way to support this is the addition of hooks. An application may (or may not) use these hooks for additional processing. This hook was inspired by a current PR (ldc-developers/ldc#1434). LDC-specific pragmas could be realized with the same approach.
1 parent 51cd4d9 commit 1ed5e04

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/appl.d

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Compiler implementation of the D programming language
2+
// Copyright (c) 1999-2016 by Digital Mars
3+
// All Rights Reserved
4+
// written by Walter Bright
5+
// http://www.digitalmars.com
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// http://www.boost.org/LICENSE_1_0.txt
8+
9+
module ddmd.appl;
10+
11+
import ddmd.dscope;
12+
import ddmd.expression;
13+
14+
struct Hooks
15+
{
16+
Expression function(TraitsExp e, Scope* sc) semanticTraits;
17+
}
18+
19+
void setHooks(Hooks hooks)
20+
{
21+
.hooks = hooks;
22+
}
23+
24+
Expression semanticTraitsHook(TraitsExp e, Scope* sc)
25+
{
26+
if (hooks.semanticTraitsHook)
27+
return hooks.semanticTraits(e, sc);
28+
return null;
29+
}
30+
31+
package:
32+
33+
__gshared Hooks hooks;

src/posix.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ endif
197197
endif
198198

199199

200-
FRONT_SRCS=$(addsuffix .d,access aggregate aliasthis apply argtypes arrayop \
200+
FRONT_SRCS=$(addsuffix .d,access aggregate aliasthis appl apply argtypes arrayop \
201201
arraytypes attrib builtin canthrow clone complex cond constfold \
202202
cppmangle ctfeexpr dcast dclass declaration delegatize denum dimport \
203203
dinifile dinterpret dmacro dmangle dmodule doc dscope dstruct dsymbol \

src/traits.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import core.stdc.stdio;
1212
import core.stdc.string;
1313
import ddmd.aggregate;
1414
import ddmd.arraytypes;
15+
import ddmd.appl;
1516
import ddmd.canthrow;
1617
import ddmd.dclass;
1718
import ddmd.declaration;
@@ -1186,6 +1187,10 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
11861187
{
11871188
return pointerBitmap(e);
11881189
}
1190+
if (Expression ret = semanticTraitsHook(e, sc))
1191+
{
1192+
return ret;
1193+
}
11891194

11901195
extern (D) void* trait_search_fp(const(char)* seed, ref int cost)
11911196
{

src/win32.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ DMDMAKE=$(MAKE) -fwin32.mak C=$C TK=$(TK) ROOT=$(ROOT) MAKE="$(MAKE)" HOST_DC="$
141141
############################### Rule Variables ###############################
142142

143143
# D front end
144-
FRONT_SRCS=access.d aggregate.d aliasthis.d apply.d argtypes.d arrayop.d \
144+
FRONT_SRCS=access.d aggregate.d aliasthis.d appl.d apply.d argtypes.d arrayop.d \
145145
arraytypes.d attrib.d builtin.d canthrow.d clone.d complex.d \
146146
cond.d constfold.d cppmangle.d ctfeexpr.d dcast.d dclass.d \
147147
declaration.d delegatize.d denum.d dimport.d dinifile.d dinterpret.d \

0 commit comments

Comments
 (0)