Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

dmd.importc

Contains semantic routines specific to ImportC

SpecificationC11

Authors:
Walter Bright
License:
Boost License 1.0

Sourceimportc.d

Documentationhttps://dlang.org/phobos/dmd_importc.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/importc.d

TypecAdjustParamType(Typet, Scope*sc);
C11 does not allow array or function parameters. Hence, adjust those types per C11 6.7.6.3 rules.
Parameters:
Typetparameter type to adjust
Scope*sccontext
Returns:
adjusted type
ExpressionarrayFuncConv(Expressione, Scope*sc);
C11 6.3.2.1-3 Convert expression that is an array of type to a pointer to type. C11 6.3.2.1-4 Convert expression that is a function to a pointer to a function.
Parameters:
ExpressioneImportC expression to possibly convert
Scope*sccontext
Returns:
converted expression
ExpressionfieldLookup(Expressione, Scope*sc, Identifierid, boolarrow);
Run semantic one. Expressione evaluates to an instance of a struct. Look upident as a field of that struct.
Parameters:
Expressioneevaluates to an instance of a struct
Scope*sccontext
Identifierididentifier of a field in that struct
boolarrow-> was used
Returns:
if successfule.ident if not thenErrorExp and message is printed
ExpressioncarraySemantic(ArrayExpae, Scope*sc);
C11 6.5.2.1-2 Apply C semantics toE[I] expression. E1[E2] is lowered to *(E1 + E2)
Parameters:
ArrayExpaeArrayExp to run semantics on
Scope*sccontext
Returns:
Expression if this was a C expression with completed semantic, null if not
voidaddDefaultCInitializer(VarDeclarationdsym);
Determine default initializer for const global symbol.
boolcFuncEquivalence(TypeFunctiontf1, TypeFunctiontf2);
Implement the C11 notion of function equivalence, which allows prototyped functions to match K+R functions, even though they are different.
Parameters:
TypeFunctiontf1type of first function
TypeFunctiontf2type of second function
Returns:
true if C11 considers them equivalent
boolcTypeEquivalence(Typet1, Typet2);
Types haven't been merged yet, because we haven't done semantic() yet. But we still need to see if t1 and t2 are the same type.
Parameters:
Typet1first type
Typet2second type
Returns:
true if they are equivalent types
DsymbolhandleTagSymbols(ref Scopesc, Dsymbols, Dsymbols2, ScopeDsymbolsds);
ImportC tag symbols sit in a parallel symbol table, so that this C code works:
struct S { a; };int S;struct Ss;
But there are relatively few such tag symbols, so that would be a waste of memory and complexity. An additional problem is we'd like the D side to find the tag symbols with ordinary lookup, not lookup in both tables, if the tag symbol is not conflicting with an ordinary symbol. The solution is to put the tag symbols that conflict into an associative array, indexed by the address of the ordinary symbol that conflicts with it. C has no modules, so this associative array is tagSymTab[] in ModuleDeclaration. A side effect of our approach is that D code cannot access a tag symbol that is hidden by an ordinary symbol. This is more of a theoretical problem, as nobody has mentioned it when importing C headers. If someone wants to do it, too bad so sad. Change the C code. This function fixes up the symbol table when faced with adding a new symbols when there is an existing symbols2 with the same name. C also allows forward and prototype declarations of tag symbols, this function merges those.
Parameters:
Scopesccontext
Dsymbolssymbol to add to symbol table
Dsymbols2existing declaration
ScopeDsymbolsdssymbol table
Returns:
if s and s2 are successfully put in symbol table then return the merged symbol, null if they conflict
DsymbolhandleSymbolRedeclarations(ref Scopesc, Dsymbols, Dsymbols2, ScopeDsymbolsds);
ImportC allows redeclarations of C variables, functions and typedefs. extern int x; int x = 3; and: extern void f(); void f() { } Attempt to merge them.
Parameters:
Scopesccontext
Dsymbolssymbol to add to symbol table
Dsymbols2existing declaration
ScopeDsymbolsdssymbol table
Returns:
if s and s2 are successfully put in symbol table then return the merged symbol, null if they conflict
voidcEnumSemantic(Scope*sc, EnumDeclarationed);
ImportC-specific semantic analysis on enum declarationed
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 00:51:18 2026

[8]ページ先頭

©2009-2026 Movatter.jp