public Vector3Type(Scope scope, string scalar) : base(scalar + "3") { Colums = 3; _scalarType = scope.GetType(scalar); scope.AddFunction(new StdFunctionDeclaration(Name, this, new ParameterDeclaration(_scalarType, "x"), new ParameterDeclaration(_scalarType, "y"), new ParameterDeclaration(_scalarType, "z"))); scope.AddFunction(new StdFunctionDeclaration(Name, this, new ParameterDeclaration(scope.GetType(scalar + "2"), "v"), new ParameterDeclaration(_scalarType, "z"))); Members = new MemberDeclaration[] { ShaderRuntime.DeclareMember(this, "x", 0, _scalarType), ShaderRuntime.DeclareMember(this, "y", 1, _scalarType), ShaderRuntime.DeclareMember(this, "z", 2, _scalarType) }; ReflectionType = new Graphics.ShaderReflectionType { Class = Graphics.TypeClass.Vector, Columns = 3, Name = Name, Register = Graphics.RegisterSet.Float4, Elements = 1, Type = ShaderRuntime.GetShaderType(scalar) }; }
/// <summary> /// This method verifies that the function signature is correct. That is that the return type and parameter types are already /// defined. It also verifies that the function does not exist in the scope. /// </summary> /// <param name="fDecl"></param> /// <returns></returns> private bool CheckFunctionSignature(FunctionDeclarationAST fDecl) { TigerType ret = null; if (!string.IsNullOrEmpty(fDecl.ReturnTypeId)) { //si se especifica retorno pero este no es un tipo ya definido ERROR //esto lo garantiza haber organizado las declaraciones if (_scope.HasType(fDecl.ReturnTypeId, out ret) == ScopeLocation.NotDeclared) { _errorListener.Add(AnalysisError.TypeIsNotDefined(fDecl, fDecl.ReturnTypeId)); fDecl.ReturnType = TigerType.GetType <ErrorType>(); return(false); } if (!ret.IsLegalType) { //TODO: Hasta que punto interesa lanzar este error?? _errorListener.Add(new AnalysisError( string.Format(AnalysisError.LoadMessage("InavalidRet"), fDecl.ReturnTypeId), fDecl.Line, fDecl.Columns)); fDecl.ReturnType = TigerType.GetType <ErrorType>(); return(false); } } //ver que la funcion no este previamente declarada if (_scope.HasFunction(fDecl.FunctionId) == ScopeLocation.NotDeclared) { var paramsInfo = new List <KeyValuePair <string, TigerType> >(); foreach (var nameType in fDecl.ParameterList) { TigerType t; //verificar si existe el tipo del parametro. if (_scope.HasType(nameType.Value, out t) == ScopeLocation.NotDeclared) { _errorListener.Add(new AnalysisError( $"Type {nameType.Value} in parameter {fDecl.FunctionId} is not defined", fDecl.Line, fDecl.Columns)); fDecl.ReturnType = TigerType.GetType <ErrorType>(); return(false); } paramsInfo.Add(new KeyValuePair <string, TigerType>(nameType.Key, t)); } var funInfo = new FunctionInfo(paramsInfo, ret ?? TigerType.GetType <NoType>()) { FunctionName = fDecl.FunctionId, FunctionParent = _scope.CurrentFunction }; //se anade en el padre para q este disponible en el scope donde se declara _scope.AddFunction(fDecl.FunctionId, funInfo); return(true); } //ya habia una funcion con ese nombre _errorListener.Add(new AnalysisError(string.Format(AnalysisError.LoadMessage("FuncDecl"), fDecl.FunctionId), fDecl.Line, fDecl.Columns)); return(false); }
private static void AddMainToScope(Scope scope) { //---> principal function var funInfo = new FunctionInfo(new List <KeyValuePair <string, TigerType> >(), TigerType.GetType <NoType>()) { FunctionName = MainFunction, CodeName = MainFunction }; scope.AddFunction(MainFunction, funInfo); //setear este funcion como la funcion actul. scope.CurrentFunction = funInfo; //<--- end of principal function }
public override void CheckSemantics(Scope scope, Report report) { Create(); foreach (var func in functions) {//agregar las funciones primero porque en el cuerpo se pueden usar funciones que esten declaradas debajo func.funcScope = scope.AddChild(ScopeType.Function); List <string> names = new List <string>(); func.paramList.Create(); foreach (var param in func.paramList.parameters) { if (names.Contains(param.id.name)) { report.Add(Line, CharPositionInLine, string.Format("Two parameters of function {0} cant have the name {1}", func.id.name, param.id.name)); returnType = scope.FindType("error"); return; } names.Add(param.id.name); func.funcScope.AddVariable(param.id.name, param.GetTypeInfo(func.funcScope)); } #region id check //esto no lo puedo hacer en el nodo de la funcion porque necesito agregar la funcion en el scope del let func.id.CheckSemantics(scope, report); if (func.id.returnType.isError || scope.ShortFindFunction(func.id.name) != null || scope.ShortFindVariable(func.id.name) != null) {//si entra aqui es que el id esta mal, o ya existe una variable y una funcion con el mismo id report.Add(Line, CharPositionInLine, string.Format("Can't create function {0}", func.id.name)); returnType = scope.FindType("error"); } #endregion scope.AddFunction(func.id.name, func); func.PutReturnType(func.funcScope); func.UpdateTypes(func.funcScope); } foreach (var func in functions) { //No puedo chequear la funcion al principio porque no estarian agregadas las variables, ni los tipos de los parametros func.CheckSemantics(func.funcScope, report); if (func.returnType != null && func.returnType.isError) { returnType = scope.FindType("error"); return; } } }
public override void AddToScope(Scope scope) { scope.AddFunction(this); }