Introduced properties

private var _tool_is_in_path: nullable Bool

nitc :: GLSLValidationPhase :: _tool_is_in_path

Is the tool glsllangValidator in path?
init defaultinit(toolcontext: ToolContext, depends: nullable Collection[Phase])

nitc :: GLSLValidationPhase :: defaultinit

private fun tool_is_in_path: nullable Bool

nitc :: GLSLValidationPhase :: tool_is_in_path

Is the tool glsllangValidator in path?
private fun tool_is_in_path=(tool_is_in_path: nullable Bool)

nitc :: GLSLValidationPhase :: tool_is_in_path=

Is the tool glsllangValidator in path?

Redefined properties

redef type SELF: GLSLValidationPhase

nitc $ GLSLValidationPhase :: SELF

Type of this instance, automatically specialized in every class
redef fun process_annotated_node(nstring: ANode, nat: AAnnotation)

nitc $ GLSLValidationPhase :: process_annotated_node

Specific actions to execute on annotated nodes

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _depends: nullable Collection[Phase]

nitc :: Phase :: _depends

The explicit dependences, used to initialize in_importation
private var _disabled: Bool

nitc :: Phase :: _disabled

Is the phase globally disabled?
private var _in_hierarchy: POSetElement[Phase]

nitc :: Phase :: _in_hierarchy

The dependence relation of the phase with the other phases
private var _tool_is_in_path: nullable Bool

nitc :: GLSLValidationPhase :: _tool_is_in_path

Is the tool glsllangValidator in path?
private var _toolcontext: ToolContext

nitc :: Phase :: _toolcontext

The toolcontext instance attached to the phase
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(toolcontext: ToolContext, depends: nullable Collection[Phase])

nitc :: GLSLValidationPhase :: defaultinit

init defaultinit(toolcontext: ToolContext, depends: nullable Collection[Phase])

nitc :: Phase :: defaultinit

fun depends: nullable Collection[Phase]

nitc :: Phase :: depends

The explicit dependences, used to initialize in_importation
protected fun depends=(depends: nullable Collection[Phase])

nitc :: Phase :: depends=

The explicit dependences, used to initialize in_importation
fun disabled: Bool

nitc :: Phase :: disabled

Is the phase globally disabled?
fun disabled=(disabled: Bool)

nitc :: Phase :: disabled=

Is the phase globally disabled?
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun in_hierarchy: POSetElement[Phase]

nitc :: Phase :: in_hierarchy

The dependence relation of the phase with the other phases
protected fun in_hierarchy=(in_hierarchy: POSetElement[Phase])

nitc :: Phase :: in_hierarchy=

The dependence relation of the phase with the other phases
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun process_annotated_node(node: ANode, nat: AAnnotation)

nitc :: Phase :: process_annotated_node

Specific actions to execute on annotated nodes
fun process_mainmodule(mainmodule: MModule, given_mmodules: SequenceRead[MModule])

nitc :: Phase :: process_mainmodule

Specific action to execute on the whole program.
fun process_nclassdef(nclassdef: AClassdef)

nitc :: Phase :: process_nclassdef

Specific actions to execute on the tree of a class definition
fun process_nmodule(nmodule: AModule)

nitc :: Phase :: process_nmodule

Specific actions to execute on the whole tree of a module
fun process_nmodule_after(nmodule: AModule)

nitc :: Phase :: process_nmodule_after

Specific actions to execute on the whole tree of a module
fun process_npropdef(npropdef: APropdef)

nitc :: Phase :: process_npropdef

Specific actions to execute on the tree of a property
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
private fun tool_is_in_path: nullable Bool

nitc :: GLSLValidationPhase :: tool_is_in_path

Is the tool glsllangValidator in path?
private fun tool_is_in_path=(tool_is_in_path: nullable Bool)

nitc :: GLSLValidationPhase :: tool_is_in_path=

Is the tool glsllangValidator in path?
fun toolcontext: ToolContext

nitc :: Phase :: toolcontext

The toolcontext instance attached to the phase
protected fun toolcontext=(toolcontext: ToolContext)

nitc :: Phase :: toolcontext=

The toolcontext instance attached to the phase
package_diagram nitc::glsl_validation::GLSLValidationPhase GLSLValidationPhase nitc::Phase Phase nitc::glsl_validation::GLSLValidationPhase->nitc::Phase core::Object Object nitc::Phase->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class Phase

nitc :: Phase

Abstraction of steps in the analysis/processing of Nit programs

Class definitions

nitc $ GLSLValidationPhase
private class GLSLValidationPhase
	super Phase

	# Annotation names

	fun annot_name_vertex: String do return "glsl_vertex_shader"
	fun annot_name_fragment: String do return "glsl_fragment_shader"

	# TODO support more shader types as needed

	# Is the tool _glsllangValidator_ in path?
	var tool_is_in_path: nullable Bool = null

	redef fun process_annotated_node(nstring, nat)
	do
		var annot_name = nat.n_atid.n_id.text
		var is_vertex = annot_name == annot_name_vertex
		var is_fragment = annot_name == annot_name_fragment

		# Skip if we are not interested
		if not is_vertex and not is_fragment then return

		# Only applicable on strings
		if not nstring isa AStringFormExpr then
			toolcontext.error(nstring.location,
				"Syntax Error: only a string literal can be annotated as `{annot_name}`.")
			return
		end

		# Do not double check if tool is in path
		var in_path = tool_is_in_path
		if in_path == null then
			# Is _glslangValidator_ installed?
			var proc_which = new ProcessReader("which", "glslangValidator")
			proc_which.wait
			proc_which.close
			var status = proc_which.status
			in_path = status == 0
			tool_is_in_path = in_path
		end

		if not in_path then
			toolcontext.advice(nat.location, "glslvalidator",
				"Warning: program `glslangValidator` not in PATH, cannot validate this shader.")
			return
		end

		# Get the shader source
		var shader = nstring.value

		# Copy the shader to a file
		# TODO make it more portable
		var tmp = "/tmp/"
		var ext
		if is_vertex then
			ext = "vert"
		else ext = "frag"
		var path = tmp / "nit_shader." + ext

		shader.write_to_file path

		# Execute the validator
		var proc_validator = new ProcessReader("glslangValidator", path)
		proc_validator.wait
		var lines = proc_validator.read_all.split('\n')
		proc_validator.close

		# Parse errors
		var regex = "[A-Z]+: ([0-9]+):([0-9]+): (.*)".to_re
		for line in lines do
			var match = line.search(regex)

			# Does it match an error?
			# If not, then it should be the summary
			if match != null then
				var shader_line_no = match.subs[1].to_s.to_i
				var msg = match.subs[2].to_s

				var line_start = nstring.location.line_start + shader_line_no
				var char_start = 0
				var char_end = 0
				var loc = new Location(nat.location.file,
					line_start, line_start,
					char_start, char_end)

				toolcontext.warning(loc, "glslvalidator",
					"Shader error on {msg}")
			end
		end
	end
end
src/frontend/glsl_validation.nit:30,1--120,3