<commit_before>/*
 * Copyright (C)2005-2012 Haxe Foundation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
package haxe.macro;

import haxe.macro.Expr;

/**
	Context provides an API for macro programming.
	
	It contains common functions that interact with the macro interpreter to
	query or set information. Other API functions are available in the tools
	classes:
		
	- `haxe.macro.ComplexTypeTools`
	- `haxe.macro.ExprTools`
	- `haxe.macro.TypeTools`
**/
#if !neko @:noDoc #end
class Context {

#if neko
	/**
		Displays a compilation error `msg` at the given `Position` `pos`
		and aborts the current macro call.
	**/
	public static function error( msg : String, pos : Position ) : Dynamic {
		return load("error",2)(untyped msg.__s, pos);
	}

	/**
		Displays a compilation warning `msg` at the given `Position` `pos`.
	**/
	public static function warning( msg : String, pos : Position ) {
		load("warning",2)(untyped msg.__s, pos);
	}

	/**
		Resolves a file name `file` based on the current class paths.
		
		The resolution follows the usual class path rules where the last
		declared class path has priority.
		
		If a class path was declared relative, this method returns the relative
		file path. Otherwise it returns the absolute file path.
	**/
	public static function resolvePath( file : String ) {
		return new String(load("resolve",1)(untyped file.__s));
	}

	/**
		Returns an `Array` of current class paths in the order of their
		declaration.
		
		Modifying the returned array has no effect on the compiler. Class paths
		can be added using `haxe.macro.Compiler.addClassPath`.
	**/
	public static function getClassPath() : Array<String> {
		var c : neko.NativeArray<neko.NativeString> = load("class_path",0)();
		var a = new Array();
		for( i in 0...neko.NativeArray.length(c) )
			a.push(Std.string(c[i]));
		return a;
	}

	/**
		Returns the position at which the macro was called.
	**/
	public static function currentPos() : Position {
		return load("curpos", 0)();
	}

	/**
		Returns the current class in which the macro was called.
		
		If no such class exists, null is returned.
	**/
	public static function getLocalClass() : Null<Type.Ref<Type.ClassType>> {
		var l : Type = load("local_type", 0)();
		if( l == null ) return null;
		return switch( l ) {
		case TInst(c,_): c;
		default: null;
		}
	}

	/**
		Returns the current type in/on which the macro was called.
		
		If no such type exists, null is returned.
	**/
	public static function getLocalType() : Null<Type> {
		var l : Type = load("local_type", 0)();
		if( l == null ) return null;
		return l;
	}

	/**
		Returns the name of the method from which the macro was called.
		
		If no such method exists, null is returned.
	**/
	public static function getLocalMethod() : Null<String> {
		var l : String = load("local_method", 0)();
		if (l == "") return null;
		return new String(l);
	}

	/**
		Returns an `Array` of classes which are available for `using` usage in
		the context the macro was called.
		
		Modifying the returned array has no effect on the compiler.
	**/
	public static function getLocalUsing() :  Array<Type.Ref<Type.ClassType>> {
		return load("local_using", 0)();
	}

	/**
		Returns a map of local variables accessible in the context the macro was
		called.
		
		The keys of the returned map are the variable names, the values are
		their types.
		
		Modifying the returned map has no effect on the compiler.
	**/
	public static function getLocalVars() : haxe.ds.StringMap<Type> {
		return load("local_vars", 0)();
	}

	/**
		Tells if compiler directive `s` has been set.
		
		Compiler directives are set using the `-D` command line parameter, or
		by calling `haxe.macro.Compiler.define`.
	**/
	public static function defined( s : String ) : Bool {
		return load("defined", 1)(untyped s.__s);
	}

