Exemplo n.º 1
0
        private ProtoCore.AST.AssociativeAST.VarDeclNode ParseArgumentDeclaration(string parameterName, Type parameterType)
        {
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access    = ProtoCore.DSASM.AccessSpecifier.kPublic;

            ProtoCore.AST.AssociativeAST.IdentifierNode identifierNode = new ProtoCore.AST.AssociativeAST.IdentifierNode
            {
                Value    = parameterName,
                Name     = parameterName,
                datatype = new ProtoCore.Type()
                {
                    Name        = "var",
                    IsIndexable = false,
                    rank        = 0,
                    UID         = (int)ProtoCore.PrimitiveType.kTypeVar
                }
            };
            //Lets emit native DS type object
            ProtoCore.Type argtype = CLRModuleType.GetProtoCoreType(parameterType, Module);

            varDeclNode.NameNode     = identifierNode;
            varDeclNode.ArgumentType = argtype;
            return(varDeclNode);
        }
Exemplo n.º 2
0
        protected virtual void EmitClassDeclNode(ref ProtoCore.AST.AssociativeAST.ClassDeclNode classDeclNode)
        {
            //EmitCode(classDeclNode.ToString());
            //EmitCode("class ");
            //EmitCode(classDeclNode.className);
            //EmitCode("\n{\n");
            List <ProtoCore.AST.AssociativeAST.AssociativeNode> varList = classDeclNode.varlist;

            foreach (ProtoCore.AST.AssociativeAST.AssociativeNode varMember in varList)
            {
                //how is var member stored?
                if (varMember is ProtoCore.AST.AssociativeAST.VarDeclNode)
                {
                    AST.AssociativeAST.VarDeclNode varDecl = varMember as ProtoCore.AST.AssociativeAST.VarDeclNode;
                    EmitVarDeclNode(ref varDecl);
                }
            }
            List <ProtoCore.AST.AssociativeAST.AssociativeNode> funcList = classDeclNode.funclist;

            foreach (ProtoCore.AST.AssociativeAST.AssociativeNode funcMember in funcList)
            {
                if (funcMember is ProtoCore.AST.AssociativeAST.FunctionDefinitionNode)
                {
                    AST.AssociativeAST.FunctionDefinitionNode funcDefNode = funcMember as ProtoCore.AST.AssociativeAST.FunctionDefinitionNode;
                    EmitFunctionDefNode(ref funcDefNode);
                }
            }
            //EmitCode("}\n");
        }
Exemplo n.º 3
0
        public ArgumentSignatureNode(ArgumentSignatureNode rhs)
            : base(rhs)
        {
            Arguments = new List<VarDeclNode>();

            foreach (VarDeclNode aNode in rhs.Arguments)
            {
                VarDeclNode newNode = new VarDeclNode(aNode);
                Arguments.Add(newNode);
            }
        }
Exemplo n.º 4
0
        private ProtoCore.AST.AssociativeAST.VarDeclNode ParseFieldDeclaration(FieldInfo f)
        {
            if (null == f || !IsBrowsable(f))
            {
                return(null);
            }

            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = ParseArgumentDeclaration(f.Name, f.FieldType);
            //TODO: temporary limitation, can't have variable name matching with class name.
            if (null != CLRModuleType.GetImportedType(f.Name))
            {
                return(null);
            }
            if (null != varDeclNode)
            {
                varDeclNode.IsStatic = f.IsStatic;
            }
            return(varDeclNode);
        }
Exemplo n.º 5
0
        private ProtoCore.AST.AssociativeAST.VarDeclNode ParseArgumentDeclaration(string parameterName, Type parameterType)
        {
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access    = ProtoCore.Compiler.AccessSpecifier.kPublic;

            ProtoCore.AST.AssociativeAST.IdentifierNode identifierNode = new ProtoCore.AST.AssociativeAST.IdentifierNode
            {
                Value    = parameterName,
                Name     = parameterName,
                datatype = ProtoCore.TypeSystem.BuildPrimitiveTypeObject(ProtoCore.PrimitiveType.kTypeVar, 0)
            };
            //Lets emit native DS type object
            ProtoCore.Type argtype = CLRModuleType.GetProtoCoreType(parameterType, Module);

            varDeclNode.NameNode     = identifierNode;
            varDeclNode.ArgumentType = argtype;
            return(varDeclNode);
        }
Exemplo n.º 6
0
    private static ProtoCore.AST.AssociativeAST.FunctionDefinitionNode GenerateBuiltInMethodSignatureNode(ProtoCore.Lang.BuiltInMethods.BuiltInMethod method)
    {
        ProtoCore.AST.AssociativeAST.FunctionDefinitionNode fDef = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
        fDef.Name = ProtoCore.Lang.BuiltInMethods.GetMethodName(method.ID);
        fDef.ReturnType = method.ReturnType;
        fDef.IsExternLib = true;
        fDef.IsBuiltIn = true;
        fDef.BuiltInMethodId = method.ID;
        fDef.Signature = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
        fDef.MethodAttributes = method.MethodAttributes;

        foreach (KeyValuePair<string, ProtoCore.Type> param in method.Parameters)
        {
            ProtoCore.AST.AssociativeAST.VarDeclNode arg = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            arg.NameNode = new ProtoCore.AST.AssociativeAST.IdentifierNode { Name = param.Key, Value = param.Key };
            arg.ArgumentType = param.Value;
            fDef.Signature.AddArgument(arg);
        }

        return fDef;
    }
        private static ProtoCore.AST.AssociativeAST.FunctionDefinitionNode GenerateBuiltInMethodSignatureNode(ProtoCore.Lang.BuiltInMethods.BuiltInMethod method)
        {
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode fDef = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            fDef.Name             = ProtoCore.Lang.BuiltInMethods.GetMethodName(method.ID);
            fDef.ReturnType       = method.ReturnType;
            fDef.IsExternLib      = true;
            fDef.IsBuiltIn        = true;
            fDef.BuiltInMethodId  = method.ID;
            fDef.Signature        = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
            fDef.MethodAttributes = method.MethodAttributes;

            foreach (KeyValuePair <string, ProtoCore.Type> param in method.Parameters)
            {
                ProtoCore.AST.AssociativeAST.VarDeclNode arg = new ProtoCore.AST.AssociativeAST.VarDeclNode();
                arg.NameNode = new ProtoCore.AST.AssociativeAST.IdentifierNode {
                    Name = param.Key, Value = param.Key
                };
                arg.ArgumentType = param.Value;
                fDef.Signature.AddArgument(arg);
            }

            return(fDef);
        }
Exemplo n.º 8
0
        private ProtoCore.AST.AssociativeAST.AssociativeNode ParseProperty(PropertyInfo p)
        {
            if (null == p || !IsBrowsable(p))
            {
                return(null);
            }

            //Index properties are not parsed as property at this moment.
            ParameterInfo[] indexParams = p.GetIndexParameters();
            if (null != indexParams && indexParams.Length > 0)
            {
                return(null);
            }

            MethodInfo m = p.GetAccessors(false)[0];

            //If this method hides the base class accessor method by signature
            if (m.IsHideBySig)
            {
                //Check if it has a base class
                Type         baseType = p.DeclaringType.BaseType;
                PropertyInfo baseProp = (baseType != null) ? GetProperty(ref baseType, p.Name) : null;
                //If this property is also declared in base class, then no need to add this is derived class.
                if (null != baseProp && baseProp.DeclaringType != p.DeclaringType)
                {
                    //base class also has this method.
                    return(null);
                }
            }

            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = ParseArgumentDeclaration(p.Name, p.PropertyType);
            if (null != varDeclNode)
            {
                varDeclNode.IsStatic = m.IsStatic;
            }
            return(varDeclNode);
        }
Exemplo n.º 9
0
        private FunctionDefinitionNode EmitSetterFunction(ProtoCore.DSASM.SymbolNode prop, ProtoCore.Type argType)
        {
            var argument = new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                Access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
                NameNode =AstFactory.BuildIdentifier(Constants.kTempArg),
                ArgumentType = argType
            };
            var argumentSingature = new ArgumentSignatureNode();
            argumentSingature.AddArgument(argument);

            FunctionDefinitionNode setter = new FunctionDefinitionNode
            {
                Name = ProtoCore.DSASM.Constants.kSetterPrefix + prop.name,
                Signature = argumentSingature,
                Pattern = null,
                ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeNull, 0),
                FunctionBody = new CodeBlockNode(),
                IsExternLib = false,
                IsDNI = false,
                ExternLibName = null,
                Access = prop.access,
                IsStatic = prop.isStatic,
                IsAutoGenerated = true
            };

            // property = %tmpArg
            var propIdent = new TypedIdentifierNode();
            propIdent.Name = propIdent.Value = prop.name;
            propIdent.datatype = prop.datatype;

            var tmpArg =AstFactory.BuildIdentifier(Constants.kTempArg);
            var assignment = AstFactory.BuildBinaryExpression(propIdent, tmpArg, Operator.assign);
            setter.FunctionBody.Body.Add(assignment);

            // return = null;
            var returnNull = AstFactory.BuildReturnStatement(new NullNode()); 
            setter.FunctionBody.Body.Add(returnNull);

            return setter;
        }
Exemplo n.º 10
0
        /*
            1 Copy user-defined function definitions (excluding constructors) into a temp

            2 Modify its signature to include an additional this pointer as the first argument.
              The 'this' argument should take the type of the current class being traversed and be the first argument in the function.
              The function name must be name mangled in order to stay unique

            3 Append this temp to the current vtable
        */
        private void InsertThisPointerArg(ThisPointerProcOverload procOverload)
        {
            // Modify its signature to include an additional this pointer as the first argument.
            // The 'this' argument should take the type of the current class being traversed and be the first argument in the function.
            // The function name must be name mangled in order to stay unique

            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode procNode = procOverload.procNode;

            string className = compileStateTracker.ClassTable.ClassNodes[procOverload.classIndex].name;
            string thisPtrArgName = ProtoCore.DSASM.Constants.kThisPointerArgName;

            ProtoCore.AST.AssociativeAST.IdentifierNode ident = new ProtoCore.AST.AssociativeAST.IdentifierNode();
            ident.Name = ident.Value = thisPtrArgName;

            VarDeclNode thisPtrArg = new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode = ident,
                ArgumentType = new ProtoCore.Type { Name = className, UID = procOverload.classIndex, IsIndexable = false, rank = 0 }
            };

            procNode.Singnature.Arguments.Insert(0, thisPtrArg);

            ProtoCore.Type type = new ProtoCore.Type();
        }
Exemplo n.º 11
0
        private ProtoCore.Type BuildArgumentTypeFromVarDeclNode(VarDeclNode argNode)
        {
            Validity.Assert(argNode != null);
            if (argNode == null)
            {
                return new ProtoCore.Type();
            }

            int uid = compileStateTracker.TypeSystem.GetType(argNode.ArgumentType.Name);
            if (uid == (int)PrimitiveType.kInvalidType && !compileStateTracker.IsTempVar(argNode.NameNode.Name))
            {
                string message = String.Format(ProtoCore.BuildData.WarningMessage.kArgumentTypeUndefined, argNode.ArgumentType.Name, argNode.NameNode.Name);
                buildStatus.LogWarning(ProtoCore.BuildData.WarningID.kTypeUndefined, message, compileStateTracker.CurrentDSFileName, argNode.line, argNode.col);
            }

            bool isArray = argNode.ArgumentType.IsIndexable;
            int rank = argNode.ArgumentType.rank;

            return compileStateTracker.TypeSystem.BuildTypeObject(uid, isArray, rank);
        }
Exemplo n.º 12
0
        private ProtoCore.AST.AssociativeAST.VarDeclNode ParseArgumentDeclaration(string parameterName, Type parameterType)
        {
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access = ProtoCore.Compiler.AccessSpecifier.kPublic;

            ProtoCore.AST.AssociativeAST.IdentifierNode identifierNode = new ProtoCore.AST.AssociativeAST.IdentifierNode
                                                                             {
                Value = parameterName,
                Name = parameterName,
                datatype = ProtoCore.TypeSystem.BuildPrimitiveTypeObject(ProtoCore.PrimitiveType.kTypeVar, 0)
            };
            //Lets emit native DS type object
            ProtoCore.Type argtype = CLRModuleType.GetProtoCoreType(parameterType, Module);

            varDeclNode.NameNode = identifierNode;
            varDeclNode.ArgumentType = argtype;
            return varDeclNode;
        }
Exemplo n.º 13
0
        private void EmitSetterForMemVar(ProtoCore.AST.AssociativeAST.ClassDeclNode cnode, ProtoCore.DSASM.SymbolNode memVar)
        {
            var argument = new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode = new ProtoCore.AST.AssociativeAST.IdentifierNode()
                {
                    Value = ProtoCore.DSASM.Constants.kTempArg,
                    Name = ProtoCore.DSASM.Constants.kTempArg,
                    datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false)
                },
                ArgumentType = new ProtoCore.Type
                {
                    Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeVar),
                    UID = (int)PrimitiveType.kTypeVar
                }
            };

            var argumentSingature = new ArgumentSignatureNode();
            argumentSingature.AddArgument(argument);

            FunctionDefinitionNode setter = new FunctionDefinitionNode()
            {
                Name = ProtoCore.DSASM.Constants.kSetterPrefix + memVar.name,
                Singnature = argumentSingature,
                Pattern = null,
                ReturnType = core.TypeSystem.BuildTypeObject((int)PrimitiveType.kTypeNull, false),
                FunctionBody = new CodeBlockNode(),
                IsExternLib = false,
                IsDNI = false,
                ExternLibName = null,
                access = memVar.access,
                IsStatic = memVar.isStatic
            };

            // property = %tmpArg
            setter.FunctionBody.Body.Add(new BinaryExpressionNode()
            {
                // return = property;
                LeftNode = new IdentifierNode()
                {
                    Value = memVar.name,
                    Name = memVar.name,
                    datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false)
                },
                Optr = ProtoCore.DSASM.Operator.assign,
                RightNode = new IdentifierNode()
                {
                    Value = ProtoCore.DSASM.Constants.kTempArg,
                    Name = ProtoCore.DSASM.Constants.kTempArg,
                    datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false)
                }
            });

            // return = null;
            setter.FunctionBody.Body.Add(new BinaryExpressionNode()
            {
                LeftNode = new IdentifierNode()
                {
                    Value = ProtoCore.DSDefinitions.Kw.kw_return,
                    Name = ProtoCore.DSDefinitions.Kw.kw_return,
                    datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeReturn, false)
                },
                Optr = ProtoCore.DSASM.Operator.assign,
                RightNode = new NullNode()
            });

            cnode.funclist.Add(setter);
        }
Exemplo n.º 14
0
 public VarDeclNode(VarDeclNode rhs)
     : base(rhs)
 {
     Attributes = new List<AssociativeNode>();
     foreach (AssociativeNode aNode in rhs.Attributes)
     {
         AssociativeNode newNode = NodeUtils.Clone(aNode);
         Attributes.Add(newNode);
     }
     memregion = rhs.memregion;
     ArgumentType = new ProtoCore.Type
     {
         UID = rhs.ArgumentType.UID,
         rank = rhs.ArgumentType.rank,
         IsIndexable = rhs.ArgumentType.IsIndexable,
         Name = rhs.ArgumentType.Name
     };
     NameNode = NodeUtils.Clone(rhs.NameNode);
     access = rhs.access;
     IsStatic = rhs.IsStatic;
 }
Exemplo n.º 15
0
        private ProtoCore.Type BuildArgumentTypeFromVarDeclNode(VarDeclNode argNode, GraphNode graphNode = null)
        {
            Validity.Assert(argNode != null);
            if (argNode == null)
            {
                return new ProtoCore.Type();
            }

            int uid = core.TypeSystem.GetType(argNode.ArgumentType.Name);
            if (uid == (int)PrimitiveType.kInvalidType && !core.IsTempVar(argNode.NameNode.Name))
            {
                string message = String.Format(ProtoCore.Properties.Resources.kArgumentTypeUndefined, argNode.ArgumentType.Name, argNode.NameNode.Name);
                buildStatus.LogWarning(WarningID.kTypeUndefined, message, core.CurrentDSFileName, argNode.line, argNode.col, graphNode);
            }

            int rank = argNode.ArgumentType.rank;

            return core.TypeSystem.BuildTypeObject(uid, rank);
        }
Exemplo n.º 16
0
        private ProtoCore.AST.AssociativeAST.VarDeclNode ParseArgumentDeclaration(string parameterName, Type parameterType)
        {
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic;

            ProtoCore.AST.AssociativeAST.IdentifierNode identifierNode = new ProtoCore.AST.AssociativeAST.IdentifierNode
                                                                             {
                Value = parameterName,
                Name = parameterName,
                datatype = new ProtoCore.Type()
                {
                    Name = "var",
                    IsIndexable = false,
                    rank = 0,
                    UID = (int)ProtoCore.PrimitiveType.kTypeVar
                }
            };
            //Lets emit native DS type object
            ProtoCore.Type argtype = CLRModuleType.GetProtoCoreType(parameterType, Module);

            varDeclNode.NameNode = identifierNode;
            varDeclNode.ArgumentType = argtype;
            return varDeclNode;
        }
Exemplo n.º 17
0
	void Associative_ArgDecl(out ProtoCore.AST.AssociativeAST.AssociativeNode node, ProtoCore.CompilerDefinitions.AccessModifier access = ProtoCore.CompilerDefinitions.AccessModifier.Public) {
		ProtoCore.AST.AssociativeAST.IdentifierNode tNode = null; 
		ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode(); 
		varDeclNode.Access = access;
		
		Expect(1);
		if (IsKeyWord(t.val, true))
		{
		   errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
		}
		tNode = AstFactory.BuildIdentifier(t.val);
		NodeUtils.SetNodeLocation(tNode, t);
		varDeclNode.NameNode = tNode;
		NodeUtils.CopyNodeLocation(varDeclNode, tNode);
		
		ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = "var"; argtype.rank = 0; argtype.UID = 0; 
		if (la.kind == 47) {
			Get();
			Expect(1);
			argtype.Name = t.val; 
			if (la.kind == 10) {
				Get();
				Expect(11);
				argtype.rank = 1; 
				if (la.kind == 10 || la.kind == 24) {
					if (la.kind == 24) {
						Get();
						Expect(10);
						Expect(11);
						argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; 
					} else {
						while (la.kind == 10) {
							Get();
							Expect(11);
							argtype.rank++; 
						}
					}
				}
			}
		}
		varDeclNode.ArgumentType = argtype; 
		node = varDeclNode; 
	}
