Exemple #1
0
        public override void Visit(VariableNameAST variableName)
        {
            var ident = _symTableManager.LookupIdentifierInfo(_currentFileName, variableName.Name, _currentScopeId, _currentNodePosition);

            if (ident.isFnParam)
            {
                _currentValue = LLVM.GetParam(_currentFunction, (uint)ident.paramIndex);
            }
        }
Exemple #2
0
        public override void Visit(VariableDecAssignAST variableDecAssign)
        {
            if (variableDecAssign.Type == null)
            {
                return;
            }

            var identInfo = _symTableManager.LookupIdentifierInfo(_currentFileName, variableDecAssign.Name,
                                                                  _currentScopeId, _currentNodePosition);

            var exprType = _exprTypeVisitor.GetAstNodeType(_currentFileName, identInfo.scopeId, identInfo.position, variableDecAssign.ExpressionValue);

            if (!IsSameTypeOrNullPtr(variableDecAssign.Type, exprType))
            {
                throw new Exception(string.Format("Type mismatch : variable '{0}' have type '{1}' but assigned '{2}' type",
                                                  variableDecAssign.Name, variableDecAssign.Type, exprType));
            }
        }
Exemple #3
0
        private TypeAST GetVariableType(VariableNameAST variableName, bool isConstant = false)
        {
            var variableInfo = _symTableManager.
                               LookupIdentifierInfo(_stateInfo.currentFile, variableName.Name,
                                                    _stateInfo.scopeId, _stateInfo.position, isConstant);

            if (variableInfo == null && !_stateInfo.lookForEnum)
            {
                throw new Exception(string.Format("Undeclared {0} variable {1} in file {2}",
                                                  isConstant ? "constant" : "", variableName.Name, _stateInfo.currentFile));
            }

            if (variableInfo == null)
            {
                var isEnum = _symTableManager.LookupTypeInfo(_stateInfo.currentFile, variableName.Name);

                if (isEnum == null || isEnum.kind != TypeKind.ENUM)
                {
                    throw new Exception(string.Format("Undeclared {0} variable {1} in file {2}",
                                                      isConstant ? "constant" : "", variableName.Name, _stateInfo.currentFile));
                }

                return(isEnum.type);
            }

            if (variableInfo.typeAST == null)
            {
                Debug.Assert(_getVariableTypeFunc != null);

                var previousStateInfo = _stateInfo;

                variableInfo.typeAST = _getVariableTypeFunc(variableInfo);

                _stateInfo = previousStateInfo;
            }

            return(variableInfo.typeAST);
        }