void Associative_DecoratedIdentifier(out ProtoCore.AST.AssociativeAST.AssociativeNode node) { node = null; if (IsLocallyTypedVariable()) { Expect(1); if (IsKeyWord(t.val, true)) { errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val)); } var typedVar = new ProtoCore.AST.AssociativeAST.TypedIdentifierNode(); typedVar.Name = typedVar.Value = t.val; NodeUtils.SetNodeLocation(typedVar, t); Expect(47); Expect(40); typedVar.IsLocal = true; Expect(1); int type = core.TypeSystem.GetType(t.val); if (type == ProtoCore.DSASM.Constants.kInvalidIndex) { var unknownType = new ProtoCore.Type(); unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex; unknownType.Name = t.val; typedVar.datatype = unknownType; } else { typedVar.datatype = core.TypeSystem.BuildTypeObject(type, 0); } if (la.kind == 10) { var datatype = typedVar.datatype; Get(); Expect(11); datatype.rank = 1; if (la.kind == 10 || la.kind == 24) { if (la.kind == 24) { Get(); Expect(10); Expect(11); datatype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; } else { while (la.kind == 10) { Get(); Expect(11); datatype.rank++; } } } typedVar.datatype = datatype; } node = typedVar; } else if (IsLocalVariable()) { Expect(1); if (IsKeyWord(t.val, true)) { errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val)); } var identNode = new ProtoCore.AST.AssociativeAST.IdentifierNode(); identNode.Name = identNode.Value = t.val; NodeUtils.SetNodeLocation(identNode, t); Expect(47); Expect(40); identNode.IsLocal = true; node = identNode; } else if (IsTypedVariable()) { Expect(1); if (IsKeyWord(t.val, true)) { errors.SemErr(t.line, t.col, String.Format(Resources.keywordCantBeUsedAsIdentifier, t.val)); } var typedVar = new ProtoCore.AST.AssociativeAST.TypedIdentifierNode(); typedVar.Name = typedVar.Value = t.val; NodeUtils.SetNodeLocation(typedVar, t); Expect(47); string strIdent = string.Empty; int type = ProtoCore.DSASM.Constants.kInvalidIndex; if (IsIdentList()) { TypedIdentifierList(out node); strIdent = node.ToString(); } else if (la.kind == 1) { Get(); strIdent = t.val; } else SynErr(91); type = core.TypeSystem.GetType(strIdent); typedVar.TypeAlias = strIdent; if (type == ProtoCore.DSASM.Constants.kInvalidIndex) { var unknownType = new ProtoCore.Type(); unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex; unknownType.Name = strIdent; typedVar.datatype = unknownType; } else { typedVar.datatype = core.TypeSystem.BuildTypeObject(type, 0); } if (la.kind == 10) { var datatype = typedVar.datatype; Get(); Expect(11); datatype.rank = 1; if (la.kind == 10 || la.kind == 24) { if (la.kind == 24) { Get(); Expect(10); Expect(11); datatype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; } else { while (la.kind == 10) { Get(); Expect(11); datatype.rank++; } } } typedVar.datatype = datatype; } node = typedVar; } else if (la.kind == 1 || la.kind == 12 || la.kind == 45) { Associative_IdentifierList(out node); } else SynErr(92); }
void Associative_DecoratedIdentifier(out ProtoCore.AST.AssociativeAST.AssociativeNode node) { node = null; if (IsTypedVariable()) { Expect(1); if (IsKeyWord(t.val, true)) { errors.SemErr(t.line, t.col, String.Format("\"{0}\" is a keyword, identifier expected", t.val)); } var typedVar = new ProtoCore.AST.AssociativeAST.TypedIdentifierNode(); typedVar.Name = typedVar.Value = t.val; NodeUtils.SetNodeLocation(typedVar, t); Expect(48); Expect(1); int type = core.TypeSystem.GetType(t.val); if (type == ProtoCore.DSASM.Constants.kInvalidIndex) { var unknownType = new ProtoCore.Type(); unknownType.UID = ProtoCore.DSASM.Constants.kInvalidIndex; unknownType.Name = t.val; typedVar.datatype = unknownType; } else { typedVar.datatype = core.TypeSystem.BuildTypeObject(type, false, 0); } if (la.kind == 7) { var datatype = typedVar.datatype; Get(); Expect(8); datatype.rank = 1; if (la.kind == 7 || la.kind == 21) { if (la.kind == 21) { Get(); Expect(7); Expect(8); datatype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; } else { while (la.kind == 7) { Get(); Expect(8); datatype.rank++; } } } typedVar.datatype = datatype; } node = typedVar; } else if (la.kind == 1 || la.kind == 9 || la.kind == 44) { Associative_IdentifierList(out node); } else SynErr(94); }
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++; //} }
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++; //} }