Exemplo n.º 18
0
	void Associative_vardecl(out ProtoCore.AST.AssociativeAST.AssociativeNode node, ProtoCore.CompilerDefinitions.AccessModifier access = ProtoCore.CompilerDefinitions.AccessModifier.Public, bool isStatic = false, List<ProtoCore.AST.AssociativeAST.AssociativeNode> attrs = null) {
		ProtoCore.AST.AssociativeAST.IdentifierNode tNode = null; 
		ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode(); 
		varDeclNode.Access = access;
		varDeclNode.IsStatic = isStatic;
		
		Expect(1);
		if (IsKeyWord(t.val, true))
		{
		   errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val));
		}
		NodeUtils.SetNodeLocation(varDeclNode, t);
		tNode = AstFactory.BuildIdentifier(t.val);
		NodeUtils.SetNodeLocation(tNode, t);
		varDeclNode.NameNode = tNode;
		
		if (la.kind == 47) {
			Get();
			Expect(1);
			ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = t.val; argtype.rank = 0; 
			if (la.kind == 10) {
				Get();
				Expect(11);
				argtype.rank = 1; 
				if (la.kind == 10 || la.kind == 24 || la.kind == 51) {
					if (la.kind == 24) {
						Get();
						Expect(10);
						Expect(11);
						argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; 
					} else {
						while (la.kind == 10) {
							Get();
							Expect(11);
							argtype.rank++; 
						}
					}
				}
			}
			string oldName = tNode.Name;
			string oldValue = tNode.Value;
			
			// Here since the variable has an explicitly specified type 
			// the "IdentifierNode" should really be "TypedIdentifierNode"
			// (which is used to indicate the identifier that has explicit 
			// type specified).
			tNode = new ProtoCore.AST.AssociativeAST.TypedIdentifierNode()
			{
			   Name = oldName,
			   Value = oldValue
			};
			
			argtype.UID = core.TypeSystem.GetType(argtype.Name);
			tNode.datatype = argtype;
			varDeclNode.NameNode = tNode;
			varDeclNode.ArgumentType = argtype;
			
		}
		if (la.kind == 51) {
			Get();
			ProtoCore.AST.AssociativeAST.AssociativeNode rhsNode; 
			Associative_Expression(out rhsNode);
			ProtoCore.AST.AssociativeAST.BinaryExpressionNode bNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode();
			NodeUtils.CopyNodeLocation(bNode, varDeclNode);
			bNode.LeftNode = tNode;
			bNode.RightNode = rhsNode;
			bNode.Optr = Operator.assign;
			varDeclNode.NameNode = bNode;       
			
		}
		node = varDeclNode; 
		//if(!isGlobalScope) {
		//    localVarCount++;
		//}
		
	}
Exemplo n.º 19
0
        void Associative_ArgDecl(out ProtoCore.AST.AssociativeAST.AssociativeNode node, ProtoCore.DSASM.AccessSpecifier access = ProtoCore.DSASM.AccessSpecifier.kPublic)
        {
            ProtoCore.AST.AssociativeAST.IdentifierNode tNode = null;
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access = access;

            Expect(1);
            if (IsKeyWord(t.val, true))
            {
               errors.SemErr(t.line, t.col, String.Format("\"{0}\" is a keyword, identifier expected", t.val));
            }
            tNode = ProtoCore.Utils.CoreUtils.BuildAssocIdentifier(core, t.val);
            NodeUtils.SetNodeLocation(tNode, t);
            varDeclNode.NameNode = tNode;
            NodeUtils.CopyNodeLocation(varDeclNode, tNode);

            ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = "var"; argtype.rank = 0; argtype.UID = 0;
            if (la.kind == 48) {
            Get();
            Expect(1);
            argtype.Name = t.val;
            if (la.kind == 7) {
                argtype.IsIndexable = true;
                Get();
                Expect(8);
                argtype.rank = 1;
                if (la.kind == 7 || la.kind == 21) {
                    if (la.kind == 21) {
                        Get();
                        Expect(7);
                        Expect(8);
                        argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank;
                    } else {
                        while (la.kind == 7) {
                            Get();
                            Expect(8);
                            argtype.rank++;
                        }
                    }
                }
            }
            }
            varDeclNode.ArgumentType = argtype;
            node = varDeclNode;
        }
Exemplo n.º 20
0
        void Associative_vardecl(out ProtoCore.AST.AssociativeAST.AssociativeNode node, ProtoCore.DSASM.AccessSpecifier access = ProtoCore.DSASM.AccessSpecifier.kPublic, bool isStatic = false, List<ProtoCore.AST.AssociativeAST.AssociativeNode> attrs = null)
        {
            ProtoCore.AST.AssociativeAST.IdentifierNode tNode = null;
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access = access;
            varDeclNode.Attributes = attrs;
            varDeclNode.IsStatic = isStatic;

            Expect(1);
            if (IsKeyWord(t.val, true))
            {
               errors.SemErr(t.line, t.col, String.Format("\"{0}\" is a keyword, identifier expected", t.val));
            }
            NodeUtils.SetNodeLocation(varDeclNode, t);
            tNode = ProtoCore.Utils.CoreUtils.BuildAssocIdentifier(core, t.val);
            NodeUtils.SetNodeLocation(tNode, t);
            varDeclNode.NameNode = tNode;

            if (la.kind == 48) {
            Get();
            Expect(1);
            ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = t.val; argtype.rank = 0;
            if (la.kind == 7) {
                argtype.IsIndexable = true;
                Get();
                Expect(8);
                argtype.rank = 1;
                if (la.kind == 7 || la.kind == 21 || la.kind == 47) {
                    if (la.kind == 21) {
                        Get();
                        Expect(7);
                        Expect(8);
                        argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank;
                    } else {
                        while (la.kind == 7) {
                            Get();
                            Expect(8);
                            argtype.rank++;
                        }
                    }
                }
            }
            string oldName = tNode.Name;
            string oldValue = tNode.Value;

            // Here since the variable has an explicitly specified type
            // the "IdentifierNode" should really be "TypedIdentifierNode"
            // (which is used to indicate the identifier that has explicit
            // type specified).
            tNode = new ProtoCore.AST.AssociativeAST.TypedIdentifierNode()
            {
               Name = oldName,
               Value = oldValue
            };

            argtype.UID = core.TypeSystem.GetType(argtype.Name);
            tNode.datatype = argtype;
            varDeclNode.NameNode = tNode;
            varDeclNode.ArgumentType = argtype;

            }
            if (la.kind == 47) {
            Get();
            ProtoCore.AST.AssociativeAST.AssociativeNode rhsNode;
            Associative_Expression(out rhsNode);
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode bNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode();
            NodeUtils.CopyNodeLocation(bNode, varDeclNode);
            bNode.LeftNode = tNode;
            bNode.RightNode = rhsNode;
            bNode.Optr = Operator.assign;
            varDeclNode.NameNode = bNode;

            }
            node = varDeclNode;
            //if(!isGlobalScope) {
            //    localVarCount++;
            //}
        }
