Search in sources :

Example 1 with Nonnull

use of mrmathami.annotations.Nonnull in project Cpp4CIA by thanhminhmr.

the class AstBuilder method createIntegralNode.

@Nonnull
private CppNode createIntegralNode(@Nonnull String typeName) {
    final CppNode existNode = integralNodeMap.get(typeName);
    if (existNode != null)
        return existNode;
    final IntegralNode newNode = new IntegralNode(typeName);
    rootNode.addChild(newNode);
    integralNodeMap.put(typeName, newNode);
    return newNode;
}
Also used : CppNode(mrmathami.cia.cpp.ast.CppNode) IntegralNode(mrmathami.cia.cpp.ast.IntegralNode) Nonnull(mrmathami.annotations.Nonnull)

Example 2 with Nonnull

use of mrmathami.annotations.Nonnull in project Cpp4CIA by thanhminhmr.

the class AstBuilder method createNode.

@Nonnull
private CppNode createNode(@Nullable IBinding binding, @Nullable IASTName astName, @Nullable String signature, @Nonnull CppNode newNode, @Nonnull CppNode parentNode) {
    assert !(newNode instanceof IntegralNode);
    if (binding == null) {
        return createIntegralNode(astName != null ? astName.toString() : signature != null ? signature : "");
    }
    final IBinding topBinding = binding instanceof ICPPSpecialization ? Objects.requireNonNullElse(((ICPPSpecialization) binding).getSpecializedBinding(), binding) : binding;
    final CppNode existNode = bindingNodeMap.get(topBinding);
    if (existNode != null && !(existNode instanceof IntegralNode))
        return existNode;
    final String name = firstNonBlank(astName != null ? astName.toString() : null, topBinding.getName());
    final String uniqueName = firstNonBlank(topBinding instanceof ICPPBinding ? PATTERN.matcher(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)).replaceAll("{ROOT}") : astName != null ? ASTStringUtil.getQualifiedName(astName) : null, name);
    newNode.setName(name);
    newNode.setUniqueName(uniqueName);
    newNode.setSignature(signature != null ? signature : uniqueName);
    parentNode.addChild(newNode);
    parentNode.addDependencyTo(newNode, DependencyType.MEMBER);
    bindingNodeMap.put(topBinding, newNode);
    if (existNode != null)
        replaceNode(existNode, newNode);
    return newNode;
}
Also used : IBinding(org.eclipse.cdt.core.dom.ast.IBinding) CppNode(mrmathami.cia.cpp.ast.CppNode) ICPPSpecialization(org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization) IntegralNode(mrmathami.cia.cpp.ast.IntegralNode) ICPPBinding(org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding) Nonnull(mrmathami.annotations.Nonnull)

Example 3 with Nonnull

use of mrmathami.annotations.Nonnull in project Cpp4CIA by thanhminhmr.

the class PreprocessorBuilder method build.

@Nonnull
public static char[] build(@Nonnull Path projectRootPath, @Nonnull List<Path> projectFiles, @Nonnull List<Path> includePaths, boolean isReadable) throws CppException {
    try {
        final Preprocessor preprocessor = new Preprocessor(EMPTY_PREPROCESSOR_LISTENER);
        preprocessor.addFeatures(FEATURE_LIST);
        preprocessor.setSystemIncludePath(includePaths);
        final StringBuilder builder = new StringBuilder();
        for (final Path sourceFile : includeList(projectFiles, includePaths)) {
            builder.append("#include \"").append(projectRootPath.relativize(sourceFile)).append("\"\n");
        }
        final Path virtualFile = projectRootPath.resolve(UUID.randomUUID() + ".virtual_file");
        preprocessor.addInput(new InputLexerSource(new StringReader(builder.toString()), virtualFile));
        // =====
        final StringBuilder fileContent = new StringBuilder();
        if (isReadable) {
            readablePreprocessor(preprocessor, fileContent);
        } else {
            fastPreprocessor(preprocessor, fileContent);
        }
        // =====
        char[] content = new char[fileContent.length()];
        fileContent.getChars(0, content.length, content, 0);
        return content;
    } catch (IOException | LexerException e) {
        throw new CppException("Cannot preprocess the source code!", e);
    }
}
Also used : Path(java.nio.file.Path) InputLexerSource(org.anarres.cpp.InputLexerSource) CppException(mrmathami.cia.cpp.CppException) StringReader(java.io.StringReader) Preprocessor(org.anarres.cpp.Preprocessor) IOException(java.io.IOException) LexerException(org.anarres.cpp.LexerException) Nonnull(mrmathami.annotations.Nonnull)

Example 4 with Nonnull

use of mrmathami.annotations.Nonnull in project Cpp4CIA by thanhminhmr.

the class ProjectVersion method getWeightMap.

@Nonnull
public Map<CppNode, Double> getWeightMap() {
    if (weightMap != null)
        return weightMap;
    final Map<CppNode, Double> map = new IdentityHashMap<>();
    // root id == 0
    map.put(rootNode, weights[0]);
    for (final CppNode node : rootNode) map.put(node, weights[node.getId()]);
    return this.weightMap = Map.copyOf(map);
}
Also used : IdentityHashMap(java.util.IdentityHashMap) CppNode(mrmathami.cia.cpp.ast.CppNode) Nonnull(mrmathami.annotations.Nonnull)

Example 5 with Nonnull

use of mrmathami.annotations.Nonnull in project Cpp4CIA by thanhminhmr.

the class VersionBuilder method createInternalIncludePaths.

@Nonnull
private static List<Path> createInternalIncludePaths(@Nonnull List<Path> projectFiles) {
    final List<Path> includePaths = new ArrayList<>();
    final Set<Path> includePathSet = new HashSet<>();
    for (final Path projectFile : projectFiles) {
        final Path canonicalAbsoluteFile = projectFile.getParent();
        if (includePathSet.add(canonicalAbsoluteFile)) {
            includePaths.add(canonicalAbsoluteFile);
        }
    }
    return includePaths;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Nonnull(mrmathami.annotations.Nonnull)

Aggregations

Nonnull (mrmathami.annotations.Nonnull)22 CppNode (mrmathami.cia.cpp.ast.CppNode)12 Path (java.nio.file.Path)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 IntegralNode (mrmathami.cia.cpp.ast.IntegralNode)5 IBinding (org.eclipse.cdt.core.dom.ast.IBinding)5 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 CppException (mrmathami.cia.cpp.CppException)3 DependencyType (mrmathami.cia.cpp.ast.DependencyType)3 RootNode (mrmathami.cia.cpp.ast.RootNode)3 Pair (mrmathami.utils.Pair)3 IASTDeclaration (org.eclipse.cdt.core.dom.ast.IASTDeclaration)3 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)3 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 FunctionNode (mrmathami.cia.cpp.ast.FunctionNode)2 TypedefNode (mrmathami.cia.cpp.ast.TypedefNode)2