dmd.expressionsem

Semantic analysis of expressions.

Specification: ($LINK2 https://dlang.org/spec/expression.html, Expressions)

Authors

Walter Bright

Source: expressionsem.d

  • Declaration

    bool expressionsToString(ref OutBuffer buf, Scope* sc, Expressions* exps);

    Perform semantic analysis and CTFE on expressions to produce a string.

    Parameters

    OutBuffer buf

    append generated string to buffer

    Scope* sc

    context

    Expressions* exps

    array of Expressions

    Return Value

    true on error

  • Declaration

    FuncDeclaration hasThis(Scope* sc);

    Determine if this is available by walking up the enclosing scopes until a function is found.

    Parameters

    Scope* sc

    where to start looking for the enclosing function

    Return Value

    Found function if it satisfies isThis(), otherwise null

  • Declaration

    StringExp semanticString(Scope* sc, Expression exp, const char* s);

    Resolve exp as a compile-time known string.

    Parameters

    Scope* sc

    scope

    Expression exp

    Expression which expected as a string

    char* s

    What the string is expected for, will be used in error diagnostic.

    Return Value

    String literal, or null if error happens.

  • Declaration

    StringExp toUTF8(StringExp se, Scope* sc);

    Convert string to char[].

  • Declaration

    Expression resolveOpDollar(Scope* sc, ArrayExp ae, Expression* pe0);

    Runs semantic on ae.arguments. Declares temporary variables if '$' was used.

  • Declaration

    Expression resolveOpDollar(Scope* sc, ArrayExp ae, IntervalExp ie, Expression* pe0);

    Runs semantic on se.lwr and se.upr. Declares a temporary variable if '$' was used.

    Return Value

    ae, or ErrorExp if errors occurred

  • Declaration

    bool arrayExpressionSemantic(Expression[] exps, Scope* sc, bool preserveErrors = false);

    Perform semantic() on an array of Expressions.

  • Declaration

    Expression doCopyOrMove(Scope* sc, Expression e, Type t = null);

    Handle the postblit call on lvalue, or the move of rvalue.

    Parameters

    Scope* sc

    the scope where the expression is encountered

    Expression e

    the expression the needs to be moved or copied (source)

    Type t

    if the struct defines a copy constructor, the type of the destination

    Return Value

    The expression that copy constructs or moves the value.

  • Declaration

    Expression valueNoDtor(Expression e);

    If we want the value of this expression, but do not want to call the destructor on it.

  • Declaration

    Expression resolvePropertiesOnly(Scope* sc, Expression e1);

    If e1 is a property function (template), resolve it.

  • Declaration

    Expression symbolToExp(Dsymbol s, const ref Loc loc, Scope* sc, bool hasOverloads);

    Turn symbol s into the expression it represents.

    Parameters

    Dsymbol s

    symbol to resolve

    Loc loc

    location of use of s

    Scope* sc

    context

    bool hasOverloads

    applies if s represents a function. true means it's overloaded and will be resolved later, false means it's the exact function symbol.

    Return Value

    s turned into an expression, ErrorExp if an error occurred

  • Declaration

    Package resolveIsPackage(Dsymbol sym);

    Determines whether a symbol represents a module or package (Used as a helper for is(type == module) and is(type == package))

    Parameters

    Dsymbol sym

    the symbol to be checked

    Return Value

    the symbol which sym represents (or null if it doesn't represent a Package)

  • Declaration

    Expression trySemantic(Expression exp, Scope* sc);

    Try to run semantic routines. If they fail, return NULL.

  • Declaration

    Expression unaSemantic(UnaExp e, Scope* sc);

    Helper function for easy error propagation. If error occurs, returns ErrorExp. Otherwise returns NULL.

  • Declaration

    Expression binSemantic(BinExp e, Scope* sc);

    Helper function for easy error propagation. If error occurs, returns ErrorExp. Otherwise returns NULL.

  • Declaration

    Expression dotIdSemanticProp(DotIdExp exp, Scope* sc, bool gag);

    Resolve properties, i.e. e1.ident, without seeing UFCS.

    Parameters

    DotIdExp exp

    expression to resolve

    Scope* sc

    context

    bool gag

    do not emit error messages, just return null

    Return Value

    resolved expression, null if error

  • Declaration

    Expression dotTemplateSemanticProp(DotTemplateInstanceExp exp, Scope* sc, bool gag);

    Resolve e1.ident!tiargs without seeing UFCS.

    Parameters

    DotTemplateInstanceExp exp

    the DotTemplateInstanceExp to resolve

    Scope* sc

    the semantic scope

    bool gag

    stop "not a property" error and return null.

    Return Value

    null if error or not found, or the resolved expression.

  • Declaration

    bool checkSharedAccess(Expression e, Scope* sc, bool returnRef = false);

    If expression is shared, check that we can access it. Give error message if not.

    Parameters

    Expression e

    expression to check

    Scope* sc

    context

    bool returnRef

    Whether this expression is for a return statement off a ref function, in which case a single level of dereference is allowed (e.g. shared(int)*).

    Return Value

    true on error

  • Declaration

    Expression addDtorHook(Expression e, Scope* sc);

    Destructors are attached to VarDeclarations. Hence, if expression returns a temp that needs a destructor, make sure and create a VarDeclaration for that temp.

  • Declaration

    bool checkAddressVar(Scope* sc, Expression exp, VarDeclaration v);

    Determine if exp, which gets its address taken, can do so safely.

    Parameters

    Scope* sc

    context

    Expression exp

    expression having its address taken

    VarDeclaration v

    the variable getting its address taken

    Return Value

    true if ok, false for error

  • Declaration

    bool checkAddressable(Expression e, Scope* sc);

    This check ensures that the object in exp can have its address taken, or issue a diagnostic error.

    Parameters

    Expression e

    expression to check

    Scope* sc

    context

    Return Value

    true if the expression is addressable

  • Declaration

    Expression getThisSkipNestedFuncs(const ref Loc loc, Scope* sc, Dsymbol s, AggregateDeclaration ad, Expression e1, Type t, Dsymbol var, bool flag = false);

    Helper function for getRightThis(). Gets this of the next outer aggregate.

    Parameters

    Loc loc

    location to use for error messages

    Scope* sc

    context

    Dsymbol s

    the parent symbol of the existing this

    AggregateDeclaration ad

    struct or class we need the correct this for

    Expression e1

    existing this

    Type t

    type of the existing this

    Dsymbol var

    the specific member of ad we're accessing

    bool flag

    if true, return null instead of throwing an error

    Return Value

    Expression representing the this for the var

  • Declaration

    VarDeclaration makeThis2Argument(const ref Loc loc, Scope* sc, FuncDeclaration fd);

    Make a dual-context container for use as a this argument.

    Parameters

    Loc loc

    location to use for error messages

    Scope* sc

    current scope

    FuncDeclaration fd

    target function that will take the this argument

    Return Value

    Temporary closure variable.

    Note: The function fd is added to the nested references of the newly created variable such that a closure is made for the variable when the address of fd is taken.

  • Declaration

    bool verifyHookExist(const ref Loc loc, ref Scope sc, Identifier id, string description, Identifier module_ = Id.object);

    Make sure that the runtime hook id exists.

    Parameters

    Loc loc

    location to use for error messages

    Scope sc

    current scope

    Identifier id

    the hook identifier

    string description

    what the hook does

    Identifier module_

    what module the hook is located in

    Return Value

    a bool indicating if the hook is present.

  • Declaration

    Expression getVarExp(EnumMember em, const ref Loc loc, Scope* sc);

    Returns em as a VariableExp

    Parameters

    EnumMember em

    the EnumMember to wrap

    Loc loc

    location of use of em

    Scope* sc

    scope of use of em

    Return Value

    VarExp referenceing em or ErrorExp if em if disabled/deprecated

  • Declaration

    Expression toBoolean(Expression exp, Scope* sc);

    Try to treat exp as a boolean,

    Parameters

    Expression exp

    the expression

    Scope* sc

    scope to evalute exp in

    Return Value

    Modified expression on success, ErrorExp on error