Exemplo n.º 21
0
        private void EmitClassDeclNode(AssociativeNode node, ref ProtoCore.Type inferedType, ProtoCore.CompilerDefinitions.Associative.SubCompilePass subPass = ProtoCore.CompilerDefinitions.Associative.SubCompilePass.kNone,
            GraphNode graphNode = null)
        {
            ClassDeclNode classDecl = node as ClassDeclNode;
            
            // Restrict classes 
            if (!IsClassAllowed(classDecl))
            {
                return;
            }
            // Handling n-pass on class declaration
            if (ProtoCore.CompilerDefinitions.Associative.CompilePass.kClassName == compilePass)
            {
                // Class name pass
                // Populating the class tables with the class names
                if (null != codeBlock.parent)
                {
                    buildStatus.LogSemanticError(Resources.ClassCannotBeDefinedInsideLanguageBlock, core.CurrentDSFileName, classDecl.line, classDecl.col);
                }


                ProtoCore.DSASM.ClassNode thisClass = new ProtoCore.DSASM.ClassNode();
                thisClass.Name = classDecl.ClassName;
                thisClass.Size = classDecl.Variables.Count;
                thisClass.IsImportedClass = classDecl.IsImportedClass;
                thisClass.TypeSystem = core.TypeSystem;
                thisClass.ClassAttributes = classDecl.ClassAttributes;
                
                if (classDecl.ExternLibName != null)
                    thisClass.ExternLib = classDecl.ExternLibName;
                else
                    thisClass.ExternLib = Path.GetFileName(core.CurrentDSFileName);

                globalClassIndex = core.ClassTable.Append(thisClass);
                if (ProtoCore.DSASM.Constants.kInvalidIndex == globalClassIndex)
                {
                    string message = string.Format("Class redefinition '{0}' (BE1C3285).\n", classDecl.ClassName);
                    buildStatus.LogSemanticError(message, core.CurrentDSFileName, classDecl.line, classDecl.col);
                    throw new BuildHaltException(message);
                }

                unPopulatedClasses.Add(globalClassIndex, classDecl);

                //Always allow us to convert a class to a bool
                thisClass.CoerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            }
            else if (ProtoCore.CompilerDefinitions.Associative.CompilePass.kClassBaseClass == compilePass)
            { 
                // Base class pass
                // Populating each class entry with their immediate baseclass
                globalClassIndex = core.ClassTable.GetClassId(classDecl.ClassName);

                ProtoCore.DSASM.ClassNode thisClass = core.ClassTable.ClassNodes[globalClassIndex];

                // Verify and store the list of classes it inherits from 
                if (null != classDecl.BaseClasses)
                {
                    for (int n = 0; n < classDecl.BaseClasses.Count; ++n)
                    {
                        int baseClass = core.ClassTable.GetClassId(classDecl.BaseClasses[n]);
                        if (baseClass == globalClassIndex)
                        {
                            string message = string.Format("Class '{0}' cannot derive from itself (DED0A61F).\n", classDecl.ClassName);
                            buildStatus.LogSemanticError(message, core.CurrentDSFileName, classDecl.line, classDecl.col);
                            throw new BuildHaltException(message);
                        }

                        if (ProtoCore.DSASM.Constants.kInvalidIndex != baseClass)
                        {
                            if (core.ClassTable.ClassNodes[baseClass].IsImportedClass && !thisClass.IsImportedClass)
                            {
                                string message = string.Format("Cannot derive from FFI class {0} (DA87AC4D).\n",
                                    core.ClassTable.ClassNodes[baseClass].Name);

                                buildStatus.LogSemanticError(message, core.CurrentDSFileName, classDecl.line, classDecl.col);
                                throw new BuildHaltException(message);
                            }

                            thisClass.Bases.Add(baseClass);
                            thisClass.CoerceTypes.Add(baseClass, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceBaseClass);
                        }
                        else
                        {
                            string message = string.Format("Unknown base class '{0}' (9E44FFB3).\n", classDecl.BaseClasses[n]);
                            buildStatus.LogSemanticError(message, core.CurrentDSFileName, classDecl.line, classDecl.col);
                            throw new BuildHaltException(message);
                        }
                    }
                }
            }
            else if (ProtoCore.CompilerDefinitions.Associative.CompilePass.kClassHierarchy == compilePass)
            {
                // Class hierarchy pass
                // Populating each class entry with all sub classes in the hierarchy
                globalClassIndex = core.ClassTable.GetClassId(classDecl.ClassName);

                ProtoCore.DSASM.ClassNode thisClass = core.ClassTable.ClassNodes[globalClassIndex];

                // Verify and store the list of classes it inherits from 
                if (null != classDecl.BaseClasses)
                {
                    for (int n = 0; n < classDecl.BaseClasses.Count; ++n)
                    {
                        int baseClass = core.ClassTable.GetClassId(classDecl.BaseClasses[n]);

                        // baseClass is already resovled in the previous pass
                        Validity.Assert(ProtoCore.DSASM.Constants.kInvalidIndex != baseClass);

                            
                        // Iterate through all the base classes until the the root class
                        // For every base class, add the coercion score
                        ProtoCore.DSASM.ClassNode tmpCNode = core.ClassTable.ClassNodes[baseClass];
                        if (tmpCNode.Bases.Count > 0)
                        {
                            baseClass = tmpCNode.Bases[0];
                            while (ProtoCore.DSASM.Constants.kInvalidIndex != baseClass)
                            {
                                thisClass.CoerceTypes.Add(baseClass, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceBaseClass);
                                tmpCNode = core.ClassTable.ClassNodes[baseClass];

                                baseClass = ProtoCore.DSASM.Constants.kInvalidIndex;
                                if (tmpCNode.Bases.Count > 0)
                                {
                                    baseClass = tmpCNode.Bases[0];
                                }
                            }
                        }
                    }
                }
            }
            else if (ProtoCore.CompilerDefinitions.Associative.CompilePass.kClassMemVar == compilePass)
            {
                EmitMemberVariables(classDecl, graphNode);
            }
            else if (ProtoCore.CompilerDefinitions.Associative.CompilePass.kClassMemFuncSig == compilePass)
            {
                // Class member variable pass
                // Populating each class entry vtables with their respective
                // member variables signatures
                globalClassIndex = core.ClassTable.GetClassId(classDecl.ClassName);

                List<AssociativeNode> thisPtrOverloadList = new List<AssociativeNode>();
                foreach (AssociativeNode funcdecl in classDecl.Procedures)
                {
                    DfsTraverse(funcdecl, ref inferedType);

                    var funcDef = funcdecl as FunctionDefinitionNode;
                    if (funcDef == null || funcDef.IsStatic || funcDef.Name == ProtoCore.DSDefinitions.Keyword.Dispose)
                        continue;

                    bool isGetterSetter = CoreUtils.IsGetterSetter(funcDef.Name);

                    var thisPtrArgName = Constants.kThisPointerArgName;
                    if (!isGetterSetter)
                    {
                        var classsShortName = classDecl.ClassName.Split('.').Last();
                        var typeDepName = classsShortName.ToLower();
                        if (typeDepName != classsShortName && funcDef.Signature.Arguments.All(a => a.NameNode.Name != typeDepName))
                            thisPtrArgName = typeDepName;
                    }

                    // This is a function, create its parameterized this pointer overload
                    ThisPointerProcOverload thisProc = new ThisPointerProcOverload();
                    thisProc.classIndex = globalClassIndex;
                    thisProc.procNode = new FunctionDefinitionNode(funcDef);
                    var thisPtrArg = new VarDeclNode()
                    {
                        Access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
                        NameNode = AstFactory.BuildIdentifier(thisPtrArgName),
                        ArgumentType = new ProtoCore.Type { Name = classDecl.ClassName, UID = globalClassIndex, rank = 0 }
                    };
                    thisProc.procNode.Signature.Arguments.Insert(0, thisPtrArg);
                    thisProc.procNode.IsAutoGeneratedThisProc = true;

                    if (CoreUtils.IsGetterSetter(funcDef.Name))
                    {
                        InsertThisPointerAtBody(thisProc);
                    }
                    else
                    {
                        // Generate a static function for member function f():
                        //     satic def f(a: A)
                        //     { 
                        //        return = a.f()
                        //     }
                        thisProc.procNode.IsStatic = true;
                        BuildThisFunctionBody(thisProc);
                    }

                    thisPtrOverloadList.Add(thisProc.procNode);
                }

                foreach (var overloadFunc in thisPtrOverloadList)
                {
                    // Emit the newly defined overloads
                    DfsTraverse(overloadFunc, ref inferedType);
                }

                classDecl.Procedures.AddRange(thisPtrOverloadList);

                if (!classDecl.IsExternLib)
                {
                    ProtoCore.DSASM.ProcedureTable vtable = core.ClassTable.ClassNodes[globalClassIndex].ProcTable;
                    if (vtable.GetFunctionBySignature(classDecl.ClassName, new List<ProtoCore.Type>()) == null)
                    {
                        ConstructorDefinitionNode defaultConstructor = new ConstructorDefinitionNode();
                        defaultConstructor.Name = classDecl.ClassName;
                        defaultConstructor.LocalVariableCount = 0;
                        defaultConstructor.Signature = new ArgumentSignatureNode();
                        defaultConstructor.ReturnType = new ProtoCore.Type { Name = "var", UID = 0 };
                        defaultConstructor.FunctionBody = new CodeBlockNode();
                        defaultConstructor.BaseConstructor = null;
                        defaultConstructor.Access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic;
                        defaultConstructor.IsExternLib = false;
                        defaultConstructor.ExternLibName = null;
                        DfsTraverse(defaultConstructor, ref inferedType);
                        classDecl.Procedures.Add(defaultConstructor);
                    }
                }
            }
            else if (ProtoCore.CompilerDefinitions.Associative.CompilePass.kGlobalScope == compilePass)
            {
                // before populate the attributes, we must know the attribute class constructor signatures
                // in order to check the parameter 
                // populate the attributes for the class and class member variable 
                globalClassIndex = core.ClassTable.GetClassId(classDecl.ClassName);
                if (globalClassIndex != ProtoCore.DSASM.Constants.kInvalidIndex)
                {
                    ProtoCore.DSASM.ClassNode thisClass = core.ClassTable.ClassNodes[globalClassIndex];
                    // class
                    if (classDecl.Attributes != null)
                    {
                        thisClass.Attributes = PopulateAttributes(classDecl.Attributes);
                    }

                    // member variable
                    int ix = -1;
                    int currentClassScope = -1;
                    foreach (ProtoCore.DSASM.SymbolNode sn in thisClass.Symbols.symbolList.Values)
                    {
                        // only populate the attributes for member variabls
                        if (sn.functionIndex != ProtoCore.DSASM.Constants.kInvalidIndex)
                            continue;
                        if (sn.classScope != globalClassIndex)
                        {
                            if (currentClassScope != sn.classScope)
                            {
                                currentClassScope = sn.classScope;
                                ix = 0;
                            }
                            // copy attribute information from base class
                            sn.Attributes = core.ClassTable.ClassNodes[currentClassScope].Symbols.symbolList[ix++].Attributes;
                        }
                        else
                        {
                            if (currentClassScope != globalClassIndex)
                            {
                                currentClassScope = globalClassIndex;
                                ix = 0;
                            }
                        }
                    }
                }
            }
            else if (ProtoCore.CompilerDefinitions.Associative.CompilePass.kClassMemFuncBody == compilePass)
            {
                // Class member variable pass
                // Populating the function body of each member function defined in the class vtables

                globalClassIndex = core.ClassTable.GetClassId(classDecl.ClassName);

                // Initialize the global function table for this class
                // 'classIndexAtCallsite' is the class index as it is stored at the callsite function tables
                int classIndexAtCallsite = globalClassIndex + 1;
                core.FunctionTable.InitGlobalFunctionEntry(classIndexAtCallsite);

                foreach (AssociativeNode funcdecl in classDecl.Procedures)
                {
                    // reset the inferedtype between functions
                    inferedType = new ProtoCore.Type();
                    DfsTraverse(funcdecl, ref inferedType, false, null, subPass);
                }
            }

            // Reset the class index
            core.ClassIndex = globalClassIndex = ProtoCore.DSASM.Constants.kGlobalScope;
        }
