8sa1-gcc/gcc/d/dmd/templateparamsem.c
Iain Buclaw 5a0aa603b2 d: Merge upstream dmd 3b808e838, druntime 483bc129, phobos f89dc217a
D front-end changes:

 - Explicit package visibility attribute is now always applied to
   introducing scopes.

 - Added `__traits(totype, string)' to convert mangled type string to an
   existing type.

 - Printf-like and scanf-like functions are now detected by prefixing
   them with `pragma(printf)' for printf-like functions or
   `pragma(scanf)' for scanf-like functions.

 - Added `__c_wchar_t', `__c_complex_float', `__c_complex_double', and
   `__c_complex_real' types for interfacing with C and C++.

 - Template alias parameters can now be instantiated with basic types,
   such as `int` or `void function()`.

 - Mixins can now be used as types in the form `mixin(string) var'.

 - Mixin expressions can take an argument list, same as `pragma(msg)'.

 - Implement DIP1034, add `typeof(*null)' types to represent `noreturn'.

 - `pragma(msg)' can print expressions of type `void'.

 - It is now an error to use private variables selectively imported from
   other modules.  Due to a bug, some imported private members were
   visible from other modules, violating the specification.

 - Added new syntax to declare an alias to a function type using the
   `alias' syntax based on the assignment operator.

 - Function literals can now return a value by reference.

Phobos changes:

 - Synchronize C bindings with the latest port fixes in upstream druntime.

 - Added alias for a `noreturn' type in object.d

 - Make use of the new `pragma(printf)' and `pragma(scanf)' pragmas, fix
   all code that got flagged as being incorrect.

 - Fixed code that relied on bugs in the D import package system.

Reviewed-on: https://github.com/dlang/dmd/pull/12339
	     https://github.com/dlang/druntime/pull/3422
	     https://github.com/dlang/phobos/pull/7932

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd 3b808e838.
	* Make-lang.in (D_FRONTEND_OBJS): Add d/chkformat.o.
	* d-codegen.cc (build_struct_literal): Handle special enums.
	* d-convert.cc (convert_expr): Handle noreturn type.
	(convert_for_condition): Likewise.
	* d-target.cc (Target::_init): Set type for wchar_t.
	(TargetCPP::derivedClassOffset): New method.
	(Target::libraryObjectMonitors): New method.
	* decl.cc (get_symbol_decl): Set TREE_THIS_VOLATILE for functions of
	type noreturn.
	* toir.cc (IRVisitor::visit (ReturnStatement *)): Handle returning
	noreturn types.
	* types.cc (TypeVisitor::visit (TypeNoreturn *)): New method.
	(TypeVisitor::visit (TypeEnum *)): Handle special enums.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime 483bc129.
	* libdruntime/Makefile.am (DRUNTIME_DSOURCES_DARWIN): Add
	core/sys/darwin/fcntl.d.
	(DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/unistd.d.
	(DRUNTIME_DSOURCES_WINDOWS): Add core/sys/windows/stdc/malloc.d.
	* libdruntime/Makefile.in: Regenerate.
	* src/MERGE: Merge upstream phobos f89dc217a.
	* src/Makefile.am (PHOBOS_DSOURCES): Add std/regex/internal/tests2.d.
	* src/Makefile.in: Regenerate.
	* testsuite/libphobos.exceptions/chain.d: Fix format arguments.
	* testsuite/libphobos.exceptions/line_trace.d: Likewise.
2021-04-04 01:26:20 +02:00

117 lines
3.4 KiB
C

/* Compiler implementation of the D programming language
* Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
* written by Walter Bright
* http://www.digitalmars.com
* Distributed under the Boost Software License, Version 1.0.
* http://www.boost.org/LICENSE_1_0.txt
*/
#include "template.h"
#include "mtype.h"
#include "scope.h"
#include "visitor.h"
bool reliesOnTident(Type *t, TemplateParameters *tparams = NULL, size_t iStart = 0);
class TemplateParameterSemanticVisitor : public Visitor
{
public:
Scope *sc;
TemplateParameters *parameters;
bool result;
TemplateParameterSemanticVisitor(Scope *sc, TemplateParameters *parameters)
{
this->sc = sc;
this->parameters = parameters;
this->result = false;
}
void visit(TemplateTypeParameter *ttp)
{
//printf("TemplateTypeParameter::semantic('%s')\n", ident->toChars());
if (ttp->specType && !reliesOnTident(ttp->specType, parameters))
{
ttp->specType = typeSemantic(ttp->specType, ttp->loc, sc);
}
result = !(ttp->specType && isError(ttp->specType));
}
void visit(TemplateValueParameter *tvp)
{
tvp->valType = typeSemantic(tvp->valType, tvp->loc, sc);
result = !isError(tvp->valType);
}
void visit(TemplateAliasParameter *tap)
{
if (tap->specType && !reliesOnTident(tap->specType, parameters))
{
tap->specType = typeSemantic(tap->specType, tap->loc, sc);
}
tap->specAlias = aliasParameterSemantic(tap->loc, sc, tap->specAlias, parameters);
result = !(tap->specType && isError(tap->specType)) &&
!(tap->specAlias && isError(tap->specAlias));
}
void visit(TemplateTupleParameter *)
{
result = true;
}
};
/************************************************
* Performs semantic on TemplateParameter AST nodes.
*
* Params:
* tp = element of `parameters` to be semantically analyzed
* sc = context
* parameters = array of `TemplateParameters` supplied to the `TemplateDeclaration`
* Returns:
* `true` if no errors
*/
bool tpsemantic(TemplateParameter *tp, Scope *sc, TemplateParameters *parameters)
{
TemplateParameterSemanticVisitor v(sc, parameters);
tp->accept(&v);
return v.result;
}
/***********************************************
* Support function for performing semantic analysis on `TemplateAliasParameter`.
*
* Params:
* loc = location (for error messages)
* sc = context
* o = object to run semantic() on, the `TemplateAliasParameter`s `specAlias` or `defaultAlias`
* parameters = array of `TemplateParameters` supplied to the `TemplateDeclaration`
* Returns:
* object resulting from running `semantic` on `o`
*/
RootObject *aliasParameterSemantic(Loc loc, Scope *sc, RootObject *o, TemplateParameters *parameters)
{
if (o)
{
Expression *ea = isExpression(o);
Type *ta = isType(o);
if (ta && (!parameters || !reliesOnTident(ta, parameters)))
{
Dsymbol *s = ta->toDsymbol(sc);
if (s)
o = s;
else
o = typeSemantic(ta, loc, sc);
}
else if (ea)
{
sc = sc->startCTFE();
ea = expressionSemantic(ea, sc);
sc = sc->endCTFE();
o = ea->ctfeInterpret();
}
}
return o;
}