	/**
		Returns the value defined for compiler directive `key`.
		
		If no value is defined for `key`, null is returned.
		
		Compiler directive values are set using the `-D key=value` command line
		parameter, or by calling `haxe.macro.Compiler.define`.
		
		The default value is `"1"`.
	**/
	public static function definedValue( key : String ) : String {
		return new String(load("defined_value", 1)(untyped key.__s));<commit_msg>fixed Context.definedValue returning "null" string<commit_after>/*
 * Copyright (C)2005-2012 Haxe Foundation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
package haxe.macro;

import haxe.macro.Expr;

/**
	Context provides an API for macro programming.
	
	It contains common functions that interact with the macro interpreter to
	query or set information. Other API functions are available in the tools
	classes:
		
	- `haxe.macro.ComplexTypeTools`
	- `haxe.macro.ExprTools`
	- `haxe.macro.TypeTools`
**/
#if !neko @:noDoc #end
class Context {

#if neko
	/**
		Displays a compilation error `msg` at the given `Position` `pos`
		and aborts the current macro call.
	**/
	public static function error( msg : String, pos : Position ) : Dynamic {
		return load("error",2)(untyped msg.__s, pos);
	}

	/**
		Displays a compilation warning `msg` at the given `Position` `pos`.
	**/
	public static function warning( msg : String, pos : Position ) {
		load("warning",2)(untyped msg.__s, pos);
	}

	/**
		Resolves a file name `file` based on the current class paths.
		
		The resolution follows the usual class path rules where the last
		declared class path has priority.
		
		If a class path was declared relative, this method returns the relative
		file path. Otherwise it returns the absolute file path.
	**/
	public static function resolvePath( file : String ) {
		return new String(load("resolve",1)(untyped file.__s));
	}

	/**
		Returns an `Array` of current class paths in the order of their
		declaration.
		
		Modifying the returned array has no effect on the compiler. Class paths
		can be added using `haxe.macro.Compiler.addClassPath`.
	**/
	public static function getClassPath() : Array<String> {
		var c : neko.NativeArray<neko.NativeString> = load("class_path",0)();
		var a = new Array();
		for( i in 0...neko.NativeArray.length(c) )
			a.push(Std.string(c[i]));
		return a;
	}

	/**
		Returns the position at which the macro was called.
	**/
	public static function currentPos() : Position {
		return load("curpos", 0)();
	}

	/**
		Returns the current class in which the macro was called.
		
		If no such class exists, null is returned.
	**/
	public static function getLocalClass() : Null<Type.Ref<Type.ClassType>> {
		var l : Type = load("local_type", 0)();
		if( l == null ) return null;
		return switch( l ) {
		case TInst(c,_): c;
		default: null;
		}
	}

	/**
		Returns the current type in/on which the macro was called.
		
		If no such type exists, null is returned.
	**/
	public static function getLocalType() : Null<Type> {
		var l : Type = load("local_type", 0)();
		if( l == null ) return null;
		return l;
	}

	/**
		Returns the name of the method from which the macro was called.
		
		If no such method exists, null is returned.
	**/
	public static function getLocalMethod() : Null<String> {
		var l : String = load("local_method", 0)();
		if (l == "") return null;
		return new String(l);
	}

	/**
		Returns an `Array` of classes which are available for `using` usage in
		the context the macro was called.
		
		Modifying the returned array has no effect on the compiler.
	**/
	public static function getLocalUsing() :  Array<Type.Ref<Type.ClassType>> {
		return load("local_using", 0)();
	}

	/**
		Returns a map of local variables accessible in the context the macro was
		called.
		
		The keys of the returned map are the variable names, the values are
		their types.
		
		Modifying the returned map has no effect on the compiler.
	**/
	public static function getLocalVars() : haxe.ds.StringMap<Type> {
		return load("local_vars", 0)();
	}

	/**
		Tells if compiler directive `s` has been set.
		
		Compiler directives are set using the `-D` command line parameter, or
		by calling `haxe.macro.Compiler.define`.
	**/
	public static function defined( s : String ) : Bool {
		return load("defined", 1)(untyped s.__s);
	}

	/**
		Returns the value defined for compiler directive `key`.
		
		If no value is defined for `key`, null is returned.
		
		Compiler directive values are set using the `-D key=value` command line
		parameter, or by calling `haxe.macro.Compiler.define`.
		
		The default value is `"1"`.
	**/
	public static function definedValue( key : String ) : String {
		var d = load("defined_value", 1)(untyped key.__s);
		return d == null ? null : new String(d);
{'fraction_non_alphanumeric': 0.09906506752290112, 'fraction_numerical': 0.004155255453772783, 'mean_word_length': 3.6043478260869564, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3796995', 'n_tokens_mistral': 3332, 'n_tokens_neox': 3024, 'n_words': 1345}