Skip to content

Instantly share code, notes, and snippets.

@rikkimax
Created February 23, 2024 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikkimax/ca6588f119397bcd1f4939c328e1f006 to your computer and use it in GitHub Desktop.
Save rikkimax/ca6588f119397bcd1f4939c328e1f006 to your computer and use it in GitHub Desktop.
Minified TODO dmd AST modules for what parser requires to compile
/**
* Defines declarations of various attributes.
*
* The term 'attribute' refers to things that can apply to a larger scope than a single declaration.
* Among them are:
* - Alignment (`align(8)`)
* - User defined attributes (`@UDA`)
* - Function Attributes (`@safe`)
* - Storage classes (`static`, `__gshared`)
* - Mixin declarations (`mixin("int x;")`)
* - Conditional compilation (`static if`, `static foreach`)
* - Linkage (`extern(C)`)
* - Anonymous structs / unions
* - Protection (`private`, `public`)
* - Deprecated declarations (`@deprecated`)
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/attrib.d, _attrib.d)
* Documentation: https://dlang.org/phobos/dmd_attrib.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/attrib.d
*/
module dmd.attrib;
import dmd.arraytypes;
import dmd.astenums;
import dmd.cond;
import dmd.dsymbol;
import dmd.expression;
import dmd.identifier;
import dmd.location;
class AttribDeclaration : Dsymbol
{
Dsymbols* decl; /// Dsymbol's affected by this AttribDeclaration
}
class StorageClassDeclaration : AttribDeclaration
{
this(StorageClass , Dsymbols* ) {
}
this(Loc , StorageClass , Dsymbols* ) {
}
}
class DeprecatedDeclaration : StorageClassDeclaration
{
this(Expression , Dsymbols* ) {
super(STC.deprecated_, decl);
}
}
class LinkDeclaration : AttribDeclaration
{
this(Loc , LINK , Dsymbols* ) {
}
}
class CPPMangleDeclaration : AttribDeclaration
{
this(Loc , CPPMANGLE , Dsymbols* ) {
}
}
class CPPNamespaceDeclaration : AttribDeclaration
{
this(Loc , Expression , Dsymbols* ) {
}
}
class VisibilityDeclaration : AttribDeclaration
{
this(Loc , Visibility , Dsymbols* ) {
//printf("decl = %p\n", decl);
}
this(Loc , Identifier[] , Dsymbols* )
{
}
}
class AlignDeclaration : AttribDeclaration
{
this(Loc , Expression , Dsymbols* )
{
}
}
class AnonDeclaration : AttribDeclaration
{
this(Loc , bool , Dsymbols* ) {
}
}
class PragmaDeclaration : AttribDeclaration
{
this(Loc , Identifier , Expressions* , Dsymbols* ) {
}
}
class ConditionalDeclaration : AttribDeclaration
{
Condition condition; /// condition deciding whether decl or elsedecl applies
Dsymbols* elsedecl; /// array of Dsymbol's for else block
this(Loc , Condition , Dsymbols* , Dsymbols* ) {
}
}
class StaticIfDeclaration : ConditionalDeclaration
{
this(Loc , Condition , Dsymbols* , Dsymbols* ) {
super(loc, condition, decl, elsedecl);
//printf("StaticIfDeclaration::StaticIfDeclaration()\n");
}
}
class StaticForeachDeclaration : AttribDeclaration
{
this(StaticForeach , Dsymbols* ) {
}
}
class ForwardingAttribDeclaration {
}
class MixinDeclaration : AttribDeclaration
{
this(Loc , Expressions* ) {
}
}
class UserAttributeDeclaration : AttribDeclaration
{
this(Expressions* , Dsymbols* ) {
}
static Expressions* concat(Expressions* , Expressions* )
{
Expressions* udas;
return udas;
}
}
dmd -c -IP:\dmd_parser\imports -J. -Jres P:\dmd_parser\src\dmd\iasmgcc.d thefiles.d
/// Utility program to write out file size changes ``$ rdmd checksize.d test "*.d"``
import std.file;
import std.stdio : writeln, writefln;
import std.path;
void main(string[] args) {
ulong[string] files;
args[1] = absolutePath(args[1]);
foreach(entry; dirEntries(args[1], args[2], SpanMode.breadth)) {
if (!isFile(entry.name))
continue;
string nowAs = relativePath(entry.name, args[1]);
files[nowAs] = getSize(entry.name);
}
writefln!"%16s%12s%12s%12s"("file", "delta", "was size", "now");
foreach(file, oldSize; files) {
string reduced = args[1] ~ ".reduced/" ~ file;
if (!(exists(reduced) && isFile(reduced)))
continue;
ulong newSize = getSize(reduced);
if (oldSize != newSize) {
writefln!"%16s%12s%12s%12s"(file, cast(long)newSize - cast(long)oldSize, oldSize, newSize);
}
}
}
/**
* Evaluate compile-time conditionals, such as `static if` `version` and `debug`.
*
* Specification: $(LINK2 https://dlang.org/spec/version.html, Conditional Compilation)
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/cond.d, _cond.d)
* Documentation: https://dlang.org/phobos/dmd_cond.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/cond.d
*/
module dmd.cond;
import dmd.arraytypes;
import dmd.ast_node;
import dmd.dmodule;
import dmd.expression;
import dmd.identifier;
import dmd.location;
import dmd.visitor;
import dmd.statement;
extern (C++) class Condition : ASTNode
{
Loc loc;
this(Loc ) {
}
override void accept(Visitor )
{
}
}
class StaticForeach {
this(Loc , ForeachStatement , ForeachRangeStatement ) {
}
}
class DVCondition : Condition
{
uint level;
Identifier ident;
Module mod;
this(Loc , Module , uint , Identifier ) {
super(loc);
}
}
class DebugCondition : DVCondition
{
this(Loc , Module , uint , Identifier ) {
super(loc, mod, level, ident);
}
}
class VersionCondition : DVCondition
{
this(Loc , Module , uint , Identifier ) {
super(loc, mod, level, ident);
}
}
class StaticIfCondition : Condition
{
this(Loc , Expression ) {
super(loc);
}
}
/****************************************
* Find `ident` in an array of identifiers.
* Params:
* ids = array of identifiers
* ident = identifier to search for
* Returns:
* true if found
*/
bool findCondition(Identifiers , Identifier ) {
return false;
}
/**
* Defines a `class` declaration.
*
* Specification: $(LINK2 https://dlang.org/spec/class.html, Classes)
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dclass.d, _dclass.d)
* Documentation: https://dlang.org/phobos/dmd_dclass.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dclass.d
*/
module dmd.dclass;
import dmd.aggregate;
import dmd.arraytypes;
import dmd.identifier;
import dmd.location;
import dmd.mtype;
struct BaseClass
{
Type type; // (before semantic processing)
}
/***********************************************************
*/
extern (C++) class ClassDeclaration : AggregateDeclaration
{
// Array of BaseClass's; first is super, rest are Interface's
BaseClasses* baseclasses;
this(Loc , Identifier id, BaseClasses* , Dsymbols* , bool )
{
super(loc, id);
}
override void finalizeSize()
{
}
}
class InterfaceDeclaration : ClassDeclaration
{
this(Loc , Identifier id, BaseClasses* )
{
super(loc, id, baseclasses, null, false);
}
}
/**
* Miscellaneous declarations, including typedef, alias, variable declarations including the
* implicit this declaration, type tuples, ClassInfo, ModuleInfo and various TypeInfos.
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/declaration.d, _declaration.d)
* Documentation: https://dlang.org/phobos/dmd_declaration.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/declaration.d
*/
module dmd.declaration;
import core.stdc.stdio;
import dmd.astenums;
import dmd.dsymbol;
import dmd.expression;
import dmd.id;
import dmd.identifier;
import dmd.init;
import dmd.location;
import dmd.mtype;
/* Accumulator for successive matches.
*/
struct MatchAccumulator
{
}
/***********************************************************
*/
extern (C++) class Declaration : Dsymbol
{
Type type;
StorageClass storage_class ;
this(Identifier ) {
}
bool isCodeseg() {
return false;
}
bool isAbstract()
{
return storage_class != 0;
}
}
class TupleDeclaration : Declaration
{
this() {
super(ident);
}
}
class AliasDeclaration : Declaration
{
this(Loc , Identifier , Type ) {
super(ident);
}
this(Loc , Identifier , Dsymbol ) {
super(ident);
}
}
class OverDeclaration : Declaration
{
this() {
super(ident);
}
}
class VarDeclaration : Declaration
{
this(Loc , Type , Identifier , Initializer , StorageClass = STC.undefined_)
{
//printf("VarDeclaration('%s')\n", ident.toChars());
super(ident);
}
}
class BitFieldDeclaration : VarDeclaration
{
this(Loc , Type , Identifier , Expression )
{
super(loc, type, ident, null);
}
}
class SymbolDeclaration : Declaration
{
this() {
super(ident);
}
}
Identifier getTypeInfoIdent(Type )
{
import core.stdc.stdlib;
import dmd.root.rmem;
// Allocate buffer on stack, fail over to using malloc()
char[] namebuf;
const namelen = 19 ;
auto name = namelen ? namebuf.ptr : cast(char*)Mem.check(malloc(namelen));
const length = snprintf(name, namelen, "_D%lluTypeInfo_%.*s6__initZ");
auto id = Identifier.idPool(name[0 .. length]);
return id;
}
class TypeInfoDeclaration : VarDeclaration
{
Type tinfo;
this(Type )
{
super(Loc.initial, Type.dtypeinfo.type, tinfo.getTypeInfoIdent, null);
}
}
class TypeInfoStructDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoClassDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoInterfaceDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoPointerDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoArrayDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoStaticArrayDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoEnumDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoFunctionDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoDelegateDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoTupleDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoConstDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoInvariantDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoSharedDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoWildDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class TypeInfoVectorDeclaration : TypeInfoDeclaration
{
this()
{
super(tinfo);
}
}
class ThisDeclaration : VarDeclaration
{
this(Type t)
{
super(loc, t, Id.This, null);
}
}
/**
* Define `enum` declarations and `enum` members.
*
* Specification: $(LINK2 https://dlang.org/spec/enum.html, Enums)
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/denum.d, _denum.d)
* Documentation: https://dlang.org/phobos/dmd_denum.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/denum.d
* References: https://dlang.org/spec/enum.html
*/
module dmd.denum;
import dmd.astenums;
import dmd.attrib;
import dmd.declaration;
import dmd.dsymbol;
import dmd.expression;
import dmd.identifier;
import dmd.init;
import dmd.location;
import dmd.mtype;
class EnumDeclaration : ScopeDsymbol
{
this(Loc , Identifier , Type )
{
}
}
class EnumMember : VarDeclaration
{
this(Loc , Identifier id, Expression value, Type )
{
super(loc, null, id , new ExpInitializer(loc, value));
}
this(Loc , Identifier id, Expression value, Type memtype,
StorageClass , UserAttributeDeclaration , DeprecatedDeclaration )
{
this(loc, id, value, memtype);
}
}
/**
* A `Dsymbol` representing a renamed import.
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dimport.d, _dimport.d)
* Documentation: https://dlang.org/phobos/dmd_dimport.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dimport.d
*/
module dmd.dimport;
import dmd.dsymbol;
import dmd.identifier;
import dmd.location;
class Import : Dsymbol
{
this(Loc , Identifier[] , Identifier , Identifier , int )
{
}
void addAlias(Identifier , Identifier )
{
}
}
/**
* Defines a package and module.
*
* Specification: $(LINK2 https://dlang.org/spec/module.html, Modules)
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dmodule.d, _dmodule.d)
* Documentation: https://dlang.org/phobos/dmd_dmodule.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dmodule.d
*/
module dmd.dmodule;
import dmd.dsymbol;
import dmd.expression;
import dmd.identifier;
import dmd.location;
import dmd.root.filename;
class Package : ScopeDsymbol
{
this(Loc , Identifier ) {
}
}
class Module : Package
{
__gshared Module rootModule;
FileName srcfile; // input source file
this()
{
super(loc, ident);
}
bool isRoot() {
return this== this;
}
}
struct ModuleDeclaration
{
Identifier id;
Identifier[] packages; // array of Identifier's representing packages
this(Loc , Identifier[] , Identifier , Expression , bool ) {
}
}
/**
* Struct and union declarations.
*
* Specification: $(LINK2 https://dlang.org/spec/struct.html, Structs, Unions)
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dstruct.d, _dstruct.d)
* Documentation: https://dlang.org/phobos/dmd_dstruct.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dstruct.d
*/
module dmd.dstruct;
import dmd.aggregate;
import dmd.identifier;
import dmd.location;
/***********************************************************
* All `struct` declarations are an instance of this.
*/
extern (C++) class StructDeclaration : AggregateDeclaration
{
this(Loc , Identifier id, bool )
{
super(loc, id);
}
override void finalizeSize()
{
}
}
class UnionDeclaration : StructDeclaration
{
this(Loc , Identifier id)
{
super(loc, id, false);
}
}
/**
* The base class for a D symbol, which can be a module, variable, function, enum, etc.
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dsymbol.d, _dsymbol.d)
* Documentation: https://dlang.org/phobos/dmd_dsymbol.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dsymbol.d
*/
module dmd.dsymbol;
import dmd.aggregate;
import dmd.arraytypes;
import dmd.attrib;
import dmd.ast_node;
import dmd.dclass;
import dmd.declaration;
import dmd.denum;
import dmd.dimport;
import dmd.dmodule;
import dmd.dversion;
import dmd.dstruct;
import dmd.dtemplate;
import dmd.expression;
import dmd.func;
import dmd.globals;
import dmd.identifier;
import dmd.location;
import dmd.mtype;
import dmd.nspace;
import dmd.statement;
import dmd.staticassert;
import dmd.visitor;
import dmd.common.outbuffer;
struct Visibility
{
///
enum Kind {
undefined,
private_,
package_,
protected_,
public_,
export_,
}
Kind kind;
}
// Search options
alias SearchOptFlags = uint;
enum SearchOpt {
all }
/***********************************************************
* Struct/Class/Union field state.
* Used for transitory information when setting field offsets, such
* as bit fields.
*/
struct FieldState
{
}
struct DsymbolAttributes
{
/// user defined attributes
UserAttributeDeclaration userAttribDecl;
}
/***********************************************************
*/
extern (C++) class Dsymbol : ASTNode
{
Identifier ident;
Loc loc; // where defined
DsymbolAttributes* atts; /// attached attribute declarations
DsymbolAttributes getAtts()
{
return *atts;
}
UserAttributeDeclaration userAttribDecl(UserAttributeDeclaration )
{
return getAtts.userAttribDecl ;
}
// helper to print fully qualified (template) arguments
const(char)* toPrettyCharsHelper()
{
return toChars;
}
Identifier getIdent()
{
return ident;
}
const(char)* toPrettyChars(bool = false)
{
OutBuffer buf;
auto s = buf.extractSlice.ptr;
return s;
}
const(char)* kind() {
return "symbol";
}
/*********************************
* If this symbol is really an alias for another,
* return that other.
* If needed, semantic() is invoked due to resolve forward reference.
*/
Dsymbol toAlias()
{
return this;
}
/*********************************
* Resolve recursive tuple expansion in eponymous template.
*/
Dsymbol toAlias2()
{
return toAlias;
}
bool overloadInsert(Dsymbol )
{
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
return false;
}
/*********************************
* Returns:
* SIZE_INVALID when the size cannot be determined
*/
uinteger_t size(ref Loc )
{
return SIZE_INVALID;
}
// is a 'this' required to access the member
inout(AggregateDeclaration) isThis() inout
{
return null;
}
// is Dsymbol exported?
bool isExport() {
return false;
}
// is Dsymbol imported?
bool isImportedSymbol() {
return false;
}
// is Dsymbol deprecated?
bool isDeprecated() {
return false;
}
bool isOverloadable() {
return false;
}
// is this a LabelDsymbol()?
LabelDsymbol isLabel()
{
return null;
}
// is this a type?
Type getType()
{
return null;
}
// need a 'this' pointer?
bool needThis()
{
return false;
}
/*************************************
*/
Visibility visible() {
return Visibility();
}
/**************************************
* Copy the syntax.
* Used for template instantiations.
* If s is NULL, allocate the new object, otherwise fill it in.
*/
Dsymbol syntaxCopy(Dsymbol )
{
assert(0);
}
/**************************************
* Determine if this symbol is only one.
* Returns:
* false, ps = null: There are 2 or more symbols
* true, ps = null: There are zero symbols
* true, ps = symbol: The one and only one symbol
*/
bool oneMember(out Dsymbol , Identifier )
{
return true;
}
/*****************************************
* Is Dsymbol a variable that contains pointers?
*/
bool hasPointers()
{
//printf("Dsymbol::hasPointers() %s\n", toChars());
return false;
}
bool hasStaticCtorOrDtor()
{
//printf("Dsymbol::hasStaticCtorOrDtor() %s\n", toChars());
return false;
}
void addObjcSymbols(ClassDeclarations* , ClassDeclarations* )
{
}
void checkCtorConstInit()
{
}
/****************************************
* Add documentation comment to Dsymbol.
* Ignore NULL comments.
*/
void addComment(const(char)* )
{
}
/**********************************
* Set ddoc unittest associated with this symbol.
*/
final ddocUnittest(UnitTestDeclaration )
{
}
/************
*/
override void accept(Visitor )
{
}
// Eliminate need for dynamic_cast
inout(Package) isPackage() inout { return null; }
inout(Module) isModule() inout { return null; }
inout(EnumMember) isEnumMember() inout { return null; }
inout(TemplateDeclaration) isTemplateDeclaration() inout { return null; }
inout(TemplateInstance) isTemplateInstance() inout { return null; }
inout(TemplateMixin) isTemplateMixin() inout { return null; }
inout(ForwardingAttribDeclaration) isForwardingAttribDeclaration() inout { return null; }
inout(Nspace) isNspace() inout { return null; }
inout(Declaration) isDeclaration() inout { return null; }
inout(StorageClassDeclaration) isStorageClassDeclaration() inout { return null; }
inout(ThisDeclaration) isThisDeclaration() inout { return null; }
inout(BitFieldDeclaration) isBitFieldDeclaration() inout { return null; }
inout(TypeInfoDeclaration) isTypeInfoDeclaration() inout { return null; }
inout(TupleDeclaration) isTupleDeclaration() inout { return null; }
inout(AliasDeclaration) isAliasDeclaration() inout { return null; }
inout(AggregateDeclaration) isAggregateDeclaration() inout { return null; }
inout(FuncDeclaration) isFuncDeclaration() inout { return null; }
inout(FuncAliasDeclaration) isFuncAliasDeclaration() inout { return null; }
inout(OverDeclaration) isOverDeclaration() inout { return null; }
inout(FuncLiteralDeclaration) isFuncLiteralDeclaration() inout { return null; }
inout(CtorDeclaration) isCtorDeclaration() inout { return null; }
inout(PostBlitDeclaration) isPostBlitDeclaration() inout { return null; }
inout(DtorDeclaration) isDtorDeclaration() inout { return null; }
inout(StaticCtorDeclaration) isStaticCtorDeclaration() inout { return null; }
inout(StaticDtorDeclaration) isStaticDtorDeclaration() inout { return null; }
inout(SharedStaticCtorDeclaration) isSharedStaticCtorDeclaration() inout { return null; }
inout(SharedStaticDtorDeclaration) isSharedStaticDtorDeclaration() inout { return null; }
inout(InvariantDeclaration) isInvariantDeclaration() inout { return null; }
inout(UnitTestDeclaration) isUnitTestDeclaration() inout { return null; }
inout(NewDeclaration) isNewDeclaration() inout { return null; }
inout(VarDeclaration) isVarDeclaration() inout { return null; }
inout(VersionSymbol) isVersionSymbol() inout { return null; }
inout(DebugSymbol) isDebugSymbol() inout { return null; }
inout(ClassDeclaration) isClassDeclaration() inout { return null; }
inout(StructDeclaration) isStructDeclaration() inout { return null; }
inout(UnionDeclaration) isUnionDeclaration() inout { return null; }
inout(InterfaceDeclaration) isInterfaceDeclaration() inout { return null; }
inout(Import) isImport() inout { return null; }
inout(EnumDeclaration) isEnumDeclaration() inout { return null; }
inout(SymbolDeclaration) isSymbolDeclaration() inout { return null; }
inout(AttribDeclaration) isAttribDeclaration() inout { return null; }
inout(AnonDeclaration) isAnonDeclaration() inout { return null; }
inout(CPPNamespaceDeclaration) isCPPNamespaceDeclaration() inout { return null; }
inout(VisibilityDeclaration) isVisibilityDeclaration() inout { return null; }
inout(MixinDeclaration) isMixinDeclaration() inout { return null; }
inout(StaticAssert) isStaticAssert() inout { return null; }
inout(StaticIfDeclaration) isStaticIfDeclaration() inout { return null; }
}
/***********************************************************
* Dsymbol that generates a scope
*/
extern (C++) class ScopeDsymbol : Dsymbol
{
Dsymbols* members; // all Dsymbol's in this scope
DsymbolTable symtab; // members[] sorted into table
bool isPackageAccessible(Package , Visibility , SearchOptFlags ) {
return false;
}
/********************************
* Insert Dsymbol in table.
* Params:
* s = symbol to add
* Returns:
* null if already in table, `s` if inserted
*/
Dsymbol symtabInsert(Dsymbol ) {
return symtab.insert;
}
}
class WithScopeSymbol {
}
class ArrayScopeSymbol {
}
class OverloadSet {
}
class ForwardingScopeDsymbol {
}
class AliasAssign : Dsymbol
{
this(Loc , Identifier , Type , Dsymbol ) {
}
}
class DsymbolTable {
/**************************
* Insert Dsymbol in table.
* Params:
* s = symbol to add
* Returns:
* null if already in table, `s` if inserted
*/
Dsymbol insert()
{
return insert;
}
}
class CAsmDeclaration : Dsymbol
{
Expression code;
}
/**
* Defines `TemplateDeclaration`, `TemplateInstance` and a few utilities
*
* This modules holds the two main template types:
* `TemplateDeclaration`, which is the user-provided declaration of a template,
* and `TemplateInstance`, which is an instance of a `TemplateDeclaration`
* with specific arguments.
*
* Template_Parameter:
* Additionally, the classes for template parameters are defined in this module.
* The base class, `TemplateParameter`, is inherited by:
* - `TemplateTypeParameter`
* - `TemplateThisParameter`
* - `TemplateValueParameter`
* - `TemplateAliasParameter`
* - `TemplateTupleParameter`
*
* Templates_semantic:
* The start of the template instantiation process looks like this:
* - A `TypeInstance` or `TypeIdentifier` is encountered.
* `TypeInstance` have a bang (e.g. `Foo!(arg)`) while `TypeIdentifier` don't.
* - A `TemplateInstance` is instantiated
* - Semantic is run on the `TemplateInstance` (see `dmd.dsymbolsem`)
* - The `TemplateInstance` search for its `TemplateDeclaration`,
* runs semantic on the template arguments and deduce the best match
* among the possible overloads.
* - The `TemplateInstance` search for existing instances with the same
* arguments, and uses it if found.
* - Otherwise, the rest of semantic is run on the `TemplateInstance`.
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dtemplate.d, _dtemplate.d)
* Documentation: https://dlang.org/phobos/dmd_dtemplate.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dtemplate.d
*/
module dmd.dtemplate;
import dmd.arraytypes;
import dmd.ast_node;
import dmd.dsymbol;
import dmd.expression;
import dmd.identifier;
import dmd.location;
import dmd.mtype;
import dmd.rootobject;
import dmd.visitor;
inout(Dsymbol) isDsymbol(inout RootObject o)
{
return cast(inout(Dsymbol))o;
}
class TemplateDeclaration : ScopeDsymbol
{
this(Loc , Identifier , TemplateParameters* , Expression , Dsymbols* , bool = false, bool = false)
{
}
}
/***********************************************************
* https://dlang.org/spec/template.html#TemplateParameter
*/
extern (C++) class TemplateParameter : ASTNode
{
Loc loc;
Identifier ident;
this(Loc , Identifier ) {
}
override void accept(Visitor )
{
}
}
class TemplateTypeParameter : TemplateParameter
{
Type specType; // if !=null, this is the type specialization
Type defaultType;
this(Loc , Identifier , Type , Type ) {
super(loc, ident);
}
}
class TemplateThisParameter : TemplateTypeParameter
{
this(Loc , Identifier , Type , Type ) {
super(loc, ident, specType, defaultType);
}
}
class TemplateValueParameter : TemplateParameter
{
this(Loc , Identifier , Type ,
Expression , Expression ) {
super(loc, ident);
}
}
class TemplateAliasParameter : TemplateParameter
{
this(Loc , Identifier , Type , RootObject , RootObject ) {
super(loc, ident);
}
}
class TemplateTupleParameter : TemplateParameter
{
this(Loc , Identifier ) {
super(loc, ident);
}
}
class TemplateInstance : ScopeDsymbol
{
// Array of Types/Expressions of template
// instance arguments [int*, char, 10*10]
Objects* tiargs;
this(Loc , Identifier , Objects* ) {
}
}
class TemplateMixin : TemplateInstance
{
TypeQualified tqual;
this(Loc , Identifier , TypeQualified , Objects* )
{
super(loc,
tqual? cast(Identifier)tqual: ident,
tiargs );
}
}
/// Pair of MATCHes
struct MATCHpair
{
}
/**
* Defines a function declaration.
*
* Includes:
* - function/delegate literals
* - function aliases
* - (static/shared) constructors/destructors/post-blits
* - `invariant`
* - `unittest`
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/func.d, _func.d)
* Documentation: https://dlang.org/phobos/dmd_func.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/func.d
*/
module dmd.func;
import dmd.arraytypes;
import dmd.astenums;
import dmd.declaration;
import dmd.dscope;
import dmd.globals;
import dmd.id;
import dmd.identifier;
import dmd.location;
import dmd.mtype;
import dmd.statement;
import dmd.tokens;
enum BUILTIN {
unknown }
struct Ensure
{
Identifier id;
Statement ensure;
}
struct ContractInfo
{
Statements* frequires; /// in contracts
Ensures* fensures; /// out contracts
}
class FuncDeclaration : Declaration
{
Statement fbody; /// function body
ContractInfo* contracts; /// contract information
Loc endloc; /// location of closing curly bracket
this(Loc , Loc , Identifier , StorageClass , Type )
{
super(ident);
}
ContractInfo getContracts()
{
return *contracts;
}
// getters
inout(Statements*) frequires() inout { return contracts ? frequires : null; }
inout(Ensures*) fensures() inout { return contracts ? fensures : null; }
static generateContractSetter(string field, string type)
{
return type ~ field ~ "(" ~ type ~ " param)" ~
"{
if (!param && !contracts) return null;
return getContracts()." ~ field ~ " = param;
}";
}
mixin(generateContractSetter("frequires", "Statements*"));
mixin(generateContractSetter("fensures", "Ensures*"));
}
class FuncAliasDeclaration : FuncDeclaration
{
this()
{
super(loc, endloc, ident, storage_class, type);
}
}
class FuncLiteralDeclaration : FuncDeclaration
{
this(Loc , Loc , Type , TOK , ForeachStatement , Identifier , StorageClass )
{
super(loc, endloc, null, storage_class, type);
//printf("FuncLiteralDeclaration() id = '%s', type = '%s'\n", this.ident.toChars(), type.toChars());
}
}
class CtorDeclaration : FuncDeclaration
{
this(Loc , Loc , StorageClass stc, Type )
{
super(loc, endloc, Id.ctor, stc, type);
//printf("CtorDeclaration(loc = %s) %s %p\n", loc.toChars(), toChars(), this);
}
}
class PostBlitDeclaration : FuncDeclaration
{
this(Loc , Loc , StorageClass stc, Identifier id)
{
super(loc, endloc, id, stc, null);
}
}
class DtorDeclaration : FuncDeclaration
{
this(Loc , Loc , StorageClass stc, Identifier id)
{
super(loc, endloc, id, stc, null);
}
}
class StaticCtorDeclaration : FuncDeclaration
{
this(Loc , Loc , StorageClass )
{
super(loc, endloc, Identifier.generateIdWithLoc("_staticCtor", loc), STC.static_ , null);
}
}
class SharedStaticCtorDeclaration : StaticCtorDeclaration
{
this(Loc , Loc , StorageClass stc)
{
super(loc, endloc, stc);
}
}
class StaticDtorDeclaration : FuncDeclaration
{
this(Loc , Loc , StorageClass )
{
super(loc, endloc, Identifier.generateIdWithLoc("_staticDtor", loc), STC.static_ , null);
}
}
class SharedStaticDtorDeclaration : StaticDtorDeclaration
{
this(Loc , Loc , StorageClass stc)
{
super(loc, endloc, stc);
}
}
class InvariantDeclaration : FuncDeclaration
{
this(Loc , Loc , StorageClass stc, Identifier id, Statement )
{
// Make a unique invariant for now; we'll fix it up as we add it to the aggregate invariant list.
super(loc, endloc, id , stc, null);
}
}
class UnitTestDeclaration : FuncDeclaration
{
this(Loc , Loc , StorageClass stc, char* )
{
super(loc, endloc, Identifier.generateIdWithLoc("__unittest", loc), stc, null);
}
}
class NewDeclaration : FuncDeclaration
{
this(Loc , StorageClass )
{
super(loc, Loc.initial, Id.classNew, STC.static_ , null);
}
}
/**************************************
* A statement / expression in this scope is not `@safe`,
* so mark the enclosing function as `@system`
*
* Params:
* sc = scope that the unsafe statement / expression is in
* gag = surpress error message (used in escape.d)
* loc = location of error
* fmt = printf-style format string
* arg0 = (optional) argument for first %s format specifier
* arg1 = (optional) argument for second %s format specifier
* arg2 = (optional) argument for third %s format specifier
* Returns: whether there's a safe error
*/
bool setUnsafe(Scope* sc)
{
return sc.setUnsafe;
}
/***************************************
* Like `setUnsafe`, but for safety errors still behind preview switches
*
* Given a `FeatureState fs`, for example dip1000 / dip25 / systemVariables,
* the behavior changes based on the setting:
*
* - In case of `-revert=fs`, it does nothing.
* - In case of `-preview=fs`, it's the same as `setUnsafe`
* - By default, print a deprecation in `@safe` functions, or store an attribute violation in inferred functions.
*
* Params:
* sc = used to find affected function/variable, and for checking whether we are in a deprecated / speculative scope
* fs = feature state from the preview flag
* gag = surpress error message
* loc = location of error
* msg = printf-style format string
* arg0 = (optional) argument for first %s format specifier
* arg1 = (optional) argument for second %s format specifier
* arg2 = (optional) argument for third %s format specifier
* Returns: whether an actual safe error (not deprecation) occured
*/
bool setUnsafePreview(Scope* sc, FeatureState fs)
{
//printf("setUnsafePreview() fs:%d %s\n", fs, msg);
with (FeatureState) final switch (fs)
{
case disabled:
return false;
case enabled:
return sc.setUnsafe;
case default_:
return false;
}
}
/**
* Defines a D type.
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/mtype.d, _mtype.d)
* Documentation: https://dlang.org/phobos/dmd_mtype.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/mtype.d
*/
module dmd.mtype;
import dmd.arraytypes;
import dmd.astenums;
import dmd.ast_node;
import dmd.dtemplate;
import dmd.expression;
import dmd.identifier;
import dmd.location;
import dmd.rootobject;
import dmd.visitor;
/************************************
* Convert MODxxxx to STCxxx
*/
StorageClass ModToStc(uint ) {
StorageClass stc ;
return stc;
}
/****************
* dotExp() bit flags
*/
enum DotExpFlag
{
none }
/// Result of a check whether two types are covariant
enum Covariant
{
distinct }
/***********************************************************
*/
extern (C++) class Type : ASTNode
{
TY ty;
__gshared Type tvoid;
__gshared Type tint8;
__gshared Type tuns8;
__gshared Type tint16;
__gshared Type tuns16;
__gshared Type tint32;
__gshared Type tuns32;
__gshared Type tint64;
__gshared Type tuns64;
__gshared Type tint128;
__gshared Type tuns128;
__gshared Type tfloat32;
__gshared Type tfloat64;
__gshared Type tfloat80;
__gshared Type timaginary32;
__gshared Type timaginary64;
__gshared Type timaginary80;
__gshared Type tcomplex32;
__gshared Type tcomplex64;
__gshared Type tcomplex80;
__gshared Type tbool;
__gshared Type tchar;
__gshared Type twchar;
__gshared Type tdchar;
__gshared Type terror; // for error recovery
extern () ubyte[] sizeTy = {
ubyte[] sizeTy ;
return sizeTy;
}();
this(TY ) {
}
Type syntaxCopy()
{
assert(0);
}
final addSTC(StorageClass )
{
Type t ;
return t;
}
/*************************************
* If this is a type of something, return that something.
*/
Type nextOf()
{
return null;
}
inout {
inout(TypePointer) isTypePointer() { return ty ? cast(typeof(return))this : null; }
inout(TypeFunction) isTypeFunction() { return ty ? cast(typeof(return))this : null; }
inout(TypeDelegate) isTypeDelegate() { return ty ? cast(typeof(return))this : null; }
}
override void accept(Visitor )
{
}
}
class TypeError : Type
{
this() {
super(Terror);
}
}
class TypeNext : Type
{
Type next;
this(TY , Type ) {
super(ty);
}
}
class TypeBasic : Type
{
this() {
super(ty);
}
}
class TypeVector : Type
{
this(Type ) {
super(Tvector);
}
}
class TypeArray : TypeNext
{
this(TY , Type ) {
super(ty, next);
}
}
class TypeSArray : TypeArray
{
Expression dim;
this(Type t, Expression ) {
super(Tsarray, t);
}
}
class TypeDArray : TypeArray
{
this(Type t) {
super(Tarray, t);
//printf("TypeDArray(t = %p)\n", t);
}
}
class TypeAArray : TypeArray
{
Type index; // key type
this(Type t, Type ) {
super(Taarray, t);
}
}
class TypePointer : TypeNext
{
this(Type t) {
super(Tpointer, t);
}
}
class TypeReference : TypeNext
{
this(Type t) {
super(Treference, t);
// BUG: what about references to static arrays?
}
}
enum RET {
regs }
class TypeFunction : TypeNext
{
// .next is the return type
ParameterList parameterList; // function parameters
this(ParameterList , Type treturn, LINK , StorageClass ) {
super(Tfunction, treturn);
}
}
class TypeDelegate : TypeNext
{
this(TypeFunction t) {
super(Tfunction, t);
}
}
class TypeTraits : Type
{
this(Loc , TraitsExp ) {
super(Ttraits);
}
}
class TypeMixin : Type
{
this(Loc , Expressions* ) {
super(Tmixin);
}
}
class TypeQualified : Type
{
Loc loc;
this(TY , Loc )
{
super(ty);
}
final addIdent(Identifier )
{
}
final addInst(TemplateInstance )
{
}
final addIndex(RootObject )
{
}
}
class TypeIdentifier : TypeQualified
{
Identifier ident;
this(Loc , Identifier )
{
super(Tident, loc);
}
}
class TypeInstance : TypeQualified
{
this(Loc , TemplateInstance )
{
super(Tinstance, loc);
}
}
class TypeTypeof : TypeQualified
{
this(Loc , Expression )
{
super(Ttypeof, loc);
}
}
class TypeReturn : TypeQualified
{
this(Loc )
{
super(Treturn, loc);
}
}
class TypeStruct : Type
{
this() {
super(Tstruct);
}
}
class TypeEnum : Type
{
this() {
super(Tenum);
}
}
class TypeClass : Type
{
this() {
super(Tclass);
}
}
class TypeTuple : Type
{
this() {
super(Ttuple);
}
}
class TypeSlice : TypeNext
{
this(Type , Expression , Expression ) {
super(Tslice, next);
}
}
class TypeNull : Type
{
this() {
//printf("TypeNull %p\n", this);
super(Tnull);
}
}
class TypeNoreturn : Type
{
this() {
//printf("TypeNoreturn %p\n", this);
super(Tnoreturn);
}
}
class TypeTag : Type
{
this() {
//printf("TypeTag ctor %s %p\n", id ? id.toChars() : "null".ptr, this);
super(Ttag);
}
}
struct ParameterList
{
/// The raw (unexpanded) formal parameters, possibly containing tuples.
Parameters* parameters;
VarArg varargs ;
this(Parameters* , VarArg , StorageClass ) {
}
}
/***********************************************************
*/
extern (C++) class Parameter : ASTNode
{
import dmd.attrib ;
UserAttributeDeclaration userAttribDecl; // user defined attributes
this(Loc , StorageClass , Type , Identifier , Expression , UserAttributeDeclaration ) {
}
override void accept(Visitor )
{
}
/***************************************
* Determine number of arguments, folding in tuples.
*/
static dim(Parameters* )
{
size_t nargs ;
return nargs;
}
}
dub run dustmite -- $1 --noremove build.bat build.bat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment