2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2007 by Digital Mars
5 // written by Walter Bright
6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
16 #include "declaration.h"
18 #include "expression.h"
21 #include "aggregate.h"
22 #include "identifier.h"
26 /**********************************
27 * Determine if function is a builtin one.
29 enum BUILTIN
FuncDeclaration::isBuiltin()
31 static const char FeZe
[] = "FeZe"; // real function(real)
33 //printf("FuncDeclaration::isBuiltin() %s\n", toChars());
34 if (builtin
== BUILTINunknown
)
38 if (parent
&& parent
->isModule())
40 if (parent
->ident
== Id::math
&&
41 parent
->parent
&& parent
->parent
->ident
== Id::std
&&
42 !parent
->parent
->parent
)
44 if (strcmp(type
->deco
, FeZe
) == 0)
48 else if (ident
== Id::cos
)
50 else if (ident
== Id::tan
)
52 else if (ident
== Id::_sqrt
)
53 builtin
= BUILTINsqrt
;
54 else if (ident
== Id::fabs
)
55 builtin
= BUILTINfabs
;
56 //printf("builtin = %d\n", builtin);
61 /* Maybe in GCC 4.3... */
68 /**************************************
69 * Evaluate builtin function.
70 * Return result; NULL if cannot evaluate it.
73 Expression
*eval_builtin(enum BUILTIN builtin
, Expressions
*arguments
)
75 assert(arguments
&& arguments
->dim
);
76 Expression
*arg0
= (Expression
*)arguments
->data
[0];
82 if (arg0
->op
== TOKfloat64
)
83 e
= new RealExp(0, sinl(arg0
->toReal()), Type::tfloat80
);
87 if (arg0
->op
== TOKfloat64
)
88 e
= new RealExp(0, cosl(arg0
->toReal()), Type::tfloat80
);
92 if (arg0
->op
== TOKfloat64
)
93 e
= new RealExp(0, tanl(arg0
->toReal()), Type::tfloat80
);
97 if (arg0
->op
== TOKfloat64
)
98 e
= new RealExp(0, sqrtl(arg0
->toReal()), Type::tfloat80
);
102 if (arg0
->op
== TOKfloat64
)
103 e
= new RealExp(0, fabsl(arg0
->toReal()), Type::tfloat80
);