Exemplo n.º 22
0
        private ArgumentInfo BuildArgumentInfoFromVarDeclNode(VarDeclNode argNode)
        {
            var argumentName = String.Empty;
            ProtoCore.AST.Node defaultExpression = null;
            if (argNode.NameNode is IdentifierNode)
            {
                argumentName = (argNode.NameNode as IdentifierNode).Value;
            }
            else if (argNode.NameNode is BinaryExpressionNode)
            {
                var bNode = argNode.NameNode as BinaryExpressionNode;
                defaultExpression = bNode;
                argumentName = (bNode.LeftNode as IdentifierNode).Value;
            }
            else
            {
                Validity.Assert(false, "Check generated AST");
            }

            var argInfo = new ProtoCore.DSASM.ArgumentInfo 
            { 
                Name = argumentName, 
                DefaultExpression = defaultExpression,
                Attributes = argNode.ExternalAttributes
            };
            return argInfo;
        }
Exemplo n.º 23
0
 public static VarDeclNode BuildParamNode(string paramName)
 {
     VarDeclNode param = new VarDeclNode();
     param.NameNode = BuildIdentifier(paramName);
     param.ArgumentType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar, false);
     return param;
 }
Exemplo n.º 24
0
 public void AddArgument(VarDeclNode arg)
 {
     Arguments.Add(arg);
 }
Exemplo n.º 25
0
 public void AddArgument(VarDeclNode arg)
 {
     Arguments.Add(arg);
 }