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;
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations